move overlaps func to d2

This commit is contained in:
Gavin Nishizawa 2023-07-18 19:24:32 -07:00
parent ae508c1d89
commit a8cc241c22
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -83,3 +83,9 @@ func (b *Box) Contains(p *Point) bool {
return !(p.X < b.TopLeft.X || b.TopLeft.X+b.Width < p.X ||
p.Y < b.TopLeft.Y || b.TopLeft.Y+b.Height < p.Y)
}
func (b1 Box) Overlaps(b2 Box) bool {
// https://silentmatt.com/rectangle-intersection/
return (b1.TopLeft.X < (b2.TopLeft.X + b2.Width)) && ((b1.TopLeft.X + b1.Width) > b2.TopLeft.X) &&
(b1.TopLeft.Y < (b2.TopLeft.Y + b2.Height)) && ((b1.TopLeft.Y + b1.Height) > b2.TopLeft.Y)
}