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
+9.4k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+6.2k Linux/Unix : Commands that you need to be careful about
+37.5k Golang : Converting a negative number to positive number
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+20.4k nginx: [emerg] unknown directive "passenger_enabled"
+19.6k Golang : Get current URL example
+27.4k Golang : Convert CSV data to JSON format and save to file
+21.8k Golang : Convert string slice to struct and access with reflect example
+7.3k Golang : File system scanning
+7.2k Golang : Null and nil value
+17.9k Golang : How to make a file read only and set it to writable again?
+29.3k Golang : Save map/struct to JSON or XML file