MCPcopy
hub / github.com/KilledByAPixel/LittleJS / isOverlapping

Function isOverlapping

src/engineMath.js:213–221  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

211 * @return {boolean} - True if overlapping
212 * @memberof Math */
213function 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

Callers 4

math.test.mjsFile · 0.90
updatePhysicsMethod · 0.85
isOverlappingMethod · 0.85
isMouseOverlappingMethod · 0.85

Calls 1

vec2Function · 0.85

Tested by

no test coverage detected