Golang image.Rectangle.Add, Canon, Dx and Dy functions example.
package image
Golang image.Rectangle.Add, Canon, Dx and Dy 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)
// Add returns the rectangle r translated by p.
pt := image.Pt(100, 100)
newRect := rect.Add(pt)
fmt.Println("Before Add() : ", rect)
fmt.Println("After Add() : ", newRect)
// Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
canonRect := newRect.Canon()
fmt.Println("Canonical Version : ", canonRect)
fmt.Println("canonRect's width : ", canonRect.Dx())
fmt.Println("canonRect's height : ", canonRect.Dy())
}
Output :
Min X : 0
Max X : 500
Before Add() : (0,0)-(500,500)
After Add() : (100,100)-(600,600)
Canonical Version : (100,100)-(600,600)
canonRect's width : 500
canonRect's height : 500
References :
Advertisement
Something interesting
Tutorials
+51.9k Golang : How to get time in milliseconds?
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+17.9k Golang : Qt image viewer example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+5.4k Javascript : How to loop over and parse JSON data?
+18.5k Golang : Set, Get and List environment variables
+18.7k Golang : Implement getters and setters
+10.5k Golang : Create matrix with Gonum Matrix package example
+6.7k Golang : Humanize and Titleize functions