Skip to content

Commit fe9a1e9

Browse files
author
Marakaido
committed
Clean up Cyrus-Beck algorithm
1 parent 109909e commit fe9a1e9

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

algorithm.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function Cyrus_Beck(line, poly, normals, outside)
5353
var W2 = [P2[0]-F[0], P2[1]-F[1]];
5454
//account for trivially invisible segments
5555
if(multiplyScalar(W, normals[i]) < 0 && multiplyScalar(W2, normals[i])<0) return result;
56+
5657
var t = -(multiplyScalar(W, normals[i]))/(multiplyScalar(D, normals[i]));
5758
if(0 <= t && t <= 1)
5859
{
@@ -69,20 +70,11 @@ function Cyrus_Beck(line, poly, normals, outside)
6970
{
7071
P1 = P(lowerLimit);
7172
P2 = P(upperLimit);
72-
if(!isOnEdge(P1, poly) || !isOnEdge(P2, poly)) return result;
7373
}
7474
else return result;
7575
}
76-
else if(lowerLimits.length != 0 && upperLimits.length == 0)
77-
{
78-
P1 = P(Math.max.apply(null, lowerLimits));
79-
if(!isOnEdge(P1, poly)) return result;
80-
}
81-
else if(lowerLimits.length == 0 && upperLimits.length != 0)
82-
{
83-
P2 = P(Math.min.apply(null, upperLimits));
84-
if(!isOnEdge(P2, poly)) return result;
85-
}
76+
else if(lowerLimits.length != 0 && upperLimits.length == 0) P1 = P(Math.max.apply(null, lowerLimits));
77+
else if(lowerLimits.length == 0 && upperLimits.length != 0) P2 = P(Math.min.apply(null, upperLimits));
8678
result[0] = [[P1[0], P1[1], P2[0], P2[1]]];
8779
result[1] = [[oldLine[0], oldLine[1], P1[0], P1[1]], [oldLine[2], oldLine[3], P2[0], P2[1]]];
8880
if(outside)

script.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ var scene = {
6767
if(w.polygon) drawPoly(w.polygon);
6868
});
6969

70-
gc.strokeStyle = newWindow.color;
71-
gc.fillStyle = newWindow.color;
72-
if(newPolygon) drawLines(newPolygon);
73-
if(newContents) newContents.forEach(drawLine);
74-
7570
gc.strokeStyle = "#95A5A6";
7671
//if(this.lines.length != 0) this.lines.forEach(drawLine);
7772

@@ -80,6 +75,11 @@ var scene = {
8075
gc.strokeStyle = w.color;
8176
drawLine(w.line);
8277
});
78+
79+
gc.strokeStyle = newWindow.color;
80+
gc.fillStyle = newWindow.color;
81+
if(newPolygon) drawLines(newPolygon);
82+
if(newContents) newContents.forEach(drawLine);
8383

8484
//if(newContents) newContents.forEach();
8585
window.requestAnimationFrame(draw);

0 commit comments

Comments
 (0)