Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@101
|
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@101
|
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
Chris@101
|
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
Chris@101
|
6
|
Chris@101
|
7 // This file was modified by Oracle on 2014.
|
Chris@101
|
8 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
|
Chris@101
|
9
|
Chris@101
|
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
Chris@16
|
11
|
Chris@16
|
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
14
|
Chris@16
|
15 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
17 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
|
Chris@16
|
20 #define BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
|
Chris@16
|
21
|
Chris@16
|
22 #include <vector>
|
Chris@16
|
23 #include <iterator>
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/concept_check.hpp>
|
Chris@101
|
26 #include <boost/core/ignore_unused.hpp>
|
Chris@101
|
27 #include <boost/mpl/assert.hpp>
|
Chris@101
|
28 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
29
|
Chris@16
|
30 #include <boost/geometry/util/parameter_type_of.hpp>
|
Chris@16
|
31
|
Chris@16
|
32 #include <boost/geometry/geometries/concepts/point_concept.hpp>
|
Chris@16
|
33 #include <boost/geometry/geometries/segment.hpp>
|
Chris@16
|
34 #include <boost/geometry/geometries/point.hpp>
|
Chris@16
|
35
|
Chris@101
|
36 #include <boost/geometry/strategies/tags.hpp>
|
Chris@101
|
37
|
Chris@16
|
38
|
Chris@16
|
39 namespace boost { namespace geometry { namespace concept
|
Chris@16
|
40 {
|
Chris@16
|
41
|
Chris@16
|
42
|
Chris@16
|
43 /*!
|
Chris@101
|
44 \brief Checks strategy for point-point or point-box or box-box distance
|
Chris@16
|
45 \ingroup distance
|
Chris@16
|
46 */
|
Chris@16
|
47 template <typename Strategy, typename Point1, typename Point2>
|
Chris@16
|
48 struct PointDistanceStrategy
|
Chris@16
|
49 {
|
Chris@16
|
50 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
|
Chris@16
|
51 private :
|
Chris@16
|
52
|
Chris@16
|
53 struct checker
|
Chris@16
|
54 {
|
Chris@16
|
55 template <typename ApplyMethod>
|
Chris@16
|
56 static void apply(ApplyMethod)
|
Chris@16
|
57 {
|
Chris@16
|
58 // 1: inspect and define both arguments of apply
|
Chris@16
|
59 typedef typename parameter_type_of
|
Chris@16
|
60 <
|
Chris@16
|
61 ApplyMethod, 0
|
Chris@16
|
62 >::type ptype1;
|
Chris@16
|
63
|
Chris@16
|
64 typedef typename parameter_type_of
|
Chris@16
|
65 <
|
Chris@16
|
66 ApplyMethod, 1
|
Chris@16
|
67 >::type ptype2;
|
Chris@16
|
68
|
Chris@101
|
69 // 2) must define meta-function "return_type"
|
Chris@16
|
70 typedef typename strategy::distance::services::return_type
|
Chris@16
|
71 <
|
Chris@16
|
72 Strategy, ptype1, ptype2
|
Chris@16
|
73 >::type rtype;
|
Chris@16
|
74
|
Chris@16
|
75 // 3) must define meta-function "comparable_type"
|
Chris@16
|
76 typedef typename strategy::distance::services::comparable_type
|
Chris@16
|
77 <
|
Chris@16
|
78 Strategy
|
Chris@16
|
79 >::type ctype;
|
Chris@16
|
80
|
Chris@16
|
81 // 4) must define meta-function "tag"
|
Chris@16
|
82 typedef typename strategy::distance::services::tag
|
Chris@16
|
83 <
|
Chris@16
|
84 Strategy
|
Chris@16
|
85 >::type tag;
|
Chris@16
|
86
|
Chris@101
|
87 static const bool is_correct_strategy_tag =
|
Chris@101
|
88 boost::is_same<tag, strategy_tag_distance_point_point>::value
|
Chris@101
|
89 || boost::is_same<tag, strategy_tag_distance_point_box>::value
|
Chris@101
|
90 || boost::is_same<tag, strategy_tag_distance_box_box>::value;
|
Chris@101
|
91
|
Chris@101
|
92 BOOST_MPL_ASSERT_MSG
|
Chris@101
|
93 ((is_correct_strategy_tag),
|
Chris@101
|
94 INCORRECT_STRATEGY_TAG,
|
Chris@101
|
95 (types<tag>));
|
Chris@101
|
96
|
Chris@16
|
97 // 5) must implement apply with arguments
|
Chris@16
|
98 Strategy* str = 0;
|
Chris@16
|
99 ptype1 *p1 = 0;
|
Chris@16
|
100 ptype2 *p2 = 0;
|
Chris@16
|
101 rtype r = str->apply(*p1, *p2);
|
Chris@16
|
102
|
Chris@16
|
103 // 6) must define (meta)struct "get_comparable" with apply
|
Chris@16
|
104 ctype c = strategy::distance::services::get_comparable
|
Chris@16
|
105 <
|
Chris@16
|
106 Strategy
|
Chris@16
|
107 >::apply(*str);
|
Chris@16
|
108
|
Chris@16
|
109 // 7) must define (meta)struct "result_from_distance" with apply
|
Chris@16
|
110 r = strategy::distance::services::result_from_distance
|
Chris@16
|
111 <
|
Chris@16
|
112 Strategy,
|
Chris@16
|
113 ptype1, ptype2
|
Chris@16
|
114 >::apply(*str, 1.0);
|
Chris@16
|
115
|
Chris@101
|
116 boost::ignore_unused<tag>();
|
Chris@101
|
117 boost::ignore_unused(str, c, r);
|
Chris@16
|
118 }
|
Chris@16
|
119 };
|
Chris@16
|
120
|
Chris@16
|
121
|
Chris@16
|
122
|
Chris@16
|
123 public :
|
Chris@16
|
124 BOOST_CONCEPT_USAGE(PointDistanceStrategy)
|
Chris@16
|
125 {
|
Chris@16
|
126 checker::apply(&Strategy::template apply<Point1, Point2>);
|
Chris@16
|
127 }
|
Chris@16
|
128 #endif
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131
|
Chris@16
|
132 /*!
|
Chris@101
|
133 \brief Checks strategy for point-segment distance
|
Chris@16
|
134 \ingroup strategy_concepts
|
Chris@16
|
135 */
|
Chris@16
|
136 template <typename Strategy, typename Point, typename PointOfSegment>
|
Chris@16
|
137 struct PointSegmentDistanceStrategy
|
Chris@16
|
138 {
|
Chris@16
|
139 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
|
Chris@16
|
140 private :
|
Chris@16
|
141
|
Chris@16
|
142 struct checker
|
Chris@16
|
143 {
|
Chris@16
|
144 template <typename ApplyMethod>
|
Chris@16
|
145 static void apply(ApplyMethod)
|
Chris@16
|
146 {
|
Chris@101
|
147 // 1) inspect and define both arguments of apply
|
Chris@16
|
148 typedef typename parameter_type_of
|
Chris@16
|
149 <
|
Chris@16
|
150 ApplyMethod, 0
|
Chris@16
|
151 >::type ptype;
|
Chris@16
|
152
|
Chris@16
|
153 typedef typename parameter_type_of
|
Chris@16
|
154 <
|
Chris@16
|
155 ApplyMethod, 1
|
Chris@16
|
156 >::type sptype;
|
Chris@16
|
157
|
Chris@101
|
158 namespace services = strategy::distance::services;
|
Chris@101
|
159 // 2) must define meta-function "tag"
|
Chris@101
|
160 typedef typename services::tag<Strategy>::type tag;
|
Chris@16
|
161
|
Chris@101
|
162 BOOST_MPL_ASSERT_MSG
|
Chris@101
|
163 ((boost::is_same
|
Chris@101
|
164 <
|
Chris@101
|
165 tag, strategy_tag_distance_point_segment
|
Chris@101
|
166 >::value),
|
Chris@101
|
167 INCORRECT_STRATEGY_TAG,
|
Chris@101
|
168 (types<tag>));
|
Chris@16
|
169
|
Chris@101
|
170 // 3) must define meta-function "return_type"
|
Chris@101
|
171 typedef typename services::return_type
|
Chris@101
|
172 <
|
Chris@101
|
173 Strategy, ptype, sptype
|
Chris@101
|
174 >::type rtype;
|
Chris@16
|
175
|
Chris@101
|
176 // 4) must define meta-function "comparable_type"
|
Chris@101
|
177 typedef typename services::comparable_type<Strategy>::type ctype;
|
Chris@101
|
178
|
Chris@101
|
179 // 5) must implement apply with arguments
|
Chris@16
|
180 Strategy *str = 0;
|
Chris@16
|
181 ptype *p = 0;
|
Chris@16
|
182 sptype *sp1 = 0;
|
Chris@16
|
183 sptype *sp2 = 0;
|
Chris@16
|
184
|
Chris@16
|
185 rtype r = str->apply(*p, *sp1, *sp2);
|
Chris@16
|
186
|
Chris@101
|
187 // 6) must define (meta-)struct "get_comparable" with apply
|
Chris@101
|
188 ctype cstrategy = services::get_comparable<Strategy>::apply(*str);
|
Chris@101
|
189
|
Chris@101
|
190 // 7) must define (meta-)struct "result_from_distance" with apply
|
Chris@101
|
191 r = services::result_from_distance
|
Chris@101
|
192 <
|
Chris@101
|
193 Strategy, ptype, sptype
|
Chris@101
|
194 >::apply(*str, rtype(1.0));
|
Chris@101
|
195
|
Chris@101
|
196 boost::ignore_unused(str, r, cstrategy);
|
Chris@16
|
197 }
|
Chris@16
|
198 };
|
Chris@16
|
199
|
Chris@16
|
200 public :
|
Chris@16
|
201 BOOST_CONCEPT_USAGE(PointSegmentDistanceStrategy)
|
Chris@16
|
202 {
|
Chris@16
|
203 checker::apply(&Strategy::template apply<Point, PointOfSegment>);
|
Chris@16
|
204 }
|
Chris@16
|
205 #endif
|
Chris@16
|
206 };
|
Chris@16
|
207
|
Chris@16
|
208
|
Chris@16
|
209 }}} // namespace boost::geometry::concept
|
Chris@16
|
210
|
Chris@16
|
211
|
Chris@16
|
212 #endif // BOOST_GEOMETRY_STRATEGIES_CONCEPTS_DISTANCE_CONCEPT_HPP
|