Skip to content

Commit c525cb4

Browse files
committed
Merge branch 'orientation-tighter-error-bound' of github.com:tinko92/geos into tinko92-orientation-tighter-error-bound
2 parents c679bff + 8e4e03e commit c525cb4

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

@@ -187,6 +161,3 @@ class GEOS_DLL CGAlgorithmsDD {
187161

188162
} // namespace geos::algorithm
189163
} // namespace geos
190-
191-
192-

0 commit comments

Comments
 (0)