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.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+7.2k CloudFlare : Another way to get visitor's real IP address
+27.6k PHP : Convert(cast) string to bigInt
+4.6k Javascript : Detect when console is activated and do something about it
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+17k Golang : How to save log messages to file?
+7.1k Golang : Gorrila mux.Vars() function example
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+9.8k Golang : Qt get screen resolution and display on center example
+8.8k Golang : Random integer with rand.Seed() within a given range
+11.6k Golang : Fuzzy string search or approximate string matching example
+33k Golang : How to check if a date is within certain range?