mirror of
https://github.com/golang/go
synced 2024-11-21 16:04:45 -07:00
exp/draw: add Point.Eq, Point.Mul, Point.Div, Rectangle.Size methods
R=nigeltao, nigeltao_golang, rsc CC=golang-dev, r https://golang.org/cl/2192048
This commit is contained in:
parent
1a8bd6715d
commit
0f17173f79
@ -28,6 +28,21 @@ func (p Point) Sub(q Point) Point {
|
||||
return Point{p.X - q.X, p.Y - q.Y}
|
||||
}
|
||||
|
||||
// Mul returns the vector p*k.
|
||||
func (p Point) Mul(k int) Point {
|
||||
return Point{p.X * k, p.Y * k}
|
||||
}
|
||||
|
||||
// Div returns the vector p/k.
|
||||
func (p Point) Div(k int) Point {
|
||||
return Point{p.X / k, p.Y / k}
|
||||
}
|
||||
|
||||
// Eq returns whether p and q are equal.
|
||||
func (p Point) Eq(q Point) bool {
|
||||
return p.X == q.X && p.Y == q.Y
|
||||
}
|
||||
|
||||
// ZP is the zero Point.
|
||||
var ZP Point
|
||||
|
||||
@ -59,6 +74,14 @@ func (r Rectangle) Dy() int {
|
||||
return r.Max.Y - r.Min.Y
|
||||
}
|
||||
|
||||
// Size returns r's width and height.
|
||||
func (r Rectangle) Size() Point {
|
||||
return Point{
|
||||
r.Max.X - r.Min.X,
|
||||
r.Max.Y - r.Min.Y,
|
||||
}
|
||||
}
|
||||
|
||||
// Add returns the rectangle r translated by p.
|
||||
func (r Rectangle) Add(p Point) Rectangle {
|
||||
return Rectangle{
|
||||
|
Loading…
Reference in New Issue
Block a user