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
+12.3k Golang : List running EC2 instances and descriptions
+5.7k Get website traffic ranking with Similar Web or Alexa
+11.3k Golang : How to flush a channel before the end of program?
+15k Golang : package is not in GOROOT during compilation
+14.5k Golang : Rename directory
+9.2k Golang : Create and shuffle deck of cards example
+17.9k Golang : Login and logout a user after password verification and redirect example
+18.1k Golang : Convert IPv4 address to decimal number(base 10) or integer
+7.2k Golang : Null and nil value
+6.7k Golang : Skip or discard items of non-interest when iterating example
+24.5k Golang : Time slice or date sort and reverse sort example
+18.5k Golang : Write file with io.WriteString