Returns true if two axis aligned bounding boxes are overlapping * this can be used for simple collision detection between objects * @param {Vector2} posA - Center of box A * @param {Vector2} sizeA - Size of box A * @param {Vector2} posB - Center of box B * @param {Vector2} [sizeB=vec2()] -
(posA, sizeA, posB, sizeB=vec2())
| 211 | * @return {boolean} - True if overlapping |
| 212 | * @memberof Math */ |
| 213 | function isOverlapping(posA, sizeA, posB, sizeB=vec2()) |
| 214 | { |
| 215 | const dx = (posA.x - posB.x)*2; |
| 216 | const dy = (posA.y - posB.y)*2; |
| 217 | const sx = sizeA.x + sizeB.x; |
| 218 | const sy = sizeA.y + sizeB.y; |
| 219 | // symmetric so isOverlapping(A,B) === isOverlapping(B,A) at touching edges |
| 220 | return abs(dx) < sx && abs(dy) < sy; |
| 221 | } |
| 222 | |
| 223 | /** Returns true if a line segment is intersecting an axis aligned box |
| 224 | * @param {Vector2} start - Start of raycast |
no test coverage detected