[SCM] PostGIS branch master updated. 3.6.0rc2-36-ge615a0e3e

git at osgeo.org git at osgeo.org
Tue Sep 9 08:43:26 PDT 2025


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 "PostGIS".

The branch, master has been updated
       via  e615a0e3e8b360b566748b125261f7948abe5369 (commit)
      from  651ff3b03cee40ee273d722dfb62cf9861adc20b (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 e615a0e3e8b360b566748b125261f7948abe5369
Author: postrowski <pawel.ostrowski at softelnet.pl>
Date:   Tue Sep 9 08:43:24 2025 -0700

    clamp [0,1] when float arithmetic is used in locate_point functions (!265)
    
    Fix ticket #5082
    
    There are functions that promise to return values from range [0, 1], but due to floating point arithmetic, the return value sometimes may jump outside that range.
    This is problematic in SQL when many functions are composed and the return value exceed 1.
    Adding simple `if` conditions solves the problem.
    
    Reviewed-on: https://gitea.osgeo.org/postgis/postgis/pulls/265
    Reviewed-by: Laurențiu Nicola <lnicola at dend.ro>
    Co-authored-by: postrowski <pawel.ostrowski at softelnet.pl>
    Co-committed-by: postrowski <pawel.ostrowski at softelnet.pl>

diff --git a/liblwgeom/lwgeodetic_measures.c b/liblwgeom/lwgeodetic_measures.c
index 8c2bca596..27f57ecdb 100644
--- a/liblwgeom/lwgeodetic_measures.c
+++ b/liblwgeom/lwgeodetic_measures.c
@@ -548,7 +548,14 @@ ptarray_locate_point_spheroid(
 	if ( (seg >= (pa->npoints-2)) && p2d_same(&proj, p) )
 		return 1.0;
 
-	return partlength / totlength;
+	/* Floating point arithmetic is not reliable, make sure we return values [0,1] */
+	double result = partlength / totlength;
+	if ( result < 0.0 ) {
+		result = 0.0;
+	} else if ( result > 1.0 ) {
+		result = 1.0;
+	}
+	return result;
 }
 
 /*****************************************************************************/
diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c
index 82a3835e4..a1e790dee 100644
--- a/liblwgeom/ptarray.c
+++ b/liblwgeom/ptarray.c
@@ -1486,7 +1486,14 @@ ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistou
 
 	LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
 
-	return plen/tlen;
+	/* Floating point arithmetic is not reliable, make sure we return values [0,1] */
+	double result = plen / tlen;
+	if ( result < 0.0 ) {
+		result = 0.0;
+	} else if ( result > 1.0 ) {
+		result = 1.0;
+	}
+	return result;
 }
 
 /**
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index 81eae6fae..65810319b 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1580,6 +1580,14 @@ SELECT '#5876', ST_AsText(ST_AddPoint(
 		'LINESTRING (1 1, 2 2)'::geometry,
 		'POINT EMPTY'::geometry), 2);
 
+
+-- https://trac.osgeo.org/postgis/ticket/5082 st_linelocatepoint returns value over 1
+select '#5082', ST_LineLocatePoint(
+	'LINESTRING (614506.766313283 390577.5124384557, 614494.089082674 390574.5586551775, 614494.8569439995 390562.1301508558, 614493.5246928157 390549.7664042029, 614486.5713433414 390544.32637928444, 614487.6296766759 390492.9548792321, 614487.6296766759 390492.9548792321)'::geometry,
+	'POINT (614487.6296766759 390492.9548792321)'::geometry
+	) <= 1.0;
+
+
 -- -------------------------------------------------------------------------------------
 -- #5978, geometry_columns not showing right SRID and Type
 -- #5829, SELECT geometry_columns returns unexpected error
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index 37218c8f9..61127d4da 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -484,6 +484,7 @@ ERROR:  Geometry contains invalid coordinates
 #5747|0
 #5855|Knosesmauet
 #5876|LINESTRING(1 1,2 2)
+#5082|t
 public.test5978.shape SRID:4326 TYPE:POINT DIMS:2 
 public.test5978.geometry SRID:4326 TYPE:POINT DIMS:2 
 public|test5829|geom|2|4326|GEOMETRY

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

Summary of changes:
 liblwgeom/lwgeodetic_measures.c | 9 ++++++++-
 liblwgeom/ptarray.c             | 9 ++++++++-
 regress/core/tickets.sql        | 8 ++++++++
 regress/core/tickets_expected   | 1 +
 4 files changed, 25 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list