Golang image.Point.In, Mod and Mul functions example
package image
Golang image.Point.In, Mod and Mul functions usage example
package main
import (
"fmt"
"image"
)
func main() {
rect := image.Rect(0, 0, 100, 100)
var aPoint, bPoint image.Point
aPoint = image.Pt(10, 10)
bPoint = image.Pt(200, 200)
// In
fmt.Println("aPoint is in rect ? :", aPoint.In(rect)) // should be true
fmt.Println("bPoint is in rect ? :", bPoint.In(rect)) // should be false
// Mod
var qPoint image.Point
qPoint = aPoint.Mod(rect)
fmt.Println("q X is : ", qPoint.X)
fmt.Println("q Y is : ", qPoint.Y)
// Mul
var mPoint image.Point
mPoint = aPoint.Mul(9) // multiply 10 with 9
fmt.Println("mPoint X is : ", mPoint.X) // should return 90
fmt.Println("mPoint Y is : ", mPoint.Y) // should return 90
}
Output :
aPoint is in rect ? : true
bPoint is in rect ? : false
q X is : 10
q Y is : 10
mPoint X is : 90
mPoint Y is : 90
References :
http://golang.org/pkg/image/#Point.In
Advertisement
Something interesting
Tutorials
+13.8k Generate salted password with OpenSSL example
+15.2k Golang : Accurate and reliable decimal calculations
+11.6k Golang : Fuzzy string search or approximate string matching example
+12.4k Golang : Search and extract certain XML data example
+33.6k Golang : How to check if slice or array is empty?
+5.9k Golang : Generate multiplication table from an integer example
+5.9k Golang : Extract unicode string from another unicode string example
+17k Golang : Get input from keyboard
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+5.7k Linux/Unix/PHP : Restart PHP-FPM
+7.1k Nginx : How to block user agent ?
+18.7k Golang : convert int to string