[postgis-tickets] r15947 - lw_dist2d_pt_arc division by zero (References #3874)

Paul Ramsey pramsey at cleverelephant.ca
Tue Oct 10 09:37:32 PDT 2017


Author: pramsey
Date: 2017-10-10 09:37:32 -0700 (Tue, 10 Oct 2017)
New Revision: 15947

Modified:
   branches/2.2/NEWS
   branches/2.2/liblwgeom/cunit/cu_measures.c
   branches/2.2/liblwgeom/measures.c
Log:
lw_dist2d_pt_arc division by zero (References #3874)



Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS	2017-10-10 16:37:14 UTC (rev 15946)
+++ branches/2.2/NEWS	2017-10-10 16:37:32 UTC (rev 15947)
@@ -13,6 +13,7 @@
   - #3878, Single defn of signum in header
   - #3880, Undefined behaviour in TYPMOD_GET_SRID
   - #3875, Fix undefined behaviour in shift operation
+  - #3874, lw_dist2d_pt_arc division by zero
 
 
 PostGIS 2.2.5

Modified: branches/2.2/liblwgeom/cunit/cu_measures.c
===================================================================
--- branches/2.2/liblwgeom/cunit/cu_measures.c	2017-10-10 16:37:14 UTC (rev 15946)
+++ branches/2.2/liblwgeom/cunit/cu_measures.c	2017-10-10 16:37:32 UTC (rev 15947)
@@ -534,6 +534,13 @@
 	CU_ASSERT_EQUAL( rv, LW_SUCCESS );
 	CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
 
+	/* Point on semicircle center */
+	P.x  = 0 ; P.y  = 0;
+	lw_dist2d_distpts_init(&dl, DIST_MIN);
+	rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
+	CU_ASSERT_EQUAL( rv, LW_SUCCESS );
+	CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
+
 	/* Point inside closed circle */
 	P.x  = 0 ; P.y  = 0.5;
 	A2.x = 1; A2.y = 0;

Modified: branches/2.2/liblwgeom/measures.c
===================================================================
--- branches/2.2/liblwgeom/measures.c	2017-10-10 16:37:14 UTC (rev 15946)
+++ branches/2.2/liblwgeom/measures.c	2017-10-10 16:37:32 UTC (rev 15947)
@@ -1440,7 +1440,16 @@
 	
 	/* Distance from point to center */	
 	d = distance2d_pt_pt(&C, P);
-	
+
+	/* P is the center of the circle */
+	if ( FP_EQUALS(d, 0.0) )
+	{
+		dl->distance = radius_A;
+		dl->p1 = *A1;
+		dl->p2 = *P;
+		return LW_TRUE;
+	}
+
 	/* X is the point on the circle where the line from P to C crosses */
 	X.x = C.x + (P->x - C.x) * radius_A / d;
 	X.y = C.y + (P->y - C.y) * radius_A / d;



More information about the postgis-tickets mailing list