|
20 | 20 |
|
21 | 21 | #include <geos/export.h> |
22 | 22 | #include <geos/math/DD.h> |
| 23 | +#include <cmath> |
23 | 24 |
|
24 | 25 | // Forward declarations |
25 | 26 | namespace geos { |
@@ -92,41 +93,14 @@ class GEOS_DLL CGAlgorithmsDD { |
92 | 93 | double pbx, double pby, |
93 | 94 | double pcx, double pcy) |
94 | 95 | { |
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; |
102 | 96 | double const detleft = (pax - pcx) * (pby - pcy); |
103 | 97 | double const detright = (pay - pcy) * (pbx - pcx); |
104 | 98 | 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); |
130 | 104 | return CGAlgorithmsDD::FAILURE; |
131 | 105 | }; |
132 | 106 |
|
@@ -188,6 +162,3 @@ class GEOS_DLL CGAlgorithmsDD { |
188 | 162 |
|
189 | 163 | } // namespace geos::algorithm |
190 | 164 | } // namespace geos |
191 | | - |
192 | | - |
193 | | - |
0 commit comments