Commit 0f17173f authored by Roger Peppe's avatar Roger Peppe Committed by Nigel Tao

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
parent 1a8bd671
......@@ -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{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment