diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp index 04a34c28f..da11e3690 100644 --- a/capi/geos_ts_c.cpp +++ b/capi/geos_ts_c.cpp @@ -2980,12 +2980,14 @@ extern "C" { return execute(extHandle, [&]() { PrecisionModel newpm; if (gridSize != 0) { - //-- check for an integral scale double scale = 1.0 / gridSize; - double scaleInt = std::round(scale); - //-- if scale factor is essentially integral, use the exact integer value - if (std::abs(scale - scaleInt) < GRIDSIZE_INTEGER_TOLERANCE) { - scale = scaleInt; + //-- check if the gridsize corresponds to an integral scale + if (gridSize < 1) { + double scaleInt = std::round(scale); + //-- if scale factor is essentially integral, use the exact integer value + if (std::abs(scale - scaleInt) < GRIDSIZE_INTEGER_TOLERANCE) { + scale = scaleInt; + } } newpm = PrecisionModel(scale); } diff --git a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp index d80c4eed7..cf0d00cbe 100644 --- a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp +++ b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp @@ -214,5 +214,17 @@ void object::test<13>() "LINESTRING (657035.913 6475590.114, 657075.57 6475500)"); } +//-- test that a large gridsize works +template<> +template<> +void object::test<14>() +{ + geom1_ = fromWKT("LINESTRING (657035.913 6475590.114,657075.57 6475500)"); + geom2_ = GEOSGeom_setPrecision(geom1_, 100, 0); +//std::cout << toWKT(geom2_) << std::endl; + ensure_geometry_equals(geom2_, + "LINESTRING (657000 6475600, 657100 6475500)"); +} + } // namespace tut