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
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+14.6k Golang : Convert(cast) int to float example
+37.5k Upload multiple files with Go
+41.4k Golang : Convert string to array/slice
+9.4k Golang : How to protect your source code from client, hosting company or hacker?
+7k Web : How to see your website from different countries?
+20.8k Golang : Convert date string to variants of time.Time type examples
+29.3k Golang : Save map/struct to JSON or XML file
+11.5k Golang : Generate DSA private, public key and PEM files example
+5.7k Golang : Frobnicate or tweaking a string example
+17k Golang : Get number of CPU cores
+43.5k Golang : Get hardware information such as disk, memory and CPU usage