Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define bounds on both circle and rect for use with interfaces #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 5 additions & 0 deletions rectangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down