Skip to content

Commit

Permalink
Simplify logic, ensure floor works
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Sep 9, 2023
1 parent bd318db commit da6215c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,17 +2979,16 @@ extern "C" {

return execute(extHandle, [&]() {
PrecisionModel newpm;
if(gridSize != 0) {
double scaleNom = 1.0 / gridSize;
double scaleInt = std::floor(scaleNom);
if (std::abs(scaleNom - scaleInt) < GRIDSIZE_INTEGER_TOLERANCE) {
//-- if scale factor is nearly integral, use an exact integer value
newpm = PrecisionModel(scaleInt);
}
else {
//-- otherwise, just use the reciprocal of the grid size
newpm = PrecisionModel(scaleNom);
if (gridSize != 0) {
//-- check for an integral scale
double scale = 1.0 / gridSize;
//-- add a small "bump" to ensure flooring works
double scaleInt = std::floor(scale + 0.1);
//-- if scale factor is essentially integral, use the exact integer value
if (std::abs(scale - scaleInt) < GRIDSIZE_INTEGER_TOLERANCE) {
scale = scaleInt;
}
newpm = PrecisionModel(scale);
}

const PrecisionModel* pm = g->getPrecisionModel();
Expand Down

0 comments on commit da6215c

Please sign in to comment.