Define bounds on both circle and rect for use with interfaces

This commit is contained in:
Ben Perry 2023-08-25 20:09:21 -05:00
parent d899a6bbed
commit a968d1cd25
2 changed files with 13 additions and 0 deletions

View File

@ -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{

View File

@ -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()