Golang image.Rectangle.Empty, Eq, In and Inset functions.
package image
Golang image.Rectangle.Empty, Eq, In and Inset 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)
// Empty reports whether the rectangle contains no points.
isempty := rect.Empty()
fmt.Println("Is rect empty ? ", isempty) // should be false
var ZR image.Rectangle
isempty = ZR.Empty()
fmt.Println("Is ZR empty ? ", isempty) // should be true
// Eq reports whether r and s are equal.
equal := ZR.Eq(rect)
fmt.Println("Is ZR equals to rect ? ", equal) // should be false
//In reports whether every point in r is in s.
s := image.Rect(-100, -100, 600, 600)
inside := rect.In(s)
fmt.Println("Is rect inside s ? ", inside) // should be true
// Inset returns the rectangle r inset by n, which may be negative.
// If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.
fmt.Println("Inset by 1 : ", s.Inset(1))
fmt.Println("Inset by 20 : ", s.Inset(20)) // see the diff ?
}
Output :
Min X : 0
Max X : 500
Is rect empty ? false
Is ZR empty ? true
Is ZR equals to rect ? false
Is rect inside s ? true
Inset by 1 : (-99,-99)-(599,599)
Inset by 20 : (-80,-80)-(580,580)
References :
http://golang.org/pkg/image/#Rectangle.Empty
http://golang.org/pkg/image/#Rectangle.Eq
Advertisement
Something interesting
Tutorials
+5.4k How to check with curl if my website or the asset is gzipped ?
+9.7k Golang : List available AWS regions
+37.5k Upload multiple files with Go
+14.6k Golang : Missing Bazaar command
+28.7k Golang : Detect (OS) Operating System
+26k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+18.5k Golang : Send email with attachment
+12k Golang : Convert a rune to unicode style string \u
+13.8k Golang : unknown escape sequence error
+55.3k Golang : Unmarshal JSON from http response
+9.9k Golang : Turn string or text file into slice example
+5.6k Fix fatal error: evacuation not done in time problem