mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-25 13:39:06 -05:00
added Query.point
This commit is contained in:
parent
e01dd229a9
commit
98ea7c7955
1 changed files with 29 additions and 0 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in a new issue