Skip to content

Commit

Permalink
Only check integral scale facter for gridsize lt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Sep 11, 2023
1 parent 83a75fa commit 135e676
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 7 additions & 5 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 135e676

Please sign in to comment.