Golang image.Rectangle.Sub and Union functions example.
package image
Golang image.Rectangle.Sub and Union 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)
p := image.Pt(20, 100)
// Sub returns the rectangle r translated by -p
subRect := rect.Sub(p)
fmt.Println(subRect)
// Union returns the smallest rectangle that contains both r and s.
unionRect := rect.Union(subRect)
fmt.Println(unionRect)
}
Output :
Min X : 0
Max X : 500
(-20,-100)-(480,400)
(-20,-100)-(500,500)
References :
Advertisement
Something interesting
Tutorials
+29.2k Golang : missing Git command
+14.4k Golang : How to filter a map's elements for faster lookup
+11.4k Golang : Concatenate (combine) buffer data example
+34.1k Golang : Create x509 certificate, private and public keys
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+13.9k Golang : convert(cast) string to float value
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+17.5k Golang : Linked list example
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+7.7k Golang : How to execute code at certain day, hour and minute?