]> granicus.if.org Git - postgis/commitdiff
lw_dist2d_pt_arc division by zero (References #3874)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 10 Oct 2017 16:33:41 +0000 (16:33 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 10 Oct 2017 16:33:41 +0000 (16:33 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15944 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_measures.c
liblwgeom/measures.c

index dc714585e9e07af89ce56277eb886a39b7fd50b2..2bb2798ddc8cd2d7c5ca325de258ac7d5994b747 100644 (file)
@@ -534,6 +534,13 @@ test_lw_dist2d_pt_arc(void)
        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;
index d6fe302f83155c0061c7a569534de26505c8cd8a..155b1a42ebde974e18c12cd2906fa7aead6452e8 100644 (file)
@@ -1455,6 +1455,15 @@ lw_dist2d_pt_arc(const POINT2D* P, const POINT2D* A1, const POINT2D* A2, const P
        /* 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;