Skip to content

Commit

Permalink
Fix WKTWriter for small precisions and with trim enabled (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews authored Nov 20, 2024
1 parent f94b913 commit 3bb7596
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix ConcaveHullOfPolygons nested shell handling (GH-1169, Martin Davis)
- Fix RelateNG for computing IM for empty-nonempty cases (Martin Davis)
- Fix TopologyPreservingSimplifier/TaggedLineString to avoid jumping components (JTS-1096, Martin Davis)
- Fix WKTWriter for small precisions and with trim enabled (GH-1199, Mike Taves)

## Changes in 3.13.0
2024-09-06
Expand Down
5 changes: 4 additions & 1 deletion src/io/WKTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ WKTWriter::writeTrimmedNumber(double d, uint32_t precision, char* buf)
// most real-world coordinates, use positional notation
if ( (precision < 4) && (da < 1.0) ) {
// adjust precision to avoid rounding to zero
precision = static_cast<std::uint32_t>(-floor(log10(da)));
const auto higher_prec = static_cast<std::uint32_t>(-floor(log10(da)));
if (higher_prec > precision) {
precision = higher_prec;
}
}
return geos_d2sfixed_buffered_n(d, precision, buf);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/capi/GEOS_printDoubleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ void object::test<1>()
TESTCASE(12, 1.2345678901234e+17, "1.234567890123e+17"),
TESTCASE(13, 1.2345678901234e+17, "1.2345678901234e+17"),
TESTCASE(14, 1.2345678901234e+17, "1.2345678901234e+17"),
TESTCASE(0, 0.0123456789, "0.01"),
TESTCASE(1, 0.0123456789, "0.01"),
TESTCASE(2, 0.0123456789, "0.01"),
TESTCASE(3, 0.0123456789, "0.012"),
TESTCASE(4, 0.0123456789, "0.0123"),
TESTCASE(0, 0.123456789, "0.1"),
TESTCASE(1, 0.123456789, "0.1"),
TESTCASE(2, 0.123456789, "0.12"),
TESTCASE(3, 0.123456789, "0.123"),
TESTCASE(4, 0.123456789, "0.1235"),
TESTCASE(0, 1.23456789, "1"),
TESTCASE(1, 1.23456789, "1.2"),
TESTCASE(2, 1.23456789, "1.23"),
TESTCASE(3, 1.23456789, "1.235"),
TESTCASE(4, 1.23456789, "1.2346"),
};
for (const auto& testcase : testcase_l) {
char buf[28];
Expand Down

0 comments on commit 3bb7596

Please # to comment.