1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP
15 #define BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP
19 #include <boost/concept_check.hpp>
20 #include <boost/function_types/result_type.hpp>
22 #include <boost/geometry/util/parameter_type_of.hpp>
25 namespace boost { namespace geometry { namespace concepts
30 \brief Checks strategy for within (point-in-polygon)
33 template <typename Strategy>
34 class WithinStrategyPolygonal
36 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
38 // 1) must define state_type
39 typedef typename Strategy::state_type state_type;
43 template <typename ApplyMethod, typename ResultMethod>
44 static void apply(ApplyMethod const&, ResultMethod const& )
46 typedef typename parameter_type_of
50 typedef typename parameter_type_of
53 >::type segment_point_type;
55 // CHECK: apply-arguments should both fulfill point concept
58 (concepts::ConstPoint<point_type>)
63 (concepts::ConstPoint<segment_point_type>)
66 // CHECK: return types (result: int, apply: bool)
71 bool, typename boost::function_types::result_type<ApplyMethod>::type
73 WRONG_RETURN_TYPE_OF_APPLY
80 int, typename boost::function_types::result_type<ResultMethod>::type
82 WRONG_RETURN_TYPE_OF_RESULT
87 // CHECK: calling method apply and result
88 Strategy const* str = 0;
90 point_type const* p = 0;
91 segment_point_type const* sp = 0;
93 bool b = str->apply(*p, *sp, *sp, *st);
94 int r = str->result(*st);
96 boost::ignore_unused_variable_warning(r);
97 boost::ignore_unused_variable_warning(b);
98 boost::ignore_unused_variable_warning(str);
104 BOOST_CONCEPT_USAGE(WithinStrategyPolygonal)
106 checker::apply(&Strategy::apply, &Strategy::result);
111 template <typename Strategy>
112 class WithinStrategyPointBox
114 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
118 template <typename ApplyMethod>
119 static void apply(ApplyMethod const&)
121 typedef typename parameter_type_of
125 typedef typename parameter_type_of
130 // CHECK: apply-arguments should fulfill point/box concept
133 (concepts::ConstPoint<point_type>)
138 (concepts::ConstBox<box_type>)
141 // CHECK: return types (apply: bool)
147 typename boost::function_types::result_type<ApplyMethod>::type
154 // CHECK: calling method apply
155 Strategy const* str = 0;
156 point_type const* p = 0;
157 box_type const* bx = 0;
159 bool b = str->apply(*p, *bx);
161 boost::ignore_unused_variable_warning(b);
162 boost::ignore_unused_variable_warning(str);
168 BOOST_CONCEPT_USAGE(WithinStrategyPointBox)
170 checker::apply(&Strategy::apply);
175 template <typename Strategy>
176 class WithinStrategyBoxBox
178 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
182 template <typename ApplyMethod>
183 static void apply(ApplyMethod const&)
185 typedef typename parameter_type_of
189 typedef typename parameter_type_of
194 // CHECK: apply-arguments should both fulfill box concept
197 (concepts::ConstBox<box_type1>)
202 (concepts::ConstBox<box_type2>)
205 // CHECK: return types (apply: bool)
211 typename boost::function_types::result_type<ApplyMethod>::type
218 // CHECK: calling method apply
219 Strategy const* str = 0;
220 box_type1 const* b1 = 0;
221 box_type2 const* b2 = 0;
223 bool b = str->apply(*b1, *b2);
225 boost::ignore_unused_variable_warning(b);
226 boost::ignore_unused_variable_warning(str);
232 BOOST_CONCEPT_USAGE(WithinStrategyBoxBox)
234 checker::apply(&Strategy::apply);
239 // So now: boost::geometry::concepts::within
243 #ifndef DOXYGEN_NO_DISPATCH
247 template <typename FirstTag, typename SecondTag, typename CastedTag, typename Strategy>
252 template <typename AnyTag, typename Strategy>
253 struct check_within<point_tag, AnyTag, areal_tag, Strategy>
255 BOOST_CONCEPT_ASSERT( (WithinStrategyPolygonal<Strategy>) );
259 template <typename Strategy>
260 struct check_within<point_tag, box_tag, areal_tag, Strategy>
262 BOOST_CONCEPT_ASSERT( (WithinStrategyPointBox<Strategy>) );
265 template <typename Strategy>
266 struct check_within<box_tag, box_tag, areal_tag, Strategy>
268 BOOST_CONCEPT_ASSERT( (WithinStrategyBoxBox<Strategy>) );
272 } // namespace dispatch
277 \brief Checks, in compile-time, the concept of any within-strategy
280 template <typename FirstTag, typename SecondTag, typename CastedTag, typename Strategy>
283 dispatch::check_within<FirstTag, SecondTag, CastedTag, Strategy> c;
284 boost::ignore_unused_variable_warning(c);
288 }}}} // namespace boost::geometry::concepts::within
291 #endif // BOOST_GEOMETRY_STRATEGIES_CONCEPTS_WITHIN_CONCEPT_HPP