Skip to content

Commit

Permalink
Change Shewchuk Orientation filter to Ozaki et al. filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinko92 committed Oct 28, 2024
1 parent dc34764 commit 78635ea
Showing 1 changed file with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
return det.signum();
}

/**
* A value which is safely greater than the
* relative round-off error in double-precision numbers
*/
private static final double DP_SAFE_EPSILON = 1e-15;

/**
* A filter for computing the orientation index of three coordinates.
* <p>
Expand All @@ -126,7 +120,8 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
* avoid the use of slower robust methods except when they are really needed,
* thus providing better average performance.
* <p>
* Uses an approach due to Jonathan Shewchuk, which is in the public domain.
* Uses an approach due to Ozaki et al., which is published at
* <a href="https://doi.org/10.1007/s10543-015-0574-9">doi:10.1007/s10543-015-0574-9</a>.
*
* @param pax A coordinate
* @param pay A coordinate
Expand All @@ -140,34 +135,12 @@ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2)
private static int orientationIndexFilter(double pax, double pay,
double pbx, double pby, double pcx, double pcy)
{
double detsum;

double detleft = (pax - pcx) * (pby - pcy);
double detright = (pay - pcy) * (pbx - pcx);
double det = detleft - detright;

if (detleft > 0.0) {
if (detright <= 0.0) {
return signum(det);
}
else {
detsum = detleft + detright;
}
}
else if (detleft < 0.0) {
if (detright >= 0.0) {
return signum(det);
}
else {
detsum = -detleft - detright;
}
}
else {
return signum(det);
}

double errbound = DP_SAFE_EPSILON * detsum;
if ((det >= errbound) || (-det >= errbound)) {
double errbound = Math.abs(detleft + detright) * 3.3306690621773714e-16;
if (Math.abs(det) >= errbound) {
return signum(det);
}

Expand Down

0 comments on commit 78635ea

Please sign in to comment.