mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
added Query.region
This commit is contained in:
parent
e8f5b221f5
commit
b98cef000d
1 changed files with 21 additions and 0 deletions
|
@ -40,4 +40,25 @@ var Query = {};
|
||||||
return collisions;
|
return collisions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all bodies whose bounds are inside (or outside if set) the given set of bounds, from the given set of bodies
|
||||||
|
* @method region
|
||||||
|
* @param {body[]} bodies
|
||||||
|
* @param {bounds} bounds
|
||||||
|
* @param {bool} outside
|
||||||
|
* @return {body[]} The bodies matching the query
|
||||||
|
*/
|
||||||
|
Query.region = function(bodies, bounds, outside) {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
|
var body = bodies[i],
|
||||||
|
overlaps = Bounds.overlaps(body.bounds, bounds);
|
||||||
|
if ((overlaps && !outside) || (!overlaps && outside))
|
||||||
|
result.push(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue