• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
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.
6 
7 // This file was modified by Oracle on 2013, 2014, 2017, 2019.
8 // Modifications copyright (c) 2013-2019 Oracle and/or its affiliates.
9 
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14 
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
21 
22 #include <cstddef>
23 
24 #include <boost/core/ignore_unused.hpp>
25 #include <boost/range.hpp>
26 
27 #include <boost/geometry/algorithms/detail/within/interface.hpp>
28 
29 #include <boost/geometry/core/access.hpp>
30 #include <boost/geometry/core/closure.hpp>
31 #include <boost/geometry/core/cs.hpp>
32 #include <boost/geometry/core/exterior_ring.hpp>
33 #include <boost/geometry/core/interior_rings.hpp>
34 #include <boost/geometry/core/point_order.hpp>
35 #include <boost/geometry/core/ring_type.hpp>
36 #include <boost/geometry/core/interior_rings.hpp>
37 #include <boost/geometry/core/tags.hpp>
38 
39 #include <boost/geometry/util/math.hpp>
40 #include <boost/geometry/util/order_as_direction.hpp>
41 
42 #include <boost/geometry/algorithms/detail/within/multi_point.hpp>
43 #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
44 #include <boost/geometry/algorithms/relate.hpp>
45 
46 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
47 #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
48 #include <deque>
49 
50 
51 namespace boost { namespace geometry
52 {
53 
54 #ifndef DOXYGEN_NO_DETAIL
55 namespace detail { namespace within {
56 
57 struct use_point_in_geometry
58 {
59     template <typename Geometry1, typename Geometry2, typename Strategy>
applyboost::geometry::detail::within::use_point_in_geometry60     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
61     {
62         return detail::within::within_point_geometry(geometry1, geometry2, strategy);
63     }
64 };
65 
66 struct use_relate
67 {
68     template <typename Geometry1, typename Geometry2, typename Strategy>
applyboost::geometry::detail::within::use_relate69     static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
70     {
71         typedef typename detail::de9im::static_mask_within_type
72             <
73                 Geometry1, Geometry2
74             >::type within_mask;
75         return geometry::relate(geometry1, geometry2, within_mask(), strategy);
76     }
77 };
78 
79 }} // namespace detail::within
80 #endif // DOXYGEN_NO_DETAIL
81 
82 #ifndef DOXYGEN_NO_DISPATCH
83 namespace dispatch
84 {
85 
86 template <typename Point, typename Box>
87 struct within<Point, Box, point_tag, box_tag>
88 {
89     template <typename Strategy>
applyboost::geometry::dispatch::within90     static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
91     {
92         boost::ignore_unused(strategy);
93         return strategy.apply(point, box);
94     }
95 };
96 
97 template <typename Box1, typename Box2>
98 struct within<Box1, Box2, box_tag, box_tag>
99 {
100     template <typename Strategy>
applyboost::geometry::dispatch::within101     static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
102     {
103         assert_dimension_equal<Box1, Box2>();
104         boost::ignore_unused(strategy);
105         return strategy.apply(box1, box2);
106     }
107 };
108 
109 // P/P
110 
111 template <typename Point1, typename Point2>
112 struct within<Point1, Point2, point_tag, point_tag>
113     : public detail::within::use_point_in_geometry
114 {};
115 
116 template <typename Point, typename MultiPoint>
117 struct within<Point, MultiPoint, point_tag, multi_point_tag>
118     : public detail::within::use_point_in_geometry
119 {};
120 
121 template <typename MultiPoint, typename Point>
122 struct within<MultiPoint, Point, multi_point_tag, point_tag>
123     : public detail::within::multi_point_point
124 {};
125 
126 template <typename MultiPoint1, typename MultiPoint2>
127 struct within<MultiPoint1, MultiPoint2, multi_point_tag, multi_point_tag>
128     : public detail::within::multi_point_multi_point
129 {};
130 
131 // P/L
132 
133 template <typename Point, typename Segment>
134 struct within<Point, Segment, point_tag, segment_tag>
135     : public detail::within::use_point_in_geometry
136 {};
137 
138 template <typename Point, typename Linestring>
139 struct within<Point, Linestring, point_tag, linestring_tag>
140     : public detail::within::use_point_in_geometry
141 {};
142 
143 template <typename Point, typename MultiLinestring>
144 struct within<Point, MultiLinestring, point_tag, multi_linestring_tag>
145     : public detail::within::use_point_in_geometry
146 {};
147 
148 template <typename MultiPoint, typename Segment>
149 struct within<MultiPoint, Segment, multi_point_tag, segment_tag>
150     : public detail::within::multi_point_single_geometry<true>
151 {};
152 
153 template <typename MultiPoint, typename Linestring>
154 struct within<MultiPoint, Linestring, multi_point_tag, linestring_tag>
155     : public detail::within::multi_point_single_geometry<true>
156 {};
157 
158 template <typename MultiPoint, typename MultiLinestring>
159 struct within<MultiPoint, MultiLinestring, multi_point_tag, multi_linestring_tag>
160     : public detail::within::multi_point_multi_geometry<true>
161 {};
162 
163 // P/A
164 
165 template <typename Point, typename Ring>
166 struct within<Point, Ring, point_tag, ring_tag>
167     : public detail::within::use_point_in_geometry
168 {};
169 
170 template <typename Point, typename Polygon>
171 struct within<Point, Polygon, point_tag, polygon_tag>
172     : public detail::within::use_point_in_geometry
173 {};
174 
175 template <typename Point, typename MultiPolygon>
176 struct within<Point, MultiPolygon, point_tag, multi_polygon_tag>
177     : public detail::within::use_point_in_geometry
178 {};
179 
180 template <typename MultiPoint, typename Ring>
181 struct within<MultiPoint, Ring, multi_point_tag, ring_tag>
182     : public detail::within::multi_point_single_geometry<true>
183 {};
184 
185 template <typename MultiPoint, typename Polygon>
186 struct within<MultiPoint, Polygon, multi_point_tag, polygon_tag>
187     : public detail::within::multi_point_single_geometry<true>
188 {};
189 
190 template <typename MultiPoint, typename MultiPolygon>
191 struct within<MultiPoint, MultiPolygon, multi_point_tag, multi_polygon_tag>
192     : public detail::within::multi_point_multi_geometry<true>
193 {};
194 
195 // L/L
196 
197 template <typename Linestring1, typename Linestring2>
198 struct within<Linestring1, Linestring2, linestring_tag, linestring_tag>
199     : public detail::within::use_relate
200 {};
201 
202 template <typename Linestring, typename MultiLinestring>
203 struct within<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
204     : public detail::within::use_relate
205 {};
206 
207 template <typename MultiLinestring, typename Linestring>
208 struct within<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
209     : public detail::within::use_relate
210 {};
211 
212 template <typename MultiLinestring1, typename MultiLinestring2>
213 struct within<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
214     : public detail::within::use_relate
215 {};
216 
217 // L/A
218 
219 template <typename Linestring, typename Ring>
220 struct within<Linestring, Ring, linestring_tag, ring_tag>
221     : public detail::within::use_relate
222 {};
223 
224 template <typename MultiLinestring, typename Ring>
225 struct within<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
226     : public detail::within::use_relate
227 {};
228 
229 template <typename Linestring, typename Polygon>
230 struct within<Linestring, Polygon, linestring_tag, polygon_tag>
231     : public detail::within::use_relate
232 {};
233 
234 template <typename MultiLinestring, typename Polygon>
235 struct within<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
236     : public detail::within::use_relate
237 {};
238 
239 template <typename Linestring, typename MultiPolygon>
240 struct within<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
241     : public detail::within::use_relate
242 {};
243 
244 template <typename MultiLinestring, typename MultiPolygon>
245 struct within<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
246     : public detail::within::use_relate
247 {};
248 
249 // A/A
250 
251 template <typename Ring1, typename Ring2>
252 struct within<Ring1, Ring2, ring_tag, ring_tag>
253     : public detail::within::use_relate
254 {};
255 
256 template <typename Ring, typename Polygon>
257 struct within<Ring, Polygon, ring_tag, polygon_tag>
258     : public detail::within::use_relate
259 {};
260 
261 template <typename Polygon, typename Ring>
262 struct within<Polygon, Ring, polygon_tag, ring_tag>
263     : public detail::within::use_relate
264 {};
265 
266 template <typename Polygon1, typename Polygon2>
267 struct within<Polygon1, Polygon2, polygon_tag, polygon_tag>
268     : public detail::within::use_relate
269 {};
270 
271 template <typename Ring, typename MultiPolygon>
272 struct within<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
273     : public detail::within::use_relate
274 {};
275 
276 template <typename MultiPolygon, typename Ring>
277 struct within<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
278     : public detail::within::use_relate
279 {};
280 
281 template <typename Polygon, typename MultiPolygon>
282 struct within<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
283     : public detail::within::use_relate
284 {};
285 
286 template <typename MultiPolygon, typename Polygon>
287 struct within<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
288     : public detail::within::use_relate
289 {};
290 
291 template <typename MultiPolygon1, typename MultiPolygon2>
292 struct within<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
293     : public detail::within::use_relate
294 {};
295 
296 } // namespace dispatch
297 #endif // DOXYGEN_NO_DISPATCH
298 
299 
300 }} // namespace boost::geometry
301 
302 #include <boost/geometry/index/rtree.hpp>
303 
304 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
305