[postgis-tickets] r17386 - Circular string distances have some failure modes, and test

Paul Ramsey pramsey at cleverelephant.ca
Fri Apr 12 03:16:08 PDT 2019


Author: pramsey
Date: 2019-04-12 15:16:07 -0700 (Fri, 12 Apr 2019)
New Revision: 17386

Modified:
   branches/2.5/NEWS
   branches/2.5/liblwgeom/cunit/cu_measures.c
   branches/2.5/liblwgeom/measures.c
Log:
Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326


Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS	2019-04-12 22:14:52 UTC (rev 17385)
+++ branches/2.5/NEWS	2019-04-12 22:16:07 UTC (rev 17386)
@@ -5,6 +5,7 @@
 
   - #4348, ST_AsMVTGeom (GEOS): Enforce validation at all times (Raúl Marín)
   - #4361, Fix postgis_type_name with (GEOMETRYM,3) (Matt Bretl)
+  - #4326, Fix circular arc distance calculation (Paul Ramsey)
 
 
 PostGIS 2.5.2

Modified: branches/2.5/liblwgeom/cunit/cu_measures.c
===================================================================
--- branches/2.5/liblwgeom/cunit/cu_measures.c	2019-04-12 22:14:52 UTC (rev 17385)
+++ branches/2.5/liblwgeom/cunit/cu_measures.c	2019-04-12 22:16:07 UTC (rev 17386)
@@ -31,7 +31,8 @@
 }
 
 #define DIST2DTEST(str1, str2, res) \
-	do_test_mindistance_tolerance(str1, str2, res, __LINE__, lwgeom_mindistance2d_tolerance)
+	do_test_mindistance_tolerance(str1, str2, res, __LINE__, lwgeom_mindistance2d_tolerance);\
+	do_test_mindistance_tolerance(str2, str1, res, __LINE__, lwgeom_mindistance2d_tolerance)
 #define DIST3DTEST(str1, str2, res) \
 	do_test_mindistance_tolerance(str1, str2, res, __LINE__, lwgeom_mindistance3d_tolerance)
 
@@ -794,6 +795,18 @@
 	POINT2D A1, A2, A3, B1, B2, B3;
 	int rv;
 
+	/* Ticket #4326 */
+	lw_dist2d_distpts_init(&dl, DIST_MIN);
+	A1.x = -1.0; A1.y =  4.0;
+	A2.x =  0.0; A2.y =  5.0;
+	A3.x =  1.0; A3.y =  4.0;
+	B1.x =  1.0; B1.y =  6.0;
+	B2.x =  6.0; B2.y =  1.0;
+	B3.x =  9.0; B3.y =  7.0;
+	rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
+	CU_ASSERT_EQUAL( rv, LW_SUCCESS );
+	CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0475666, 0.000001);
+
 	/* Unit semicircle at 0,0 */
 	B1.x = -1; B1.y = 0;
 	B2.x = 0 ; B2.y = 1;
@@ -958,7 +971,6 @@
 	CU_ASSERT_EQUAL( rv, LW_SUCCESS );
 	CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
 
-
 }
 
 static void

Modified: branches/2.5/liblwgeom/measures.c
===================================================================
--- branches/2.5/liblwgeom/measures.c	2019-04-12 22:14:52 UTC (rev 17385)
+++ branches/2.5/liblwgeom/measures.c	2019-04-12 22:16:07 UTC (rev 17386)
@@ -1500,7 +1500,6 @@
 {
 	POINT2D CA, CB; /* Center points of arcs A and B */
 	double radius_A, radius_B, d; /* Radii of arcs A and B */
-	POINT2D P; /* Temporary point P */
 	POINT2D D; /* Mid-point between the centers CA and CB */
 	int pt_in_arc_A, pt_in_arc_B; /* Test whether potential intersection point is within the arc */
 
@@ -1546,11 +1545,13 @@
 	if ( radius_B > radius_A )
 	{
 		const POINT2D *tmp;
+		POINT2D TP; /* Temporary point P */
+		double td;
 		tmp = B1; B1 = A1; A1 = tmp;
 		tmp = B2; B2 = A2; A2 = tmp;
 		tmp = B3; B3 = A3; A3 = tmp;
-		P = CB; CB = CA; CA = P;
-		d = radius_B; radius_B = radius_A; radius_A = d;
+		TP = CB; CB = CA; CA = TP;
+		td = radius_B; radius_B = radius_A; radius_A = td;
 	}
 
 	/* Circles touch at a point. Is that point within the arcs? */
@@ -1666,8 +1667,8 @@
 	{
 		lw_dist2d_pt_pt(A1, B1, dl);
 		lw_dist2d_pt_pt(A1, B3, dl);
-		lw_dist2d_pt_pt(A2, B1, dl);
-		lw_dist2d_pt_pt(A2, B3, dl);
+		lw_dist2d_pt_pt(A3, B1, dl);
+		lw_dist2d_pt_pt(A3, B3, dl);
 		return LW_TRUE;
 	}
 



More information about the postgis-tickets mailing list