1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_disjoint_coverage
13 #endif
14
15 // unit test to test disjoint for all geometry combinations
16
17 #include <iostream>
18
19 #include <boost/test/included/unit_test.hpp>
20
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/core/tags.hpp>
23
24 #include <boost/geometry/strategies/strategies.hpp>
25
26 #include <boost/geometry/io/wkt/wkt.hpp>
27 #include <boost/geometry/io/dsv/write.hpp>
28
29 #include <boost/geometry/geometries/geometries.hpp>
30
31 #include <boost/geometry/algorithms/disjoint.hpp>
32
33 #include <from_wkt.hpp>
34
35
36 #ifdef HAVE_TTMATH
37 #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
38 #endif
39
40 namespace bg = ::boost::geometry;
41
42 //============================================================================
43
44 struct test_disjoint
45 {
46 template <typename Geometry1, typename Geometry2>
applytest_disjoint47 static inline void apply(std::string const& case_id,
48 Geometry1 const& geometry1,
49 Geometry2 const& geometry2,
50 bool expected_result)
51 {
52 bool result = bg::disjoint(geometry1, geometry2);
53 BOOST_CHECK_MESSAGE(result == expected_result,
54 "case ID: " << case_id << ", G1: " << bg::wkt(geometry1)
55 << ", G2: " << bg::wkt(geometry2) << " -> Expected: "
56 << expected_result << ", detected: " << result);
57
58 result = bg::disjoint(geometry2, geometry1);
59 BOOST_CHECK_MESSAGE(result == expected_result,
60 "case ID: " << case_id << ", G1: " << bg::wkt(geometry2)
61 << ", G2: " << bg::wkt(geometry1) << " -> Expected: "
62 << expected_result << ", detected: " << result);
63
64 #ifdef BOOST_GEOMETRY_TEST_DEBUG
65 std::cout << "case ID: " << case_id << "; G1 - G2: ";
66 std::cout << bg::wkt(geometry1) << " - ";
67 std::cout << bg::wkt(geometry2) << std::endl;
68 std::cout << std::boolalpha;
69 std::cout << "expected/computed result: "
70 << expected_result << " / " << result << std::endl;
71 std::cout << std::endl;
72 std::cout << std::noboolalpha;
73 #endif
74 }
75 };
76
77 //============================================================================
78
79 // pointlike-pointlike geometries
80 template <typename P>
test_point_point()81 inline void test_point_point()
82 {
83 typedef test_disjoint tester;
84
85 tester::apply("p-p-01",
86 from_wkt<P>("POINT(0 0)"),
87 from_wkt<P>("POINT(0 0)"),
88 false);
89
90 tester::apply("p-p-02",
91 from_wkt<P>("POINT(0 0)"),
92 from_wkt<P>("POINT(1 1)"),
93 true);
94 }
95
96 template <typename P>
test_point_multipoint()97 inline void test_point_multipoint()
98 {
99 typedef bg::model::multi_point<P> MP;
100
101 typedef test_disjoint tester;
102
103 tester::apply("p-mp-01",
104 from_wkt<P>("POINT(0 0)"),
105 from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
106 false);
107
108 tester::apply("p-mp-02",
109 from_wkt<P>("POINT(0 0)"),
110 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
111 true);
112
113 tester::apply("p-mp-03",
114 from_wkt<P>("POINT(0 0)"),
115 from_wkt<MP>("MULTIPOINT()"),
116 true);
117 }
118
119 template <typename P>
test_multipoint_point()120 inline void test_multipoint_point()
121 {
122 typedef bg::model::multi_point<P> MP;
123
124 typedef test_disjoint tester;
125
126 tester::apply("mp-p-01",
127 from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
128 from_wkt<P>("POINT(0 0)"),
129 false);
130
131 tester::apply("mp-p-02",
132 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
133 from_wkt<P>("POINT(0 0)"),
134 true);
135 }
136
137 template <typename P>
test_multipoint_multipoint()138 inline void test_multipoint_multipoint()
139 {
140 typedef bg::model::multi_point<P> MP;
141
142 typedef test_disjoint tester;
143
144 tester::apply("mp-mp-01",
145 from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
146 from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
147 false);
148
149 tester::apply("mp-mp-02",
150 from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
151 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
152 true);
153
154 tester::apply("mp-mp-03",
155 from_wkt<MP>("MULTIPOINT()"),
156 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
157 true);
158
159 tester::apply("mp-mp-04",
160 from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
161 from_wkt<MP>("MULTIPOINT()"),
162 true);
163 }
164
165 //============================================================================
166
167 template <typename CoordinateType>
test_pointlike_pointlike()168 inline void test_pointlike_pointlike()
169 {
170 typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
171
172 test_point_point<point_type>();
173 test_point_multipoint<point_type>();
174 test_multipoint_point<point_type>();
175 test_multipoint_multipoint<point_type>();
176 }
177
178 //============================================================================
179
BOOST_AUTO_TEST_CASE(test_pointlike_pointlike_all)180 BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all )
181 {
182 test_pointlike_pointlike<double>();
183 test_pointlike_pointlike<int>();
184 #ifdef HAVE_TTMATH
185 test_pointlike_pointlike<ttmath_big>();
186 #endif
187 }
188