17 #include "CUnit/Basic.h"
33 #define DIST2DTEST(str1, str2, res) \
34 do_test_mindistance_tolerance(str1, str2, res, __LINE__, lwgeom_mindistance2d_tolerance);\
35 do_test_mindistance_tolerance(str2, str1, res, __LINE__, lwgeom_mindistance2d_tolerance)
36 #define DIST3DTEST(str1, str2, res) \
37 do_test_mindistance_tolerance(str1, str2, res, __LINE__, lwgeom_mindistance3d_tolerance)
44 double (*distancef)(
const LWGEOM *,
const LWGEOM *,
double))
49 char *msg1 =
"test_mindistance2d_tolerance failed (got %g expected %g) at line %d\n";
50 char *msg2 =
"\n\ndo_test_mindistance2d_tolerance: NULL lwgeom generated from WKT\n %s\n\n";
70 if ( fabs(
distance - expected_res) > 0.00001 )
72 printf(msg1,
distance, expected_res, line);
87 DIST2DTEST(
"POINT(0 0)",
"MULTIPOINT(0 1.5,0 2,0 2.5)", 1.5);
92 DIST2DTEST(
"POINT(0 0)",
"GEOMETRYCOLLECTION(POINT(3 4))", 5.0);
97 DIST2DTEST(
"POINT(0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4)))", 5.0);
102 DIST2DTEST(
"POINT(0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4))))", 5.0);
107 DIST2DTEST(
"POINT(0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(3 4))))", 5.0);
112 DIST2DTEST(
"GEOMETRYCOLLECTION(POINT(0 0))",
"GEOMETRYCOLLECTION(POINT(3 4))", 5.0);
117 DIST2DTEST(
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4)))", 5.0);
122 DIST2DTEST(
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(0 0)))",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(3 4)))", 5.0);
127 DIST2DTEST(
"LINESTRING(-2 0, -0.2 0)",
"POINT(-2 0)", 0);
132 DIST2DTEST(
"LINESTRING(-0.2 0, -2 0)",
"POINT(-2 0)", 0);
137 DIST2DTEST(
"LINESTRING(-1e-8 0, -0.2 0)",
"POINT(-1e-8 0)", 0);
142 DIST2DTEST(
"LINESTRING(-0.2 0, -1e-8 0)",
"POINT(-1e-8 0)", 0);
147 DIST2DTEST(
"CIRCULARSTRING(-1 0, 0 1, 1 0)",
"POINT(0 0)", 1);
148 DIST2DTEST(
"CIRCULARSTRING(-3 0, -2 0, -1 0, 0 1, 1 0)",
"POINT(0 0)", 1);
153 DIST2DTEST(
"CIRCULARSTRING(-1 0, 0 1, 1 0)",
"CIRCULARSTRING(0 0, 1 -1, 2 0)", 1);
158 static char *cs1 =
"CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(1 6, 6 1, 9 7),(9 7, 3 13, 1 6)),COMPOUNDCURVE((3 6, 5 4, 7 4, 7 6),CIRCULARSTRING(7 6,5 8,3 6)))";
167 DIST2DTEST(cs1,
"LINESTRING(0 0, 50 0)", 0.917484);
170 DIST2DTEST(cs1,
"LINESTRING(4 7, 5 6, 6 7)", 0.585786);
171 DIST2DTEST(cs1,
"LINESTRING(10 0, 10 2, 10 0)", 1.52913);
176 DIST2DTEST(cs1,
"POLYGON((10 4, 10 8, 13 8, 13 4, 10 4))", 0.58415);
177 DIST2DTEST(cs1,
"POLYGON((9 4, 9 8, 12 8, 12 4, 9 4))", 0);
178 DIST2DTEST(cs1,
"POLYGON((1 4, 1 8, 4 8, 4 4, 1 4))", 0);
183 DIST2DTEST(cs1,
"CURVEPOLYGON(CIRCULARSTRING(-1 4, 0 5, 1 4, 0 3, -1 4))", 0.0475666);
184 DIST2DTEST(cs1,
"CURVEPOLYGON(CIRCULARSTRING(1 4, 2 5, 3 4, 2 3, 1 4))", 0.0);
189 static char *cs2 =
"MULTISURFACE(POLYGON((0 0,0 4,4 4,4 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(8 2,10 4,12 2,10 0,8 2)))";
190 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(5 2,6 3,7 2,6 1,5 2))", 1);
191 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(4 2,5 3,6 2,5 1,4 2))", 0);
192 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(5 3,6 2,5 1,4 2,5 3))", 0);
193 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(4.5 3,5.5 2,4.5 1,3.5 2,4.5 3))", 0);
194 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(5.5 3,6.5 2,5.5 1,4.5 2,5.5 3))", 0.5);
195 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(10 3,11 2,10 1,9 2,10 3))", 0);
196 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(2 3,3 2,2 1,1 2,2 3))", 0);
197 DIST2DTEST(cs2,
"CURVEPOLYGON(CIRCULARSTRING(5 7,6 8,7 7,6 6,5 7))", 2.60555);
202 DIST2DTEST(
"LINESTRING(0.5 1,0.5 3)",
"MULTICURVE(CIRCULARSTRING(2 3,3 2,2 1,1 2,2 3),(0 0, 0 5))", 0.5);
208 "CURVEPOLYGON(CIRCULARSTRING(7874821 8715927,8907663 8715927,8844683 7750316,7937800 7750316,7874821 8715927))",
209 "POINT(5433865 8243495)", 2271704.2698450615);
216 DIST3DTEST(
"POINT(0 0 0)",
"MULTIPOINT(0 1.5 0, 0 2 0, 0 2.5 0)", 1.5);
217 DIST3DTEST(
"POINT(0 0 0)",
"MULTIPOINT(0 1.5 0, 0 2 0, 0 2.5 0)", 1.5);
218 DIST3DTEST(
"POINT(0 0 0)",
"GEOMETRYCOLLECTION(POINT(3 4 0))", 5.0);
219 DIST3DTEST(
"POINT(0 0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4 0)))", 5.0);
220 DIST3DTEST(
"POINT(0 0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4 0))))", 5.0);
221 DIST3DTEST(
"POINT(0 0)",
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(3 4))))", 5.0);
222 DIST3DTEST(
"GEOMETRYCOLLECTION(POINT(0 0 0))",
"GEOMETRYCOLLECTION(POINT(3 4 0))", 5.0);
223 DIST3DTEST(
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0 0)))",
224 "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4 0)))",
226 DIST3DTEST(
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(0 0 0)))",
227 "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(3 4 0)))",
229 DIST3DTEST(
"LINESTRING(-2 0 0, -0.2 0 0)",
"POINT(-2 0 0)", 0);
230 DIST3DTEST(
"LINESTRING(-0.2 0 0, -2 0 0)",
"POINT(-2 0 0)", 0);
231 DIST3DTEST(
"LINESTRING(-1e-8 0 0, -0.2 0 0)",
"POINT(-1e-8 0 0)", 0);
232 DIST3DTEST(
"LINESTRING(-0.2 0 0, -1e-8 0 0)",
"POINT(-1e-8 0 0)", 0);
235 DIST3DTEST(
"LINESTRING(1 0 0 , 2 0 0)",
"POLYGON((1 1 0, 2 1 0, 2 2 0, 1 2 0, 1 1 0))", 1.0);
236 DIST3DTEST(
"LINESTRING(1 1 1 , 2 1 0)",
"POLYGON((1 1 0, 2 1 0, 2 2 0, 1 2 0, 1 1 0))", 0.0);
237 DIST3DTEST(
"LINESTRING(1 1 1 , 2 1 1)",
"POLYGON((1 1 0, 2 1 0, 2 2 0, 1 2 0, 1 1 0))", 1.0);
239 DIST3DTEST(
"LINESTRING(1 1 1 , 2 2 2)",
"POLYGON((0 0 0, 2 2 2, 3 3 1, 0 0 0))", 0.0);
242 DIST3DTEST(
"LINESTRING(-10000 -10000 0, 0 0 1)",
"POLYGON((0 0 0, 1 0 0, 1 1 0, 0 1 0, 0 0 0))", 1);
245 DIST3DTEST(
"LINESTRING(1 1 1 , 2 2 2)",
"POLYGON((0 0 0, 2 2 2, 3 3 3, 0 0 0))", 0);
263 poly =
lwgeom_from_wkt(
"CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,1 5,0 10),(0 10,10 10,10 0, 0 0)),COMPOUNDCURVE(CIRCULARSTRING(3 7,5 8,7 7),(7 7,7 3,3 3, 3 7)))",
LW_PARSER_CHECK_NONE);
271 CU_ASSERT_EQUAL(
tree_pt(tree, 5, 7.5), 0);
273 CU_ASSERT_EQUAL(
tree_pt(tree, 8, 9), 1);
275 CU_ASSERT_EQUAL(
tree_pt(tree, -1, 5), 0);
277 CU_ASSERT_EQUAL(
tree_pt(tree, -1, 7.5), 0);
279 CU_ASSERT_EQUAL(
tree_pt(tree, 0.2, 7.5), 0);
281 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 0.5), 1);
283 CU_ASSERT_EQUAL(
tree_pt(tree, 2, 7.5), 1);
285 CU_ASSERT_EQUAL(
tree_pt(tree, 7, 7), 1);
294 poly =
lwgeom_from_wkt(
"POLYGON((0 0,0 10,10 10,10 0,9 0,9 9,8 6,8 0,2 0,2 9,1 6,1 0,0 0),(4 4,4 6,6 6,6 4,4 4))",
LW_PARSER_CHECK_NONE);
298 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 6), 1);
300 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 5.5), 1);
302 CU_ASSERT_EQUAL(
tree_pt(tree, -3, 5.5), 0);
304 CU_ASSERT_EQUAL(
tree_pt(tree, 4, 4), 1);
305 CU_ASSERT_EQUAL(
tree_pt(tree, 6, 6), 1);
307 CU_ASSERT_EQUAL(
tree_pt(tree, 4.5, 4), 1);
309 CU_ASSERT_EQUAL(
tree_pt(tree, 8, 0), 1);
310 CU_ASSERT_EQUAL(
tree_pt(tree, 9, 0), 1);
311 CU_ASSERT_EQUAL(
tree_pt(tree, 10, 1), 1);
312 CU_ASSERT_EQUAL(
tree_pt(tree, 9.5, 1), 1);
313 CU_ASSERT_EQUAL(
tree_pt(tree, 0, 10), 1);
315 CU_ASSERT_EQUAL(
tree_pt(tree, 1, 6), 1);
317 CU_ASSERT_EQUAL(
tree_pt(tree, -1, 6), 0);
319 CU_ASSERT_EQUAL(
tree_pt(tree, 5, 5), 0);
321 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 4), 1);
322 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 6), 1);
323 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 9), 1);
335 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 0.5), 1);
337 CU_ASSERT_EQUAL(
tree_pt(tree, 1.5, 0.5), 0);
339 CU_ASSERT_EQUAL(
tree_pt(tree, -1, 1), 0);
341 CU_ASSERT_EQUAL(
tree_pt(tree, 1, 1), 1);
343 CU_ASSERT_EQUAL(
tree_pt(tree, 0.5, 1), 1);
345 CU_ASSERT_EQUAL(
tree_pt(tree, 1, 0.5), 1);
355 CU_ASSERT_EQUAL(
tree_pt(tree, -0.5, 0.5), 0);
357 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 1), 0);
359 CU_ASSERT_EQUAL(
tree_pt(tree, 2, 1), 1);
361 CU_ASSERT_EQUAL(
tree_pt(tree, 0, 1), 1);
363 CU_ASSERT_EQUAL(
tree_pt(tree, 0, 3), 1);
365 CU_ASSERT_EQUAL(
tree_pt(tree, 4, 0), 1);
367 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 3), 1);
369 CU_ASSERT_EQUAL(
tree_pt(tree, 2, 0), 1);
377 poly =
lwgeom_from_wkt(
"POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
LW_PARSER_CHECK_NONE);
381 CU_ASSERT_EQUAL(
tree_pt(tree, -0.5, 3.5), 0);
383 CU_ASSERT_EQUAL(
tree_pt(tree, 6.0, 2.2), 0);
385 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 2), 1);
387 CU_ASSERT_EQUAL(
tree_pt(tree, 1, 0), 1);
389 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 6), 1);
391 CU_ASSERT_EQUAL(
tree_pt(tree, 3, 1), 1);
393 CU_ASSERT_EQUAL(
tree_pt(tree, 0, 2), 1);
395 CU_ASSERT_EQUAL(
tree_pt(tree, 0, 6), 1);
420 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
421 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))"),
427 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
428 "POLYGON((0.3 0.7, 0.3 0.8, 0.4 0.8, 0.4 0.7, 0.3 0.7))"),
434 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
435 "POLYGON((0.3 0.7, 0.3 0.8, 0.4 0.8, 1.3 0.3, 0.3 0.7))"),
441 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
442 "POLYGON((-1 5, 0 5, 0 7, -1 7, -1 5))"),
448 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
449 "GEOMETRYCOLLECTION(MULTILINESTRING((1 2, 3 2)),POINT(1 2))"),
455 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
456 "GEOMETRYCOLLECTION(MULTILINESTRING((6 3, 8 4)),POINT(5 3))"),
462 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
463 "GEOMETRYCOLLECTION(MULTILINESTRING((6 3, 8 4)),POINT(1 3.5))"),
469 "POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))",
470 "GEOMETRYCOLLECTION(MULTILINESTRING((1.5 4.1, 1.6 2)),POINT(1 3.5))"),
499 #define TDT(w1, w2, d) CU_ASSERT_DOUBLE_EQUAL(test_rect_tree_distance_tree_case(w1, w2), d, 0.00001);
506 wkt =
"MULTIPOLYGON(((-123.35702791281 48.4232302445918,-123.35689654493 48.4237265810249,-123.354053908057 48.4234039978588,-123.35417179975 48.4229151379279,-123.354369811539 48.4220987102936,-123.355779071731 48.4222571534228,-123.357238860904 48.4224209369449,-123.35702791281 48.4232302445918)))";
507 TDT(wkt,
"MULTIPOLYGON(((-123.353452578038 48.4259519079838,-123.35072012771 48.4256699150083,-123.347337809991 48.4254740864963,-123.347469111645 48.4245757659326,-123.349409235923 48.4246224093429,-123.349966167324 48.4246562342604,-123.353650661317 48.4250703224683,-123.353452578038 48.4259519079838)))", 0.0017144228293396);
510 TDT(wkt,
"MULTIPOINT(0 1.5,0 2,0 2.5)", 1.5);
511 TDT(wkt,
"GEOMETRYCOLLECTION(POINT(3 4))", 5.0);
512 TDT(wkt,
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4)))", 5.0);
513 TDT(wkt,
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(3 4))))", 5.0);
514 TDT(wkt,
"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTIPOINT(3 4))))", 5.0);
516 TDT(
"LINESTRING(-2 0, -0.2 0)",
"POINT(-2 0)", 0);
517 TDT(
"LINESTRING(-0.2 0, -2 0)",
"POINT(-2 0)", 0);
518 TDT(
"LINESTRING(-1e-8 0, -0.2 0)",
"POINT(-1e-8 0)", 0);
519 TDT(
"LINESTRING(-0.2 0, -1e-8 0)",
"POINT(-1e-8 0)", 0);
521 wkt =
"CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(1 6, 6 1, 9 7),(9 7, 3 13, 1 6)),COMPOUNDCURVE((3 6, 5 4, 7 4, 7 6),CIRCULARSTRING(7 6,5 8,3 6)))";
522 TDT(wkt,
"POINT(3 14)", 1);
523 TDT(wkt,
"POINT(3 8)", 0);
524 TDT(wkt,
"POINT(6 5)", 1);
525 TDT(wkt,
"POINT(6 4)", 0);
527 wkt =
"MULTISURFACE(POLYGON((0 0,0 4,4 4,4 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(8 2,10 4,12 2,10 0,8 2)))";
528 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(5 7,6 8,7 7,6 6,5 7))", 2.60555);
529 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(5 2,6 3,7 2,6 1,5 2))", 1);
530 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(4 2,5 3,6 2,5 1,4 2))", 0);
531 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(5 3,6 2,5 1,4 2,5 3))", 0);
532 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(4.5 3,5.5 2,4.5 1,3.5 2,4.5 3))", 0);
533 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(5.5 3,6.5 2,5.5 1,4.5 2,5.5 3))", 0.5);
534 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(10 3,11 2,10 1,9 2,10 3))", 0);
535 TDT(wkt,
"CURVEPOLYGON(CIRCULARSTRING(2 3,3 2,2 1,1 2,2 3))", 0);
537 wkt =
"CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,5 0,0 0)))";
538 TDT(wkt,
"POINT(3 0)", 0.0);
539 TDT(wkt,
"POINT(5 0)", 0.0);
540 TDT(wkt,
"POINT(7 0)", 2.0);
541 TDT(wkt,
"POINT(2.5 3.5)", 1.0);
544 TDT(wkt,
"POINT(0 1)", 1.0);
545 TDT(wkt,
"POINT(1 0)", 1.0);
547 wkt =
"LINESTRING(0 0,1 0)";
548 TDT(wkt,
"LINESTRING(1 0,1 1)", 0.0);
549 TDT(wkt,
"LINESTRING(0 1,1 1)", 1.0);
551 wkt =
"POLYGON((0 0,0 1,1 1,1 0,0 0))";
552 TDT(wkt,
"POINT(2 2)", sqrt(2));
553 TDT(wkt,
"POINT(0.5 0.5)", 0);
554 TDT(wkt,
"POINT(1 1)", 0);
556 wkt =
"POLYGON((0 0,0 10,10 10,10 0,0 0), (4 4,4 6,6 6,6 4,4 4))";
557 TDT(wkt,
"POINT(5 5)", 1);
558 TDT(wkt,
"POLYGON((5 5,5 5.5,5.5 5.5,5.5 5, 5 5))", 0.5);
578 CU_ASSERT_EQUAL(lineout, NULL);
584 CU_ASSERT_EQUAL(lineout, NULL);
588 "MULTIPOLYGON(((0 0,20 0,20 20,0 20,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6)),((40 0,40 20,60 20,60 0,40 0),(42 2,42 4,44 4,44 2,42 2)))"
592 CU_ASSERT_EQUAL(lineout, NULL);
596 "GEOMETRYCOLLECTION(MULTIPOLYGON(((0 0,20 0,20 20,0 20,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6)),((40 0,40 20,60 20,60 0,40 0),(42 2,42 4,44 4,44 2,42 2))),MULTILINESTRING((0 0,10 0),(20 0, 30 0)),MULTIPOINT(0 0, 3 4))"
598 CU_ASSERT_FATAL(linein != NULL);
601 CU_ASSERT_EQUAL(lineout, NULL);
619 double measure = 105.0;
659 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
666 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
673 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0), 0.000001);
680 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0)-1, 0.000001);
687 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0, 0.000001);
694 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0, 0.000001);
701 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
711 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
734 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
742 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
746 A1.
x = -2; A1.
y = -2;
750 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
755 A2.
x = 0; A2.
y = 0.5;
758 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
766 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0., 0.000001);
774 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0)-1, 0.000001);
782 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0, 0.000001);
791 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0)-1, 0.000001);
801 POINT2D A1, A2, A3, B1, B2, B3;
806 A1.
x = -1.0; A1.
y = 4.0;
807 A2.
x = 0.0; A2.
y = 5.0;
808 A3.
x = 1.0; A3.
y = 4.0;
809 B1.
x = 1.0; B1.
y = 6.0;
810 B2.
x = 6.0; B2.
y = 1.0;
811 B3.
x = 9.0; B3.
y = 7.0;
814 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.0475666, 0.000001);
828 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
837 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0, 0.000001);
846 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2)-1, 0.000001);
855 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0, 0.000001);
859 A1.
x = -2.0; A1.
y = 0.0;
860 A2.
x = 0.0; A2.
y = 2.0;
861 A3.
x = 2.0; A3.
y = 0.0;
864 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
868 A1.
x = -0.5 / sqrt(2.0); A1.
y = 0.5 / sqrt(2.0);
869 A2.
x = 0.0; A2.
y = 0.5;
870 A3.
x = 0.5 / sqrt(2.0); A3.
y = 0.5 / sqrt(2.0);
873 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
877 A1.
x = -0.5 / sqrt(2.0); A1.
y = -0.5 / sqrt(2.0);
878 A2.
x = -0.5; A2.
y = 0.0;
879 A3.
x = -0.5 / sqrt(2.0); A3.
y = 0.5 / sqrt(2.0);
882 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
886 A1.
x = -0.5 / sqrt(2.0); A1.
y = -0.5 / sqrt(2.0);
887 A2.
x = 0.0; A2.
y = -0.5;
888 A3.
x = 0.5 / sqrt(2.0); A3.
y = -0.5 / sqrt(2.0);
891 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.736813, 0.000001);
895 A1.
x = -1.0; A1.
y = 0.0;
896 A2.
x = 0.0; A2.
y = 1.0;
897 A3.
x = 1.0; A3.
y = 0.0;
900 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.0, 0.000001);
903 B1.
x = -10.0; B1.
y = 0.0;
904 B2.
x = 0.0 ; B2.
y = 10.0;
905 B3.
x = 10.0 ; B3.
y = 0.0;
908 A1.
x = -22.0; A1.
y = 0.0;
909 A2.
x = -17.0; A2.
y = -5.0;
910 A3.
x = -12.0; A3.
y = 0.0;
913 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 2.0, 0.000001);
916 A1.
x = -19.0; A1.
y = 0.0;
917 A2.
x = -14.0; A2.
y = -5.0;
918 A3.
x = - 9.0; A3.
y = 0.0;
921 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
924 A1.
x = -9.0; A1.
y = 0.0;
925 A2.
x = -4.0; A2.
y = -5.0;
926 A3.
x = 1.0; A3.
y = 0.0;
929 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
932 A1.
x = -1.0; A1.
y = 0.0;
933 A2.
x = 4.0; A2.
y = -5.0;
934 A3.
x = 9.0; A3.
y = 0.0;
937 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
940 A1.
x = 1.0; A1.
y = 0.0;
941 A2.
x = 6.0; A2.
y = -5.0;
942 A3.
x = 11.0; A3.
y = 0.0;
945 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
948 A1.
x = 11.0; A1.
y = 0.0;
949 A2.
x = 16.0; A2.
y = -5.0;
950 A3.
x = 21.0; A3.
y = 0.0;
953 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
957 A1.
x = -15.0; A1.
y = -6.0;
958 A2.
x = -10.0; A2.
y = -1.0;
959 A3.
x = - 5.0; A3.
y = -6.0;
962 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1.0, 0.000001);
965 A1.
x = -5.0; A1.
y = 0.0;
966 A2.
x = 0.0; A2.
y = 5.0;
967 A3.
x = 5.0; A3.
y = 0.0;
970 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 5.0, 0.000001);
973 A1.
x = -5.0; A1.
y = 0.0;
974 A2.
x = 0.0; A2.
y = -5.0;
975 A3.
x = 5.0; A3.
y = 0.0;
978 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 5.0, 0.000001);
997 CU_ASSERT_DOUBLE_EQUAL(d, M_PI, 0.000001);
999 CU_ASSERT_DOUBLE_EQUAL(d, M_PI, 0.000001);
1004 A3.
x = 0; A3.
y = -1;
1008 CU_ASSERT_DOUBLE_EQUAL(d, M_PI, 0.000001);
1010 CU_ASSERT_DOUBLE_EQUAL(d, M_PI, 0.000001);
1013 A1.
x = -1; A1.
y = 0;
1015 A3.
x = 0; A3.
y = -1;
1019 CU_ASSERT_DOUBLE_EQUAL(d, 3*M_PI_2, 0.000001);
1021 CU_ASSERT_DOUBLE_EQUAL(d, 3*M_PI_2, 0.000001);
1041 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1048 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1051 P.
y = P.
x = 2 * cos(M_PI_4);
1055 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1066 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0), 0.000001);
1073 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1076 P.
x = -1.5; P.
y = 0;
1080 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
1083 P.
x = -2.5; P.
y = 0;
1087 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
1090 P.
y = -2.5; P.
x = 0;
1094 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
1101 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, sqrt(2.0)-1.0, 0.000001);
1124 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1134 "lw_dist2d_ptarray_ptarrayarc called with non-arc input");
1143 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 1, 0.000001);
1152 CU_ASSERT_DOUBLE_EQUAL(dl.
distance, 0.5, 0.000001);
1174 "Both input geometries must have a measure dimension");
1185 "Both input geometries must be linestrings");
1199 "Both input lines must have at least 2 points"
1213 "Both input lines must have at least 2 points"
1451 CU_pSuite suite = CU_add_suite(
"measures", NULL, NULL);
static void test_lw_dist2d_ptarray_ptarrayarc(void)
static void do_test_mindistance_tolerance(char *in1, char *in2, double expected_res, int line, double(*distancef)(const LWGEOM *, const LWGEOM *, double))
static void test_lw_arc_length(void)
static void test_rect_tree_intersects_tree(void)
static void test_mindistance2d_tolerance(void)
static void test_lwgeom_is_trajectory(void)
void measures_suite_setup(void)
static int tree_inter(const char *wkt1, const char *wkt2)
static void test_lwgeom_tcpa(void)
static void test_lw_dist2d_seg_arc(void)
static void test_rect_tree_distance_tree(void)
static void test_lw_dist2d_pt_ptarrayarc(void)
#define DIST2DTEST(str1, str2, res)
#define DIST3DTEST(str1, str2, res)
static void test_lw_dist2d_arc_arc(void)
static void test_rect_tree_contains_point(void)
static void test_lwgeom_locate_along(void)
static void test_lwgeom_segmentize2d(void)
static LWGEOM * lwgeom_from_text(const char *str)
static void test_lw_dist2d_pt_arc(void)
static double test_rect_tree_distance_tree_case(const char *wkt1, const char *wkt2)
static void test_mindistance3d_tolerance(void)
static int tree_pt(RECT_NODE *tree, double x, double y)
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define ASSERT_DOUBLE_EQUAL(o, e)
#define ASSERT_INT_EQUAL(o, e)
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
void lwgeom_request_interrupt(void)
Request interruption of any running code.
LWGEOM * lwgeom_locate_along(const LWGEOM *lwin, double m, double offset)
Determine the location(s) along a measured line where m occurs and return as a multipoint.
void lwgeom_free(LWGEOM *geom)
#define LW_PARSER_CHECK_NONE
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
int lwgeom_is_trajectory(const LWGEOM *geom)
Return LW_TRUE or LW_FALSE depending on whether or not a geometry is a linestring with measure value ...
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
#define LW_TRUE
Return types for functions with status returns.
void lwline_free(LWLINE *line)
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
Datum distance(PG_FUNCTION_ARGS)
RECT_NODE * rect_tree_from_lwgeom(const LWGEOM *lwgeom)
Create a tree index on top an LWGEOM.
int rect_tree_contains_point(RECT_NODE *node, const POINT2D *pt)
void rect_tree_free(RECT_NODE *node)
Recurse from top of node tree and free all children.
double rect_tree_distance_tree(RECT_NODE *n1, RECT_NODE *n2, double threshold)
Return the distance between two RECT_NODE trees.
int rect_tree_intersects_tree(RECT_NODE *n1, RECT_NODE *n2)
Test if two RECT_NODE trees intersect one another.
int lw_dist2d_pt_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, DISTPTS *dl)
int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
Calculate the shortest distance between an arc and an edge.
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
int lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
int lw_dist2d_ptarray_ptarrayarc(const POINTARRAY *pa, const POINTARRAY *pb, DISTPTS *dl)
Test each segment of pa against each arc of pb for distance.
int lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl)
Search all the arcs of pointarray to see which one is closest to p1 Returns minimum distance between ...
Structure used in distance-calculations.
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.