diff --git a/src/collision/Query.js b/src/collision/Query.js index f1e2a70..fc80a1c 100644 --- a/src/collision/Query.js +++ b/src/collision/Query.js @@ -40,4 +40,25 @@ var Query = {}; 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; + }; + })(); \ No newline at end of file