0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

added Query.point

This commit is contained in:
liabru 2015-04-08 23:33:11 +01:00
parent e01dd229a9
commit 98ea7c7955

View file

@ -70,4 +70,33 @@ var Query = {};
return result; 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;
};
})(); })();