Skip to content

Commit 74f24a0

Browse files
committed
Use new GetLineToPoints function
1 parent 1a12759 commit 74f24a0

1 file changed

Lines changed: 7 additions & 29 deletions

File tree

src/geom/intersects/GetLineToPolygon.js

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
var Vector3 = require('../../math/Vector3');
88
var Vector4 = require('../../math/Vector4');
9-
var GetLineToLine = require('./GetLineToLine');
10-
var Line = require('../line/Line');
11-
12-
// Temp calculation segment
13-
var segment = new Line();
9+
var GetLineToPoints = require('./GetLineToPoints');
1410

1511
// Temp vec3
1612
var tempIntersect = new Vector3();
@@ -37,10 +33,7 @@ var tempIntersect = new Vector3();
3733
*/
3834
var GetLineToPolygon = function (line, polygons, out)
3935
{
40-
if (out === undefined)
41-
{
42-
out = new Vector4();
43-
}
36+
if (out === undefined) { out = new Vector4(); }
4437

4538
if (!Array.isArray(polygons))
4639
{
@@ -49,32 +42,17 @@ var GetLineToPolygon = function (line, polygons, out)
4942

5043
var closestIntersect = false;
5144

52-
// Reset our temporary vec4
45+
// Reset our vec4s
46+
out.set();
5347
tempIntersect.set();
5448

55-
for (var p = 0; p < polygons.length; p++)
49+
for (var i = 0; i < polygons.length; i++)
5650
{
57-
var points = polygons[p].points;
58-
59-
var prev = points[0];
60-
61-
for (var i = 1; i < points.length; i++)
51+
if (GetLineToPoints(line, polygons[i].points, tempIntersect))
6252
{
63-
var current = points[i];
64-
65-
segment.setTo(prev.x, prev.y, current.x, current.y);
66-
67-
prev = current;
68-
69-
if (!GetLineToLine(line, segment, tempIntersect))
70-
{
71-
// No intersection? Carry on ...
72-
continue;
73-
}
74-
7553
if (!closestIntersect || tempIntersect.z < out.z)
7654
{
77-
out.set(tempIntersect.x, tempIntersect.y, tempIntersect.z, p);
55+
out.set(tempIntersect.x, tempIntersect.y, tempIntersect.z, i);
7856

7957
closestIntersect = true;
8058
}

0 commit comments

Comments
 (0)