Skip to content

Commit 51561ed

Browse files
committed
Merge pull request #60 from mcharters/fix-clipping-infinite-loop
Fix an infinite loop during clipping
2 parents 5779163 + d33de6a commit 51561ed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/technology/tabula/CohenSutherlandClipping.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ public boolean clip(Line2D.Float line) {
102102

103103
if ((c & LEFT) != INSIDE) {
104104
qx = xMin;
105-
qy = (qx-p1x)*slope + p1y;
105+
qy = (Utils.feq(qx, p1x) ? 0 : qx-p1x)*slope + p1y;
106106
}
107107
else if ((c & RIGHT) != INSIDE) {
108108
qx = xMax;
109-
qy = (qx-p1x)*slope + p1y;
109+
qy = (Utils.feq(qx, p1x) ? 0 : qx-p1x)*slope + p1y;
110110
}
111111
else if ((c & BOTTOM) != INSIDE) {
112112
qy = yMin;
113113
qx = vertical
114114
? p1x
115-
: (qy-p1y)/slope + p1x;
115+
: (Utils.feq(qy, p1y) ? 0 : qy-p1y)/slope + p1x;
116116
}
117117
else if ((c & TOP) != INSIDE) {
118118
qy = yMax;
119119
qx = vertical
120120
? p1x
121-
: (qy-p1y)/slope + p1x;
121+
: (Utils.feq(qy, p1y) ? 0 : qy-p1y)/slope + p1x;
122122
}
123123

124124
if (c == c1) {

0 commit comments

Comments
 (0)