From 0f17173f79d674b3e94e6dabf096116677468fe6 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Thu, 23 Sep 2010 10:58:59 +1000 Subject: [PATCH] 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 --- src/pkg/image/geom.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pkg/image/geom.go b/src/pkg/image/geom.go index 06c13fec16a..d031c37d1c8 100644 --- a/src/pkg/image/geom.go +++ b/src/pkg/image/geom.go @@ -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{