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
+10.2k Golang : How to profile or log time spend on execution?
+30.6k Golang : Remove characters from string example
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+18.4k Golang : How to remove certain lines from a file
+13.6k Golang : reCAPTCHA example
+9.2k Golang : Generate Codabar
+19.2k Golang : Delete item from slice based on index/key position
+5k Golang : Display packages names during compilation
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+7.4k Golang : How to detect if a sentence ends with a punctuation?
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+12.2k Golang : calculate elapsed run time