1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
4 
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
7 
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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_multipoint()120 inline void test_multipoint_multipoint()
121 {
122     typedef bg::model::multi_point<P> MP;
123 
124     typedef test_disjoint tester;
125 
126     tester::apply("mp-mp-01",
127                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
128                   from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
129                   false);
130 
131     tester::apply("mp-mp-02",
132                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
133                   from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
134                   true);
135 
136     tester::apply("mp-mp-03",
137                   from_wkt<MP>("MULTIPOINT()"),
138                   from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
139                   true);
140 
141     tester::apply("mp-mp-04",
142                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
143                   from_wkt<MP>("MULTIPOINT()"),
144                   true);
145 }
146 
147 //============================================================================
148 
149 template <typename CoordinateType>
test_pointlike_pointlike()150 inline void test_pointlike_pointlike()
151 {
152     typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
153 
154     test_point_point<point_type>();
155     test_point_multipoint<point_type>();
156 
157     test_multipoint_multipoint<point_type>();
158 }
159 
160 //============================================================================
161 
BOOST_AUTO_TEST_CASE(test_pointlike_pointlike_all)162 BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all )
163 {
164     test_pointlike_pointlike<double>();
165     test_pointlike_pointlike<int>();
166 #ifdef HAVE_TTMATH
167     test_pointlike_pointlike<ttmath_big>();
168 #endif
169 }
170