]> 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:36:55 +0000 (16:36 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 10 Oct 2017 16:36:55 +0000 (16:36 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@15945 b70326c6-7e19-0410-871a-916f4a2858ee

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

diff --git a/NEWS b/NEWS
index 4007b460ddb0afdbdabe46f3f57cb0783a1ca492..eb9402faaa6fcf68ffce960acb1c28f720bdf569 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ YYYY/MM/DD
   - #3880, Undefined behaviour in TYPMOD_GET_SRID
   - #3875, Fix undefined behaviour in shift operation
   - #3864, Performance improvements for b-tree geometry sorts
+  - #3874, lw_dist2d_pt_arc division by zero
 
 
 PostGIS 2.4.0
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;