[postgis-tickets] r17385 - Circular string distances have some failure modes, and test
Paul Ramsey
pramsey at cleverelephant.ca
Fri Apr 12 03:14:52 PDT 2019
Author: pramsey
Date: 2019-04-12 15:14:52 -0700 (Fri, 12 Apr 2019)
New Revision: 17385
Modified:
trunk/liblwgeom/cunit/cu_measures.c
trunk/liblwgeom/measures.c
Log:
Circular string distances have some failure modes, and test
suite should test everything bi-directionally.
References #4326
Modified: trunk/liblwgeom/cunit/cu_measures.c
===================================================================
--- trunk/liblwgeom/cunit/cu_measures.c 2019-04-12 19:45:33 UTC (rev 17384)
+++ trunk/liblwgeom/cunit/cu_measures.c 2019-04-12 22:14:52 UTC (rev 17385)
@@ -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);\
do_test_mindistance_tolerance(str2, str1, res, __LINE__, lwgeom_mindistance3d_tolerance)
@@ -875,6 +876,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;
@@ -1039,7 +1052,6 @@
CU_ASSERT_EQUAL( rv, LW_SUCCESS );
CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
-
}
static void
Modified: trunk/liblwgeom/measures.c
===================================================================
--- trunk/liblwgeom/measures.c 2019-04-12 19:45:33 UTC (rev 17384)
+++ trunk/liblwgeom/measures.c 2019-04-12 22:14:52 UTC (rev 17385)
@@ -1499,7 +1499,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 */
@@ -1545,11 +1544,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? */
@@ -1665,8 +1666,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