0
0
Fork 0
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:
liabru 2014-04-28 12:49:36 +01:00
parent e8f5b221f5
commit b98cef000d

View file

@ -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;
};
})(); })();