From da6215c9aec117992ea6881a4998276def128cb5 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Sat, 9 Sep 2023 08:06:47 -0700 Subject: [PATCH] Simplify logic, ensure floor works --- capi/geos_ts_c.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp index 27ee9c0e91..90a5637311 100644 --- a/capi/geos_ts_c.cpp +++ b/capi/geos_ts_c.cpp @@ -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();