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

Paul Ramsey pramsey at cleverelephant.ca
Tue Oct 10 09:33:41 PDT 2017


Author: pramsey
Date: 2017-10-10 09:33:41 -0700 (Tue, 10 Oct 2017)
New Revision: 15944

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


Modified: trunk/liblwgeom/cunit/cu_measures.c
===================================================================
--- trunk/liblwgeom/cunit/cu_measures.c	2017-10-10 16:27:08 UTC (rev 15943)
+++ trunk/liblwgeom/cunit/cu_measures.c	2017-10-10 16:33:41 UTC (rev 15944)
@@ -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: trunk/liblwgeom/measures.c
===================================================================
--- trunk/liblwgeom/measures.c	2017-10-10 16:27:08 UTC (rev 15943)
+++ trunk/liblwgeom/measures.c	2017-10-10 16:33:41 UTC (rev 15944)
@@ -1455,6 +1455,15 @@
 	/* 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