[geos-commits] [SCM] GEOS branch main updated. 3bb7596c313ea69b9c20f1e8e6d860da3da4fc23
git at osgeo.org
git at osgeo.org
Wed Nov 20 14:28:40 PST 2024
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, main has been updated
via 3bb7596c313ea69b9c20f1e8e6d860da3da4fc23 (commit)
from f94b91384411bf21bd44b8d0947e5a16ba1a3e13 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3bb7596c313ea69b9c20f1e8e6d860da3da4fc23
Author: Mike Taves <mwtoews at gmail.com>
Date: Thu Nov 21 11:28:16 2024 +1300
Fix WKTWriter for small precisions and with trim enabled (#1199)
diff --git a/NEWS.md b/NEWS.md
index 56cfc634b..2d3f1e158 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -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
diff --git a/src/io/WKTWriter.cpp b/src/io/WKTWriter.cpp
index 53fa14269..7c8f04bdc 100644
--- a/src/io/WKTWriter.cpp
+++ b/src/io/WKTWriter.cpp
@@ -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);
}
diff --git a/tests/unit/capi/GEOS_printDoubleTest.cpp b/tests/unit/capi/GEOS_printDoubleTest.cpp
index 69cd61562..0bcf62427 100644
--- a/tests/unit/capi/GEOS_printDoubleTest.cpp
+++ b/tests/unit/capi/GEOS_printDoubleTest.cpp
@@ -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];
-----------------------------------------------------------------------
Summary of changes:
NEWS.md | 1 +
src/io/WKTWriter.cpp | 5 ++++-
tests/unit/capi/GEOS_printDoubleTest.cpp | 15 +++++++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list