[postgis-tickets] r17183 - Geodetic tolerance issue in 32-bit

Paul Ramsey pramsey at cleverelephant.ca
Fri Jan 18 10:03:46 PST 2019


Author: pramsey
Date: 2019-01-18 10:03:46 -0800 (Fri, 18 Jan 2019)
New Revision: 17183

Modified:
   branches/2.4/NEWS
   branches/2.4/liblwgeom/lwgeodetic.c
Log:
Geodetic tolerance issue in 32-bit 
References #4298



Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS	2019-01-18 18:02:30 UTC (rev 17182)
+++ branches/2.4/NEWS	2019-01-18 18:03:46 UTC (rev 17183)
@@ -14,6 +14,7 @@
   - #4289, ST_AsMVTGeom: Transform coordinates space before clipping (Raúl Marín)
   - #4275, Avoid passing a NULL pointer to GEOSisEmpty (Raúl Marín)
   - #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín)
+  - #4298, Geodetic tolerance issue in 32-bit (Paul Ramsey)
 
 
 PostGIS 2.4.6

Modified: branches/2.4/liblwgeom/lwgeodetic.c
===================================================================
--- branches/2.4/liblwgeom/lwgeodetic.c	2019-01-18 18:02:30 UTC (rev 17182)
+++ branches/2.4/liblwgeom/lwgeodetic.c	2019-01-18 18:03:46 UTC (rev 17183)
@@ -36,6 +36,15 @@
 int gbox_geocentric_slow = LW_FALSE;
 
 /**
+* Utility function for ptarray_contains_point_sphere()
+*/
+static int
+point3d_equals(const POINT3D *p1, const POINT3D *p2)
+{
+	return FP_EQUALS(p1->x, p2->x) && FP_EQUALS(p1->y, p2->y) && FP_EQUALS(p1->z, p2->z);
+}
+
+/**
 * Convert a longitude to the range of -PI,PI
 */
 double longitude_radians_normalize(double lon)
@@ -3357,6 +3366,10 @@
 	POINT3D AC; /* Center point of A1/A2 */
 	double min_similarity, similarity;
 
+	/* Boundary case */
+	if (point3d_equals(A1, P) || point3d_equals(A2, P))
+		return LW_TRUE;
+
 	/* The normalized sum bisects the angle between start and end. */
 	vector_sum(A1, A2, &AC);
 	normalize(&AC);
@@ -3365,7 +3378,7 @@
 	min_similarity = dot_product(A1, &AC);
 
 	/* If the edge is sufficiently curved, use the dot product test */
-	if (fabs(1.0 - min_similarity) > 1e-10 )
+	if (fabs(1.0 - min_similarity) > 1e-10)
 	{
 		/* The projection of candidate p onto the center */
 		similarity = dot_product(P, &AC);
@@ -3374,7 +3387,7 @@
 		/* the projection of the start point, the candidate */
 		/* must be closer to the center than the start, so */
 		/* therefor inside the cone */
-		if ( similarity > min_similarity )
+		if (similarity > min_similarity)
 		{
 			return LW_TRUE;
 		}
@@ -3409,14 +3422,6 @@
 }
 
 
-/**
-* Utility function for ptarray_contains_point_sphere()
-*/
-static int
-point3d_equals(const POINT3D *p1, const POINT3D *p2)
-{
-	return FP_EQUALS(p1->x, p2->x) && FP_EQUALS(p1->y, p2->y) && FP_EQUALS(p1->z, p2->z);
-}
 
 /**
 * Utility function for edge_intersects(), signum with a tolerance



More information about the postgis-tickets mailing list