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
+13k Swift : Convert (cast) Int to String ?
+9.2k Golang : How to control fmt or log print format?
+3.7k Golang : Switch Redis database redis.NewClient
+7.4k Golang : Check to see if *File is a file or directory
+8.2k Android Studio : Rating bar example
+16.3k Golang : convert string or integer to big.Int type
+15.2k Golang : Accurate and reliable decimal calculations
+13.5k Golang : Read XML elements data with xml.CharData example
+7.3k Golang : alternative to os.Exit() function
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+6.3k Apt-get to install and uninstall Golang