diff --git a/interface.go b/interface.go index 7d07503..092ff08 100644 --- a/interface.go +++ b/interface.go @@ -135,6 +135,19 @@ func (r Rect) AddPoint(other Point) Rect { } } +// SubtractPoint is the inverse of AddPoint. Use this only if you need to invert +// the Point being added. +// +// This does r.X - other.X, r.Y - other.Y and keeps the width/height the same. +func (r Rect) SubtractPoint(other Point) Rect { + return Rect{ + X: r.X - other.X, + Y: r.Y - other.Y, + W: r.W, + H: r.H, + } +} + // Text holds information for drawing text. type Text struct { Text string diff --git a/point.go b/point.go index 272238c..6ef757d 100644 --- a/point.go +++ b/point.go @@ -75,6 +75,12 @@ func (p *Point) Add(other Point) { p.Y += other.Y } +// Subtract the other point from your current point. +func (p *Point) Subtract(other Point) { + p.X -= other.X + p.Y -= other.Y +} + // MarshalText to convert the point into text so that a render.Point may be used // as a map key and serialized to JSON. func (p *Point) MarshalText() ([]byte, error) {