Skip to content

Commit 8e4e03e

Browse files
committed
Use Ozaki et al.'s error bound and single-branch evaluation in orientation index filter.
1 parent addad48 commit 8e4e03e

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

include/geos/algorithm/CGAlgorithmsDD.h

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <geos/export.h>
2222
#include <geos/math/DD.h>
23+
#include <cmath>
2324

2425
// Forward declarations
2526
namespace geos {
@@ -92,41 +93,14 @@ class GEOS_DLL CGAlgorithmsDD {
9293
double pbx, double pby,
9394
double pcx, double pcy)
9495
{
95-
/**
96-
* A value which is safely greater than the relative round-off
97-
* error in double-precision numbers
98-
*/
99-
double constexpr DP_SAFE_EPSILON = 1e-15;
100-
101-
double detsum;
10296
double const detleft = (pax - pcx) * (pby - pcy);
10397
double const detright = (pay - pcy) * (pbx - pcx);
10498
double const det = detleft - detright;
105-
106-
if(detleft > 0.0) {
107-
if(detright <= 0.0) {
108-
return orientation(det);
109-
}
110-
else {
111-
detsum = detleft + detright;
112-
}
113-
}
114-
else if(detleft < 0.0) {
115-
if(detright >= 0.0) {
116-
return orientation(det);
117-
}
118-
else {
119-
detsum = -detleft - detright;
120-
}
121-
}
122-
else {
123-
return orientation(det);
124-
}
125-
126-
double const errbound = DP_SAFE_EPSILON * detsum;
127-
if((det >= errbound) || (-det >= errbound)) {
128-
return orientation(det);
129-
}
99+
// Coefficient due to https://doi.org/10.1007/s10543-015-0574-9
100+
double const error = std::abs(detleft + detright)
101+
* 3.3306690621773724e-16;
102+
if (std::abs(det) >= error)
103+
return (det > 0) - (det < 0);
130104
return CGAlgorithmsDD::FAILURE;
131105
};
132106

@@ -188,6 +162,3 @@ class GEOS_DLL CGAlgorithmsDD {
188162

189163
} // namespace geos::algorithm
190164
} // namespace geos
191-
192-
193-

0 commit comments

Comments
 (0)