1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
5
6 // This file was modified by Oracle on 2014, 2015, 2016.
7 // Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
8
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15
16 #include "test_within.hpp"
17
18
19 #include <boost/geometry/geometries/geometries.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/multi_linestring.hpp>
22
23 template <typename P1, typename P2>
test_l_l()24 void test_l_l()
25 {
26 typedef bg::model::linestring<P1> ls1;
27 typedef bg::model::multi_linestring<ls1> mls1;
28 typedef bg::model::linestring<P2> ls2;
29 typedef bg::model::multi_linestring<ls2> mls2;
30
31 test_geometry<ls1, ls2>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
32
33 test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
34 test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", true);
35 test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(3 2, 2 2, 0 0)", true);
36 test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(3 2, 2 2, 0 0)", true);
37
38 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
39 test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(0 0, 2 2, 4 2)", true);
40 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(4 2, 2 2, 0 0)", true);
41 test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(4 2, 2 2, 0 0)", true);
42
43 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false);
44 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false);
45 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false);
46 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false);
47
48 test_geometry<ls1, ls2>("LINESTRING(0 1, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
49 test_geometry<ls1, ls2>("LINESTRING(0 1, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
50 test_geometry<ls1, ls2>("LINESTRING(1 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
51 test_geometry<ls1, ls2>("LINESTRING(1 0, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
52
53 // duplicated points
54 test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
55 test_geometry<ls1, ls2>("LINESTRING(1 1, 1 1, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
56
57 test_geometry<ls1, ls2>("LINESTRING(0 0, 0 0, 0 0, 1 1, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 3 3)",
58 "LINESTRING(0 0, 2 2, 4 4)", true);
59
60 // invalid linestrings
61 // test_geometry<ls1, ls2>("LINESTRING(0 0)", "LINESTRING(0 0)", false);
62 // test_geometry<ls1, ls2>("LINESTRING(1 1)", "LINESTRING(0 0, 2 2)", true);
63 // test_geometry<ls1, ls2>("LINESTRING(0 0)", "LINESTRING(0 0, 2 2)", false);
64 // test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1)", "LINESTRING(0 0)", false);
65
66 // spikes
67 // FOR NOW DISABLED
68
69 /*test_geometry<ls1, ls2>("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true);
70
71 test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true);
72 test_geometry<ls1, ls2>("LINESTRING(0 0,3 3,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false);
73 test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,4 4,6 3)", true);
74 test_geometry<ls1, ls2>("LINESTRING(0 0,4 4,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false);
75
76 test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", false);*/
77
78 test_geometry<ls1, mls2>("LINESTRING(1 1, 2 2)", "MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", true);
79
80 test_geometry<mls1, ls2>("MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", "LINESTRING(0 0, 5 5)", true);
81
82 test_geometry<mls1, mls2>("MULTILINESTRING((1 1, 2 2),(3 3, 4 4))", "MULTILINESTRING((1 1, 2 2),(2 2, 5 5))", true);
83 }
84
85 template <typename P1, typename P2>
test_all()86 void test_all()
87 {
88 test_l_l<P1, P2>();
89 }
90
91 template <typename P>
test_all()92 void test_all()
93 {
94 test_l_l<P, P>();
95 }
96
test_main(int,char * [])97 int test_main( int , char* [] )
98 {
99 test_all<bg::model::d2::point_xy<int> >();
100 test_all<bg::model::d2::point_xy<double> >();
101 test_all<bg::model::d2::point_xy<double>, bg::model::point<double, 2, bg::cs::cartesian> >();
102
103 #if defined(HAVE_TTMATH)
104 test_all<bg::model::d2::point_xy<ttmath_big> >();
105 #endif
106
107 return 0;
108 }
109