Golang image.Rectangle.Intersect, Overlaps, Size and String functions.
package image
Golang image.Rectangle.Intersect, Overlaps, Size and String functions usage example.
package main
import (
"fmt"
"image"
"runtime"
)
func main() {
// maximize CPU usage for maximum performance
runtime.GOMAXPROCS(runtime.NumCPU())
// define a rectangle
rect := image.Rect(0, 0, 500, 500)
fmt.Println("Min X : ", rect.Min.X)
fmt.Println("Max X : ", rect.Max.X)
s := image.Rect(-100, -100, 550, 550)
// Intersect returns the largest rectangle contained by both r and s.
// If the two rectangles do not overlap then the zero rectangle will be returned.
interRect := rect.Intersect(s)
fmt.Println(interRect)
// Overlaps reports whether r and s have a non-empty intersection.
fmt.Println("Did rect overlaps s ? ", rect.Overlaps(s))
// Size returns r's width and height.
fmt.Println(rect.Size())
// String returns a string representation of r like "(3,4)-(6,5)".
fmt.Println(rect.String())
}
Output :
Min X : 0
Max X : 500
(0,0)-(500,500)
Did rect overlaps s ? true
(500,500)
(0,0)-(500,500)
References :
http://golang.org/pkg/image/#Rectangle.Intersect
http://golang.org/pkg/image/#Rectangle.Overlaps
Advertisement
Something interesting
Tutorials
+7.3k Golang : Calculate how many weeks left to go in a given year
+12.3k Golang : Print UTF-8 fonts on image example
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+9.7k Golang : Sort and reverse sort a slice of floats
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+6.7k Golang : Skip or discard items of non-interest when iterating example
+14.7k Golang : Reset buffer example
+25.7k Golang : How to write CSV data to file
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates