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
+13.9k Golang : Get current time
+20k Golang : How to run your code only once with sync.Once object
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+46.4k Golang : Encode image to base64 example
+5.3k Python : Convert(cast) string to bytes example
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+9.6k Golang : How to extract video or image files from html source code
+4.7k JavaScript: Add marker function on Google Map
+16.3k Golang :Trim white spaces from a string
+14.5k Golang : Find network of an IP address
+16.9k Golang : Get the IPv4 and IPv6 addresses for a specific network interface