]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/covered_by/test_covered_by.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / covered_by / test_covered_by.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
6
7 // This file was modified by Oracle on 2017.
8 // Modifications copyright (c) 2017 Oracle and/or its affiliates.
9
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Use, modification and distribution is subject to the Boost Software License,
13 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt)
15
16
17 #ifndef BOOST_GEOMETRY_TEST_COVERED_BY_HPP
18 #define BOOST_GEOMETRY_TEST_COVERED_BY_HPP
19
20
21 #include <geometry_test_common.hpp>
22
23 #include <boost/variant/variant.hpp>
24
25 #include <boost/geometry/algorithms/covered_by.hpp>
26 #include <boost/geometry/core/ring_type.hpp>
27 #include <boost/geometry/geometries/ring.hpp>
28 #include <boost/geometry/geometries/polygon.hpp>
29 #include <boost/geometry/geometries/multi_linestring.hpp>
30 #include <boost/geometry/io/wkt/read.hpp>
31 #include <boost/geometry/strategies/strategies.hpp>
32
33 struct no_strategy {};
34
35 template <typename Geometry1, typename Geometry2, typename Strategy>
36 bool call_covered_by(Geometry1 const& geometry1,
37 Geometry2 const& geometry2,
38 Strategy const& strategy)
39 {
40 return bg::covered_by(geometry1, geometry2, strategy);
41 }
42
43 template <typename Geometry1, typename Geometry2>
44 bool call_covered_by(Geometry1 const& geometry1,
45 Geometry2 const& geometry2,
46 no_strategy)
47 {
48 return bg::covered_by(geometry1, geometry2);
49 }
50
51 template <typename Geometry1, typename Geometry2, typename Strategy>
52 void check_geometry(Geometry1 const& geometry1,
53 Geometry2 const& geometry2,
54 std::string const& wkt1,
55 std::string const& wkt2,
56 bool expected,
57 Strategy const& strategy)
58 {
59 bool detected = call_covered_by(geometry1, geometry2, strategy);
60
61 BOOST_CHECK_MESSAGE(detected == expected,
62 "covered_by: " << wkt1
63 << " in " << wkt2
64 << " -> Expected: " << expected
65 << " detected: " << detected);
66 }
67
68 template <typename Geometry1, typename Geometry2>
69 void test_geometry(std::string const& wkt1,
70 std::string const& wkt2, bool expected)
71 {
72 Geometry1 geometry1;
73 Geometry2 geometry2;
74 bg::read_wkt(wkt1, geometry1);
75 bg::read_wkt(wkt2, geometry2);
76 boost::variant<Geometry1> v1(geometry1);
77 boost::variant<Geometry2> v2(geometry2);
78
79 typedef typename bg::strategy::covered_by::services::default_strategy
80 <
81 Geometry1, Geometry2
82 >::type strategy_type;
83
84 check_geometry(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
85 check_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
86 check_geometry(v1, geometry2, wkt1, wkt2, expected, no_strategy());
87 check_geometry(geometry1, v2, wkt1, wkt2, expected, no_strategy());
88 check_geometry(v1, v2, wkt1, wkt2, expected, no_strategy());
89 }
90
91 template <typename Geometry1, typename Geometry2, typename Strategy>
92 void test_geometry(std::string const& wkt1,
93 std::string const& wkt2,
94 bool expected,
95 Strategy const& strategy)
96 {
97 Geometry1 geometry1;
98 Geometry2 geometry2;
99 bg::read_wkt(wkt1, geometry1);
100 bg::read_wkt(wkt2, geometry2);
101
102 check_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy);
103 }
104
105 /*
106
107 template <typename Point, bool Clockwise, bool Closed>
108 void test_ordered_ring(std::string const& wkt_point,
109 std::string const& wkt_geometry, bool expected)
110 {
111 typedef bg::model::ring<Point, Clockwise, Closed> ring_type;
112 ring_type ring;
113 Point point;
114
115 bg::read_wkt(wkt_geometry, ring);
116 if (! Clockwise)
117 {
118 std::reverse(boost::begin(ring), boost::end(ring));
119 }
120 if (! Closed)
121 {
122 ring.resize(ring.size() - 1);
123 }
124
125 bg::read_wkt(wkt_point, point);
126
127 bool detected = bg::covered_by(point, ring);
128
129 BOOST_CHECK_MESSAGE(detected == expected,
130 "covered_by: " << wkt_point
131 << " in " << wkt_geometry
132 << " -> Expected: " << expected
133 << " detected: " << detected
134 << " clockwise: " << int(Clockwise)
135 << " closed: " << int(Closed)
136 );
137
138 // other strategy (note that this one cannot detect OnBorder
139 // (without modifications)
140
141 bg::strategy::covered_by::franklin<Point> franklin;
142 detected = bg::covered_by(point, ring, franklin);
143 if (! on_border)
144 {
145 BOOST_CHECK_MESSAGE(detected == expected,
146 "covered_by: " << wkt_point
147 << " in " << wkt_geometry
148 << " -> Expected: " << expected
149 << " detected: " << detected
150 << " clockwise: " << int(Clockwise)
151 << " closed: " << int(Closed)
152 );
153 }
154
155
156 bg::strategy::covered_by::crossings_multiply<Point> cm;
157 detected = bg::covered_by(point, ring, cm);
158 if (! on_border)
159 {
160 BOOST_CHECK_MESSAGE(detected == expected,
161 "covered_by: " << wkt_point
162 << " in " << wkt_geometry
163 << " -> Expected: " << expected
164 << " detected: " << detected
165 << " clockwise: " << int(Clockwise)
166 << " closed: " << int(Closed)
167 );
168 }
169 }
170
171 template <typename Point>
172 void test_ring(std::string const& wkt_point,
173 std::string const& wkt_geometry,
174 bool expected)
175 {
176 test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected);
177 test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected);
178 test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected);
179 test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected);
180 test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected);
181 }
182 */
183
184 #endif