Skip to content

Commit 1a12759

Browse files
committed
Only test unique angles
1 parent 4678fc7 commit 1a12759

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/geom/intersects/GetRaysFromPointToPolygon.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var GetRaysFromPointToPolygon = function (x, y, polygons)
6161
}
6262

6363
var intersects = [];
64+
var angles = [];
6465

6566
for (var i = 0; i < polygons.length; i++)
6667
{
@@ -70,10 +71,16 @@ var GetRaysFromPointToPolygon = function (x, y, polygons)
7071
{
7172
var angle = Math.atan2(points[p].y - y, points[p].x - x);
7273

73-
// +- 0.00001 rads to catch lines behind segment corners
74-
CheckIntersects(angle, x, y, polygons, intersects);
75-
CheckIntersects(angle - 0.00001, x, y, polygons, intersects);
76-
CheckIntersects(angle + 0.00001, x, y, polygons, intersects);
74+
if (angles.indexOf(angle) === -1)
75+
{
76+
// +- 0.00001 rads to catch lines behind segment corners
77+
78+
CheckIntersects(angle, x, y, polygons, intersects);
79+
CheckIntersects(angle - 0.00001, x, y, polygons, intersects);
80+
CheckIntersects(angle + 0.00001, x, y, polygons, intersects);
81+
82+
angles.push(angle);
83+
}
7784
}
7885
}
7986

0 commit comments

Comments
 (0)