mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
optimised Vertices.contains
This commit is contained in:
parent
6883d0d98a
commit
c1988783db
1 changed files with 13 additions and 4 deletions
|
@ -224,12 +224,21 @@ var Common = require('../core/Common');
|
||||||
* @return {boolean} True if the vertices contains point, otherwise false
|
* @return {boolean} True if the vertices contains point, otherwise false
|
||||||
*/
|
*/
|
||||||
Vertices.contains = function(vertices, point) {
|
Vertices.contains = function(vertices, point) {
|
||||||
for (var i = 0; i < vertices.length; i++) {
|
var pointX = point.x,
|
||||||
var vertice = vertices[i],
|
pointY = point.y,
|
||||||
nextVertice = vertices[(i + 1) % vertices.length];
|
verticesLength = vertices.length,
|
||||||
if ((point.x - vertice.x) * (nextVertice.y - vertice.y) + (point.y - vertice.y) * (vertice.x - nextVertice.x) > 0) {
|
vertex = vertices[verticesLength - 1],
|
||||||
|
nextVertex;
|
||||||
|
|
||||||
|
for (var i = 0; i < verticesLength; i++) {
|
||||||
|
nextVertex = vertices[i];
|
||||||
|
|
||||||
|
if ((pointX - vertex.x) * (nextVertex.y - vertex.y)
|
||||||
|
+ (pointY - vertex.y) * (vertex.x - nextVertex.x) > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertex = nextVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue