Overlaps tells whether the two given space components overlap with the given tolerance. Uses hitboxes if available, then tries AABB. Algorithm used is the [Separation of Axis](http://www.dyn4j.org/2010/01/sat)
(other SpaceComponent, thisTolerance, otherTolerance engo.Point)
| 278 | // tolerance. Uses hitboxes if available, then tries AABB. |
| 279 | // Algorithm used is the [Separation of Axis](http://www.dyn4j.org/2010/01/sat) |
| 280 | func (sc SpaceComponent) Overlaps(other SpaceComponent, thisTolerance, otherTolerance engo.Point) (bool, engo.Point) { |
| 281 | if len(sc.hitboxes) == 0 && len(other.hitboxes) == 0 { |
| 282 | thisAABB := sc.AABB() |
| 283 | thisAABB.Min.X -= thisTolerance.X |
| 284 | thisAABB.Min.Y -= thisTolerance.Y |
| 285 | thisAABB.Max.X += thisTolerance.X |
| 286 | thisAABB.Max.Y += thisTolerance.Y |
| 287 | |
| 288 | otherAABB := other.AABB() |
| 289 | otherAABB.Min.X -= otherTolerance.X |
| 290 | otherAABB.Min.Y -= otherTolerance.Y |
| 291 | otherAABB.Max.X += otherTolerance.X |
| 292 | otherAABB.Max.Y += otherTolerance.Y |
| 293 | |
| 294 | if IsIntersecting(thisAABB, otherAABB) { |
| 295 | return true, MinimumTranslation(thisAABB, otherAABB) |
| 296 | } |
| 297 | |
| 298 | return false, engo.Point{} |
| 299 | } |
| 300 | if len(sc.hitboxes) == 0 { |
| 301 | sc.hitboxes = []Shape{ |
| 302 | { |
| 303 | Lines: []engo.Line{ |
| 304 | { |
| 305 | P1: engo.Point{X: 0, Y: 0}, |
| 306 | P2: engo.Point{X: sc.Width, Y: 0}, |
| 307 | }, |
| 308 | { |
| 309 | P1: engo.Point{X: sc.Width, Y: 0}, |
| 310 | P2: engo.Point{X: sc.Width, Y: sc.Height}, |
| 311 | }, |
| 312 | { |
| 313 | P1: engo.Point{X: sc.Width, Y: sc.Height}, |
| 314 | P2: engo.Point{X: 0, Y: sc.Height}, |
| 315 | }, |
| 316 | { |
| 317 | P1: engo.Point{X: 0, Y: sc.Height}, |
| 318 | P2: engo.Point{X: 0, Y: 0}, |
| 319 | }, |
| 320 | }, |
| 321 | }, |
| 322 | } |
| 323 | } |
| 324 | if len(other.hitboxes) == 0 { |
| 325 | other.hitboxes = []Shape{ |
| 326 | { |
| 327 | Lines: []engo.Line{ |
| 328 | { |
| 329 | P1: engo.Point{X: 0, Y: 0}, |
| 330 | P2: engo.Point{X: other.Width, Y: 0}, |
| 331 | }, |
| 332 | { |
| 333 | P1: engo.Point{X: other.Width, Y: 0}, |
| 334 | P2: engo.Point{X: other.Width, Y: other.Height}, |
| 335 | }, |
| 336 | { |
| 337 | P1: engo.Point{X: other.Width, Y: other.Height}, |