From d31ac49128d9f6135b8c52e9b2074cddfd58e475 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 10 Oct 2017 16:33:41 +0000 Subject: [PATCH] lw_dist2d_pt_arc division by zero (References #3874) git-svn-id: http://svn.osgeo.org/postgis/trunk@15944 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_measures.c | 7 +++++++ liblwgeom/measures.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/liblwgeom/cunit/cu_measures.c b/liblwgeom/cunit/cu_measures.c index dc714585e..2bb2798dd 100644 --- a/liblwgeom/cunit/cu_measures.c +++ b/liblwgeom/cunit/cu_measures.c @@ -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; diff --git a/liblwgeom/measures.c b/liblwgeom/measures.c index d6fe302f8..155b1a42e 100644 --- a/liblwgeom/measures.c +++ b/liblwgeom/measures.c @@ -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; -- 2.40.0