Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/concept_check.hpp>
|
Chris@16
|
20 #include <boost/function_types/result_type.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/geometry/util/parameter_type_of.hpp>
|
Chris@16
|
23
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace geometry { namespace concept
|
Chris@16
|
26 {
|
Chris@16
|
27
|
Chris@16
|
28
|
Chris@16
|
29 /*!
|
Chris@16
|
30 \brief Checks strategy for within (point-in-polygon)
|
Chris@16
|
31 \ingroup within
|
Chris@16
|
32 */
|
Chris@16
|
33 template <typename Strategy>
|
Chris@16
|
34 class WithinStrategyPolygonal
|
Chris@16
|
35 {
|
Chris@16
|
36 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
|
Chris@16
|
37
|
Chris@16
|
38 // 1) must define state_type
|
Chris@16
|
39 typedef typename Strategy::state_type state_type;
|
Chris@16
|
40
|
Chris@16
|
41 struct checker
|
Chris@16
|
42 {
|
Chris@16
|
43 template <typename ApplyMethod, typename ResultMethod>
|
Chris@16
|
44 static void apply(ApplyMethod const&, ResultMethod const& )
|
Chris@16
|
45 {
|
Chris@16
|
46 typedef typename parameter_type_of
|
Chris@16
|
47 <
|
Chris@16
|
48 ApplyMethod, 0
|
Chris@16
|
49 >::type point_type;
|
Chris@16
|
50 typedef typename parameter_type_of
|
Chris@16
|
51 <
|
Chris@16
|
52 ApplyMethod, 1
|
Chris@16
|
53 >::type segment_point_type;
|
Chris@16
|
54
|
Chris@16
|
55 // CHECK: apply-arguments should both fulfill point concept
|
Chris@16
|
56 BOOST_CONCEPT_ASSERT
|
Chris@16
|
57 (
|
Chris@16
|
58 (concept::ConstPoint<point_type>)
|
Chris@16
|
59 );
|
Chris@16
|
60
|
Chris@16
|
61 BOOST_CONCEPT_ASSERT
|
Chris@16
|
62 (
|
Chris@16
|
63 (concept::ConstPoint<segment_point_type>)
|
Chris@16
|
64 );
|
Chris@16
|
65
|
Chris@16
|
66 // CHECK: return types (result: int, apply: bool)
|
Chris@16
|
67 BOOST_MPL_ASSERT_MSG
|
Chris@16
|
68 (
|
Chris@16
|
69 (boost::is_same
|
Chris@16
|
70 <
|
Chris@16
|
71 bool, typename boost::function_types::result_type<ApplyMethod>::type
|
Chris@16
|
72 >::type::value),
|
Chris@16
|
73 WRONG_RETURN_TYPE_OF_APPLY
|
Chris@16
|
74 , (bool)
|
Chris@16
|
75 );
|
Chris@16
|
76 BOOST_MPL_ASSERT_MSG
|
Chris@16
|
77 (
|
Chris@16
|
78 (boost::is_same
|
Chris@16
|
79 <
|
Chris@16
|
80 int, typename boost::function_types::result_type<ResultMethod>::type
|
Chris@16
|
81 >::type::value),
|
Chris@16
|
82 WRONG_RETURN_TYPE_OF_RESULT
|
Chris@16
|
83 , (int)
|
Chris@16
|
84 );
|
Chris@16
|
85
|
Chris@16
|
86
|
Chris@16
|
87 // CHECK: calling method apply and result
|
Chris@16
|
88 Strategy const* str = 0;
|
Chris@16
|
89 state_type* st = 0;
|
Chris@16
|
90 point_type const* p = 0;
|
Chris@16
|
91 segment_point_type const* sp = 0;
|
Chris@16
|
92
|
Chris@16
|
93 bool b = str->apply(*p, *sp, *sp, *st);
|
Chris@16
|
94 int r = str->result(*st);
|
Chris@16
|
95
|
Chris@16
|
96 boost::ignore_unused_variable_warning(r);
|
Chris@16
|
97 boost::ignore_unused_variable_warning(b);
|
Chris@16
|
98 boost::ignore_unused_variable_warning(str);
|
Chris@16
|
99 }
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102
|
Chris@16
|
103 public :
|
Chris@16
|
104 BOOST_CONCEPT_USAGE(WithinStrategyPolygonal)
|
Chris@16
|
105 {
|
Chris@16
|
106 checker::apply(&Strategy::apply, &Strategy::result);
|
Chris@16
|
107 }
|
Chris@16
|
108 #endif
|
Chris@16
|
109 };
|
Chris@16
|
110
|
Chris@16
|
111 template <typename Strategy>
|
Chris@16
|
112 class WithinStrategyPointBox
|
Chris@16
|
113 {
|
Chris@16
|
114 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
|
Chris@16
|
115
|
Chris@16
|
116 struct checker
|
Chris@16
|
117 {
|
Chris@16
|
118 template <typename ApplyMethod>
|
Chris@16
|
119 static void apply(ApplyMethod const&)
|
Chris@16
|
120 {
|
Chris@16
|
121 typedef typename parameter_type_of
|
Chris@16
|
122 <
|
Chris@16
|
123 ApplyMethod, 0
|
Chris@16
|
124 >::type point_type;
|
Chris@16
|
125 typedef typename parameter_type_of
|
Chris@16
|
126 <
|
Chris@16
|
127 ApplyMethod, 1
|
Chris@16
|
128 >::type box_type;
|
Chris@16
|
129
|
Chris@16
|
130 // CHECK: apply-arguments should fulfill point/box concept
|
Chris@16
|
131 BOOST_CONCEPT_ASSERT
|
Chris@16
|
132 (
|
Chris@16
|
133 (concept::ConstPoint<point_type>)
|
Chris@16
|
134 );
|
Chris@16
|
135
|
Chris@16
|
136 BOOST_CONCEPT_ASSERT
|
Chris@16
|
137 (
|
Chris@16
|
138 (concept::ConstBox<box_type>)
|
Chris@16
|
139 );
|
Chris@16
|
140
|
Chris@16
|
141 // CHECK: return types (apply: bool)
|
Chris@16
|
142 BOOST_MPL_ASSERT_MSG
|
Chris@16
|
143 (
|
Chris@16
|
144 (boost::is_same
|
Chris@16
|
145 <
|
Chris@101
|
146 bool,
|
Chris@16
|
147 typename boost::function_types::result_type<ApplyMethod>::type
|
Chris@16
|
148 >::type::value),
|
Chris@16
|
149 WRONG_RETURN_TYPE
|
Chris@16
|
150 , (bool)
|
Chris@16
|
151 );
|
Chris@16
|
152
|
Chris@16
|
153
|
Chris@16
|
154 // CHECK: calling method apply
|
Chris@16
|
155 Strategy const* str = 0;
|
Chris@16
|
156 point_type const* p = 0;
|
Chris@16
|
157 box_type const* bx = 0;
|
Chris@16
|
158
|
Chris@16
|
159 bool b = str->apply(*p, *bx);
|
Chris@16
|
160
|
Chris@16
|
161 boost::ignore_unused_variable_warning(b);
|
Chris@16
|
162 boost::ignore_unused_variable_warning(str);
|
Chris@16
|
163 }
|
Chris@16
|
164 };
|
Chris@16
|
165
|
Chris@16
|
166
|
Chris@16
|
167 public :
|
Chris@16
|
168 BOOST_CONCEPT_USAGE(WithinStrategyPointBox)
|
Chris@16
|
169 {
|
Chris@16
|
170 checker::apply(&Strategy::apply);
|
Chris@16
|
171 }
|
Chris@16
|
172 #endif
|
Chris@16
|
173 };
|
Chris@16
|
174
|
Chris@16
|
175 template <typename Strategy>
|
Chris@16
|
176 class WithinStrategyBoxBox
|
Chris@16
|
177 {
|
Chris@16
|
178 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
|
Chris@16
|
179
|
Chris@16
|
180 struct checker
|
Chris@16
|
181 {
|
Chris@16
|
182 template <typename ApplyMethod>
|
Chris@16
|
183 static void apply(ApplyMethod const&)
|
Chris@16
|
184 {
|
Chris@16
|
185 typedef typename parameter_type_of
|
Chris@16
|
186 <
|
Chris@16
|
187 ApplyMethod, 0
|
Chris@16
|
188 >::type box_type1;
|
Chris@16
|
189 typedef typename parameter_type_of
|
Chris@16
|
190 <
|
Chris@16
|
191 ApplyMethod, 1
|
Chris@16
|
192 >::type box_type2;
|
Chris@16
|
193
|
Chris@16
|
194 // CHECK: apply-arguments should both fulfill box concept
|
Chris@16
|
195 BOOST_CONCEPT_ASSERT
|
Chris@16
|
196 (
|
Chris@16
|
197 (concept::ConstBox<box_type1>)
|
Chris@16
|
198 );
|
Chris@16
|
199
|
Chris@16
|
200 BOOST_CONCEPT_ASSERT
|
Chris@16
|
201 (
|
Chris@16
|
202 (concept::ConstBox<box_type2>)
|
Chris@16
|
203 );
|
Chris@16
|
204
|
Chris@16
|
205 // CHECK: return types (apply: bool)
|
Chris@16
|
206 BOOST_MPL_ASSERT_MSG
|
Chris@16
|
207 (
|
Chris@16
|
208 (boost::is_same
|
Chris@16
|
209 <
|
Chris@101
|
210 bool,
|
Chris@16
|
211 typename boost::function_types::result_type<ApplyMethod>::type
|
Chris@16
|
212 >::type::value),
|
Chris@16
|
213 WRONG_RETURN_TYPE
|
Chris@16
|
214 , (bool)
|
Chris@16
|
215 );
|
Chris@16
|
216
|
Chris@16
|
217
|
Chris@16
|
218 // CHECK: calling method apply
|
Chris@16
|
219 Strategy const* str = 0;
|
Chris@16
|
220 box_type1 const* b1 = 0;
|
Chris@16
|
221 box_type2 const* b2 = 0;
|
Chris@16
|
222
|
Chris@16
|
223 bool b = str->apply(*b1, *b2);
|
Chris@16
|
224
|
Chris@16
|
225 boost::ignore_unused_variable_warning(b);
|
Chris@16
|
226 boost::ignore_unused_variable_warning(str);
|
Chris@16
|
227 }
|
Chris@16
|
228 };
|
Chris@16
|
229
|
Chris@16
|
230
|
Chris@16
|
231 public :
|
Chris@16
|
232 BOOST_CONCEPT_USAGE(WithinStrategyBoxBox)
|
Chris@16
|
233 {
|
Chris@16
|
234 checker::apply(&Strategy::apply);
|
Chris@16
|
235 }
|
Chris@16
|
236 #endif
|
Chris@16
|
237 };
|
Chris@16
|
238
|
Chris@16
|
239 // So now: boost::geometry::concept::within
|
Chris@101
|
240 namespace within
|
Chris@101
|
241 {
|
Chris@16
|
242
|
Chris@16
|
243 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
244 namespace dispatch
|
Chris@16
|
245 {
|
Chris@16
|
246
|
Chris@16
|
247 template <typename FirstTag, typename SecondTag, typename CastedTag, typename Strategy>
|
Chris@16
|
248 struct check_within
|
Chris@16
|
249 {};
|
Chris@16
|
250
|
Chris@16
|
251
|
Chris@16
|
252 template <typename AnyTag, typename Strategy>
|
Chris@16
|
253 struct check_within<point_tag, AnyTag, areal_tag, Strategy>
|
Chris@16
|
254 {
|
Chris@16
|
255 BOOST_CONCEPT_ASSERT( (WithinStrategyPolygonal<Strategy>) );
|
Chris@16
|
256 };
|
Chris@16
|
257
|
Chris@16
|
258
|
Chris@16
|
259 template <typename Strategy>
|
Chris@16
|
260 struct check_within<point_tag, box_tag, areal_tag, Strategy>
|
Chris@16
|
261 {
|
Chris@16
|
262 BOOST_CONCEPT_ASSERT( (WithinStrategyPointBox<Strategy>) );
|
Chris@16
|
263 };
|
Chris@16
|
264
|
Chris@16
|
265 template <typename Strategy>
|
Chris@16
|
266 struct check_within<box_tag, box_tag, areal_tag, Strategy>
|
Chris@16
|
267 {
|
Chris@16
|
268 BOOST_CONCEPT_ASSERT( (WithinStrategyBoxBox<Strategy>) );
|
Chris@16
|
269 };
|
Chris@16
|
270
|
Chris@16
|
271
|
Chris@16
|
272 } // namespace dispatch
|
Chris@16
|
273 #endif
|
Chris@16
|
274
|
Chris@16
|
275
|
Chris@16
|
276 /*!
|
Chris@16
|
277 \brief Checks, in compile-time, the concept of any within-strategy
|
Chris@16
|
278 \ingroup concepts
|
Chris@16
|
279 */
|
Chris@16
|
280 template <typename FirstTag, typename SecondTag, typename CastedTag, typename Strategy>
|
Chris@16
|
281 inline void check()
|
Chris@16
|
282 {
|
Chris@16
|
283 dispatch::check_within<FirstTag, SecondTag, CastedTag, Strategy> c;
|
Chris@16
|
284 boost::ignore_unused_variable_warning(c);
|
Chris@16
|
285 }
|
Chris@16
|
286
|
Chris@16
|
287
|
Chris@16
|
288 }}}} // namespace boost::geometry::concept::within
|
Chris@16
|
289
|
Chris@16
|
290
|
Chris@16
|
291 #endif // BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP
|