Skip to content

Commit 332bbcd

Browse files
committed
Patch over bad behaviour for near-parallel boxes and distancetree.
Unfortunately, this "fix" is probably breakable, just put the boxes closer and closer together until we get "close enough to be the same" results from the edge normal comparison again. Only way around this is to do dot product and comparisons in higher-than-double space References #4223 git-svn-id: http://svn.osgeo.org/postgis/trunk@16981 b70326c6-7e19-0410-871a-916f4a2858ee
1 parent 65a6f49 commit 332bbcd

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

liblwgeom/cunit/cu_geodetic.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ static void test_edge_intersects(void)
586586
GEOGRAPHIC_POINT g;
587587
uint32_t rv;
588588

589+
/* 5m close case */
590+
line2pts("LINESTRING(58.5112113206308 0, 58.511211320077201 0.00090193752520337797)", &A1, &A2);
591+
line2pts("LINESTRING(58.511166525601702 0.00027058124084120699, 58.511166525562899 0.00036077498778824899)", &B1, &B2);
592+
rv = edge_intersects(&A1, &A2, &B1, &B2);
593+
CU_ASSERT(rv == 0);
594+
589595
/* Covers case, end-to-end intersection */
590596
line2pts("LINESTRING(50 -10.999999999999998224, -10.0 50.0)", &A1, &A2);
591597
line2pts("LINESTRING(-10.0 50.0, -10.272779983831613393 -16.937003313332997578)", &B1, &B2);

liblwgeom/cunit/cu_tree.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,35 @@ static void test_tree_circ_distance(void)
177177
LWGEOM *lwg1, *lwg2;
178178
CIRC_NODE *c1, *c2;
179179
SPHEROID s;
180-
double d1, d2, d3, d4;
180+
double d1, d2, d3, d4, e1, e2;
181181
double threshold = 0.0;
182182

183183
spheroid_init(&s, 1.0, 1.0);
184184

185+
/* Ticket #4223 */
186+
/* tall skinny rectangle */
187+
lwg1 = lwgeom_from_wkt("POLYGON((58.5112113206308 0,58.5112113200772 0.000901937525203378,58.511300910044 0.000901937636668872,58.5113009105976 0,58.5112113206308 0))", LW_PARSER_CHECK_NONE);
188+
/* square box 5m to left */
189+
lwg2 = lwgeom_from_wkt("POLYGON((58.5111665256017 0.000270581240841207,58.5111665255629 0.000360774987788249,58.5110769356128 0.000360774943200728,58.5110769356515 0.000270581207400566,58.5111665256017 0.000270581240841207))", LW_PARSER_CHECK_NONE);
190+
c1 = lwgeom_calculate_circ_tree(lwg1);
191+
c2 = lwgeom_calculate_circ_tree(lwg2);
192+
d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
193+
d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
194+
e1 = d1 * WGS84_RADIUS;
195+
e2 = d2 * WGS84_RADIUS;
196+
// printf("d1 = %g d2 = %g\n", d1, d2);
197+
// printf("e1 = %g e2 = %g\n", e1, e2);
198+
// printf("polygon a\n");
199+
// circ_tree_print(c1, 0);
200+
// printf("polygon b\n");
201+
// circ_tree_print(c2, 0);
202+
circ_tree_free(c1);
203+
circ_tree_free(c2);
204+
lwgeom_free(lwg1);
205+
lwgeom_free(lwg2);
206+
CU_ASSERT_DOUBLE_EQUAL(e1, e2, 0.0001);
207+
208+
185209
/* Ticket #1958 */
186210
lwg1 = lwgeom_from_wkt("LINESTRING(22.88333 41.96667,21.32667 42.13667)", LW_PARSER_CHECK_NONE);
187211
lwg2 = lwgeom_from_wkt("POLYGON((22.94472 41.34667,22.87528 41.99028,22.87389 41.98472,22.87472 41.98333,22.94472 41.34667))", LW_PARSER_CHECK_NONE);

liblwgeom/lwgeodetic.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#define NAN 0.0/0.0
3838
#endif
3939

40+
#ifdef FP_TOLERANCE
41+
#undef FP_TOLERANCE
42+
#define FP_TOLERANCE 1e-14
43+
#endif
44+
4045
extern int gbox_geocentric_slow;
4146

4247
#define POW2(x) ((x)*(x))

0 commit comments

Comments
 (0)