[geos-commits] [SCM] GEOS branch main updated. 54177f2da3d9b8f2903b1a6ed5f7837fda68aabc

git at osgeo.org git at osgeo.org
Tue Jun 27 11:29:21 PDT 2023


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  54177f2da3d9b8f2903b1a6ed5f7837fda68aabc (commit)
      from  95b160126e8d7173cdc424999495c75953c093c1 (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 54177f2da3d9b8f2903b1a6ed5f7837fda68aabc
Author: Max Gabrielsson <max at gabrielsson.com>
Date:   Tue Jun 27 20:28:59 2023 +0200

    Expose geos ryu fork (#919)
    
    Makes ryu number formatting accessible to c clients.

diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index 04e6c4fd3..d1f820d19 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -1443,6 +1443,11 @@ extern "C" {
         GEOSWKBWriter_setIncludeSRID_r(handle, writer, newIncludeSRID);
     }
 
+    int
+    GEOS_printDouble(double d, unsigned int precision, char *result) {
+        return WKTWriter::writeTrimmedNumber(d, precision, result);
+    }
+
     /* GeoJSON Reader */
     GeoJSONReader*
     GEOSGeoJSONReader_create()
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 210fd014e..781ff7c13 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -1898,6 +1898,19 @@ extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(
     GEOSWKTWriter *writer,
     int useOld3D);
 
+/** Print the shortest representation of a double using fixed notation.
+ * Only works for numbers smaller than 1e17 (absolute value).
+ * \param d The number to format.
+ * \param precision The desired precision. (max digits after decimal point)
+ * \param result The buffer to write the result to.
+ * \return the length of the written string.
+ */
+extern int GEOS_DLL GEOS_printDouble(
+    double d,
+    unsigned int precision,
+    char *result
+);
+
 /* ========== WKB Reader ========== */
 
 /** \see GEOSWKBReader_create */
diff --git a/include/geos/io/WKTWriter.h b/include/geos/io/WKTWriter.h
index 09f6184ef..a37973a87 100644
--- a/include/geos/io/WKTWriter.h
+++ b/include/geos/io/WKTWriter.h
@@ -195,6 +195,9 @@ public:
      */
     void setOutputDimension(uint8_t newOutputDimension);
 
+    static std::string writeNumber(double d, bool trim, uint32_t precision);
+    static int writeTrimmedNumber(double d, uint32_t precision, char* buf);
+
 protected:
 
     int decimalPlaces;
diff --git a/src/io/WKTWriter.cpp b/src/io/WKTWriter.cpp
index 77d4b20dc..def315a44 100644
--- a/src/io/WKTWriter.cpp
+++ b/src/io/WKTWriter.cpp
@@ -404,18 +404,21 @@ WKTWriter::appendSequenceText(const CoordinateSequence& seq,
     }
 }
 
-/* protected */
-std::string
-WKTWriter::writeNumber(double d) const
+int 
+WKTWriter::writeTrimmedNumber(double d, uint32_t precision, char* buf)
 {
-    uint32_t precision = decimalPlaces >= 0 ? static_cast<std::uint32_t>(decimalPlaces) : 0;
+    return geos_d2sfixed_buffered_n(d, precision, buf);
+}
+
+std::string
+WKTWriter::writeNumber(double d, bool trim, uint32_t precision) {
     /*
     * For a "trimmed" result, with no trailing zeros we use
     * the ryu library.
     */
     if (trim) {
         char buf[128];
-        int len = geos_d2sfixed_buffered_n(d, precision, buf);
+        int len = writeTrimmedNumber(d, precision, buf);
         buf[len] = '\0';
         std::string s(buf);
         return s;
@@ -433,6 +436,14 @@ WKTWriter::writeNumber(double d) const
     }
 }
 
+/* protected */
+std::string
+WKTWriter::writeNumber(double d) const
+{
+    uint32_t precision = decimalPlaces >= 0 ? static_cast<std::uint32_t>(decimalPlaces) : 0;
+    return writeNumber(d, trim, precision);
+}
+
 void
 WKTWriter::appendLineStringText(const LineString& lineString, OrdinateSet outputOrdinates, int p_level,
                                 bool doIndent, Writer& writer) const

-----------------------------------------------------------------------

Summary of changes:
 capi/geos_c.cpp             |  5 +++++
 capi/geos_c.h.in            | 13 +++++++++++++
 include/geos/io/WKTWriter.h |  3 +++
 src/io/WKTWriter.cpp        | 21 ++++++++++++++++-----
 4 files changed, 37 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list