Skip to content

Commit d498a5e

Browse files
ZaqueuCavalcantejazzido
authored andcommitted
Moving logic.
1 parent b8d44f6 commit d498a5e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public final class CohenSutherlandClipping {
3131
private static final int BOTTOM = 4;
3232
private static final int TOP = 8;
3333

34+
private final static float MINIMUM_DELTA = 0.01f;
35+
3436
/**
3537
* Creates a Cohen Sutherland clipper with clip rect (0, 0, 0, 0).
3638
*/
@@ -90,23 +92,23 @@ public boolean clip(Line2D.Float line) {
9092

9193
if ((outsidePointRegion & LEFT) != INSIDE) {
9294
outsidePointX = xMin;
93-
outsidePointY = (Utils.feq(outsidePointX, point1X) ? 0 : outsidePointX-point1X)*lineSlope + point1Y;
95+
outsidePointY = delta(outsidePointX, point1X)*lineSlope + point1Y;
9496
}
9597
else if ((outsidePointRegion & RIGHT) != INSIDE) {
9698
outsidePointX = xMax;
97-
outsidePointY = (Utils.feq(outsidePointX, point1X) ? 0 : outsidePointX-point1X)*lineSlope + point1Y;
99+
outsidePointY = delta(outsidePointX, point1X)*lineSlope + point1Y;
98100
}
99101
else if ((outsidePointRegion & BOTTOM) != INSIDE) {
100102
outsidePointY = yMin;
101103
outsidePointX = lineIsVertical
102104
? point1X
103-
: (Utils.feq(outsidePointY, point1Y) ? 0 : outsidePointY-point1Y)/lineSlope + point1X;
105+
: delta(outsidePointY, point1Y)/lineSlope + point1X;
104106
}
105107
else if ((outsidePointRegion & TOP) != INSIDE) {
106108
outsidePointY = yMax;
107109
outsidePointX = lineIsVertical
108110
? point1X
109-
: (Utils.feq(outsidePointY, point1Y) ? 0 : outsidePointY-point1Y)/lineSlope + point1X;
111+
: delta(outsidePointY, point1Y)/lineSlope + point1X;
110112
}
111113

112114
if (outsidePointRegion == point1Region) {
@@ -124,4 +126,8 @@ else if ((outsidePointRegion & TOP) != INSIDE) {
124126
return true;
125127
}
126128

129+
private static double delta(double value1, double value2) {
130+
return (Math.abs(value1 - value2) < MINIMUM_DELTA) ? 0 : (value1 - value2);
131+
}
132+
127133
}

0 commit comments

Comments
 (0)