diff --git a/src/collision/Query.js b/src/collision/Query.js index 2bd25cb..1eb7ec8 100644 --- a/src/collision/Query.js +++ b/src/collision/Query.js @@ -70,4 +70,33 @@ var Query = {}; return result; }; + /** + * Returns all bodies whose vertices contain the given point, from the given set of bodies. + * @method ray + * @param {body[]} bodies + * @param {vector} point + * @return {body[]} The bodies matching the query + */ + Query.point = function(bodies, point) { + var result = []; + + for (var i = 0; i < bodies.length; i++) { + var body = bodies[i]; + + if (Bounds.contains(body.bounds, point)) { + for (var j = body.parts.length === 1 ? 0 : 1; j < body.parts.length; j++) { + var part = body.parts[j]; + + if (Bounds.contains(part.bounds, point) + && Vertices.contains(part.vertices, point)) { + result.push(body); + break; + } + } + } + } + + return result; + }; + })(); \ No newline at end of file