Skip to content

Commit

Permalink
added Query.point
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 8, 2015
1 parent e01dd22 commit 98ea7c7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/collision/Query.js
Expand Up @@ -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;
};

})();

0 comments on commit 98ea7c7

Please sign in to comment.