add Rect.Contains(Vec) bool method

This commit is contained in:
faiface 2017-02-25 18:38:22 +01:00
parent 095fec8622
commit 7974f86c4a
1 changed files with 6 additions and 0 deletions

View File

@ -151,3 +151,9 @@ func (r Rect) XYWH() (x, y, w, h float64) {
func (r Rect) Center() Vec { func (r Rect) Center() Vec {
return r.Pos + r.Size.Scaled(0.5) return r.Pos + r.Size.Scaled(0.5)
} }
// Contains checks whether a vector u is contained within this Rect (including it's borders).
func (r Rect) Contains(u Vec) bool {
min, max := r.Pos, r.Pos+r.Size
return min.X() <= u.X() && u.X() <= max.X() && min.Y() <= u.Y() && u.Y() <= max.Y()
}