[postgis-tickets] r17387 - Circular string distances have some failure modes, and test
Paul Ramsey
pramsey at cleverelephant.ca
Fri Apr 12 03:16:43 PDT 2019
Author: pramsey
Date: 2019-04-12 15:16:43 -0700 (Fri, 12 Apr 2019)
New Revision: 17387
Modified:
branches/2.4/NEWS
branches/2.4/liblwgeom/cunit/cu_measures.c
branches/2.4/liblwgeom/measures.c
Log:
Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326
Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS 2019-04-12 22:16:07 UTC (rev 17386)
+++ branches/2.4/NEWS 2019-04-12 22:16:43 UTC (rev 17387)
@@ -4,7 +4,9 @@
* Bug Fixes and Enhancements *
- #4361, Fix postgis_type_name with (GEOMETRYM,3) (Matt Bretl)
+ - #4326, Fix circular arc distance calculation (Paul Ramsey)
+
PostGIS 2.4.7
2019/03/11
Modified: branches/2.4/liblwgeom/cunit/cu_measures.c
===================================================================
--- branches/2.4/liblwgeom/cunit/cu_measures.c 2019-04-12 22:16:07 UTC (rev 17386)
+++ branches/2.4/liblwgeom/cunit/cu_measures.c 2019-04-12 22:16:43 UTC (rev 17387)
@@ -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)
@@ -687,6 +688,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;
@@ -851,7 +864,6 @@
CU_ASSERT_EQUAL( rv, LW_SUCCESS );
CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
-
}
static void
Modified: branches/2.4/liblwgeom/measures.c
===================================================================
--- branches/2.4/liblwgeom/measures.c 2019-04-12 22:16:07 UTC (rev 17386)
+++ branches/2.4/liblwgeom/measures.c 2019-04-12 22:16:43 UTC (rev 17387)
@@ -1496,7 +1496,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 */
@@ -1542,11 +1541,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? */
@@ -1662,8 +1663,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