Define bounds on both circle and rect for use with interfaces
This commit is contained in:
parent
d899a6bbed
commit
a968d1cd25
|
@ -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{
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue