[geos-commits] [SCM] GEOS branch 3.13 updated. 29e3f0583318fa194d1b27fcf35497bb8c312b48

git at osgeo.org git at osgeo.org
Wed Nov 20 17:24:06 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, 3.13 has been updated
       via  29e3f0583318fa194d1b27fcf35497bb8c312b48 (commit)
      from  23c7c2e96e32933701b81f536c8762a36f8d3379 (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 29e3f0583318fa194d1b27fcf35497bb8c312b48
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 30877064d..6eb86f277 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -6,6 +6,7 @@
   - Fix RelateNG for computing IM for empty-nonempty cases (Martin Davis)
   - Fix LineString->getPoint(n) for M geometries (GH-1191, @hsieyuan)
   - 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
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