Skip to content

Commit 78635ea

Browse files
committed
Change Shewchuk Orientation filter to Ozaki et al. filter.
1 parent dc34764 commit 78635ea

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

modules/core/src/main/java/org/locationtech/jts/algorithm/CGAlgorithmsDD.java

+4-31
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
108108
return det.signum();
109109
}
110110

111-
/**
112-
* A value which is safely greater than the
113-
* relative round-off error in double-precision numbers
114-
*/
115-
private static final double DP_SAFE_EPSILON = 1e-15;
116-
117111
/**
118112
* A filter for computing the orientation index of three coordinates.
119113
* <p>
@@ -126,7 +120,8 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
126120
* avoid the use of slower robust methods except when they are really needed,
127121
* thus providing better average performance.
128122
* <p>
129-
* Uses an approach due to Jonathan Shewchuk, which is in the public domain.
123+
* Uses an approach due to Ozaki et al., which is published at
124+
* <a href="https://doi.org/10.1007/s10543-015-0574-9">doi:10.1007/s10543-015-0574-9</a>.
130125
*
131126
* @param pax A coordinate
132127
* @param pay A coordinate
@@ -140,34 +135,12 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
140135
private static int orientationIndexFilter(double pax, double pay,
141136
double pbx, double pby, double pcx, double pcy)
142137
{
143-
double detsum;
144-
145138
double detleft = (pax - pcx) * (pby - pcy);
146139
double detright = (pay - pcy) * (pbx - pcx);
147140
double det = detleft - detright;
148141

149-
if (detleft > 0.0) {
150-
if (detright <= 0.0) {
151-
return signum(det);
152-
}
153-
else {
154-
detsum = detleft + detright;
155-
}
156-
}
157-
else if (detleft < 0.0) {
158-
if (detright >= 0.0) {
159-
return signum(det);
160-
}
161-
else {
162-
detsum = -detleft - detright;
163-
}
164-
}
165-
else {
166-
return signum(det);
167-
}
168-
169-
double errbound = DP_SAFE_EPSILON * detsum;
170-
if ((det >= errbound) || (-det >= errbound)) {
142+
double errbound = Math.abs(detleft + detright) * 3.3306690621773714e-16;
143+
if (Math.abs(det) >= errbound) {
171144
return signum(det);
172145
}
173146

0 commit comments

Comments
 (0)