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

http://golang.org/pkg/image/#Point.Mod

http://golang.org/pkg/image/#Point.Mul

Advertisement