Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ozaki et al.'s error bound and single-branch evaluation in orientation index filter. #1184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions include/geos/algorithm/CGAlgorithmsDD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <geos/export.h>
#include <geos/math/DD.h>
#include <cmath>

// Forward declarations
namespace geos {
Expand Down Expand Up @@ -92,41 +93,14 @@ class GEOS_DLL CGAlgorithmsDD {
double pbx, double pby,
double pcx, double pcy)
{
/**
* A value which is safely greater than the relative round-off
* error in double-precision numbers
*/
double constexpr DP_SAFE_EPSILON = 1e-15;

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

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

double const errbound = DP_SAFE_EPSILON * detsum;
if((det >= errbound) || (-det >= errbound)) {
return orientation(det);
}
// Coefficient due to https://doi.org/10.1007/s10543-015-0574-9
double const error = std::abs(detleft + detright)
* 3.3306690621773724e-16;
if (std::abs(det) >= error)
return (det > 0) - (det < 0);
return CGAlgorithmsDD::FAILURE;
};

Expand Down Expand Up @@ -188,6 +162,3 @@ class GEOS_DLL CGAlgorithmsDD {

} // namespace geos::algorithm
} // namespace geos



Loading