From a968d1cd251529ada811de4bf112d0bacdb51051 Mon Sep 17 00:00:00 2001 From: Ben Perry Date: Fri, 25 Aug 2023 20:09:21 -0500 Subject: [PATCH] Define bounds on both circle and rect for use with interfaces --- circle.go | 8 ++++++++ rectangle.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/circle.go b/circle.go index 8e29207..58f3b0e 100644 --- a/circle.go +++ b/circle.go @@ -48,6 +48,14 @@ func (c Circle) Area() float64 { return math.Pi * math.Pow(c.Radius, 2) } +// Bounds returns the bounding box for the circle +func (c Circle) Bounds() Rect { + return Rect{ + Min: V(c.Center.X-c.Radius, c.Center.Y-c.Radius), + Max: V(c.Center.X+c.Radius, c.Center.Y+c.Radius), + } +} + // Moved returns the Circle moved by the given vector delta. func (c Circle) Moved(delta Vec) Circle { return Circle{ diff --git a/rectangle.go b/rectangle.go index 5881da2..767e378 100644 --- a/rectangle.go +++ b/rectangle.go @@ -70,6 +70,11 @@ func (r Rect) Area() float64 { return r.W() * r.H() } +// Bounds returns the bounding box for the rect (itself) +func (r Rect) Bounds() Rect { + return r +} + // Edges will return the four lines which make up the edges of the rectangle. func (r Rect) Edges() [4]Line { corners := r.Vertices()