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 // This file was modified by Oracle on 2013-2021.
8 // Modifications copyright (c) 2013-2021 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
25 #include <boost/core/ignore_unused.hpp>
27 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
28 #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
29 #include <boost/geometry/algorithms/detail/within/interface.hpp>
30 #include <boost/geometry/algorithms/detail/within/multi_point.hpp>
31 #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
32 #include <boost/geometry/algorithms/relate.hpp>
34 #include <boost/geometry/core/access.hpp>
35 #include <boost/geometry/core/closure.hpp>
36 #include <boost/geometry/core/cs.hpp>
37 #include <boost/geometry/core/exterior_ring.hpp>
38 #include <boost/geometry/core/interior_rings.hpp>
39 #include <boost/geometry/core/point_order.hpp>
40 #include <boost/geometry/core/ring_type.hpp>
41 #include <boost/geometry/core/interior_rings.hpp>
42 #include <boost/geometry/core/tags.hpp>
44 #include <boost/geometry/strategies/relate/cartesian.hpp>
45 #include <boost/geometry/strategies/relate/geographic.hpp>
46 #include <boost/geometry/strategies/relate/spherical.hpp>
48 #include <boost/geometry/util/math.hpp>
49 #include <boost/geometry/util/order_as_direction.hpp>
51 namespace boost { namespace geometry
54 #ifndef DOXYGEN_NO_DETAIL
55 namespace detail { namespace within {
57 struct use_point_in_geometry
59 template <typename Geometry1, typename Geometry2, typename Strategy>
60 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
62 return detail::within::within_point_geometry(geometry1, geometry2, strategy);
68 template <typename Geometry1, typename Geometry2, typename Strategy>
69 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
71 typedef typename detail::de9im::static_mask_within_type
75 return geometry::relate(geometry1, geometry2, within_mask(), strategy);
79 }} // namespace detail::within
80 #endif // DOXYGEN_NO_DETAIL
82 #ifndef DOXYGEN_NO_DISPATCH
86 template <typename Point, typename Box>
87 struct within<Point, Box, point_tag, box_tag>
89 template <typename Strategy>
90 static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
92 return strategy.within(point, box).apply(point, box);
96 template <typename Box1, typename Box2>
97 struct within<Box1, Box2, box_tag, box_tag>
99 template <typename Strategy>
100 static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
102 assert_dimension_equal<Box1, Box2>();
103 return strategy.within(box1, box2).apply(box1, box2);
109 template <typename Point1, typename Point2>
110 struct within<Point1, Point2, point_tag, point_tag>
111 : public detail::within::use_point_in_geometry
114 template <typename Point, typename MultiPoint>
115 struct within<Point, MultiPoint, point_tag, multi_point_tag>
116 : public detail::within::use_point_in_geometry
119 template <typename MultiPoint, typename Point>
120 struct within<MultiPoint, Point, multi_point_tag, point_tag>
121 : public detail::within::multi_point_point
124 template <typename MultiPoint1, typename MultiPoint2>
125 struct within<MultiPoint1, MultiPoint2, multi_point_tag, multi_point_tag>
126 : public detail::within::multi_point_multi_point
131 template <typename Point, typename Segment>
132 struct within<Point, Segment, point_tag, segment_tag>
133 : public detail::within::use_point_in_geometry
136 template <typename Point, typename Linestring>
137 struct within<Point, Linestring, point_tag, linestring_tag>
138 : public detail::within::use_point_in_geometry
141 template <typename Point, typename MultiLinestring>
142 struct within<Point, MultiLinestring, point_tag, multi_linestring_tag>
143 : public detail::within::use_point_in_geometry
146 template <typename MultiPoint, typename Segment>
147 struct within<MultiPoint, Segment, multi_point_tag, segment_tag>
148 : public detail::within::multi_point_single_geometry<true>
151 template <typename MultiPoint, typename Linestring>
152 struct within<MultiPoint, Linestring, multi_point_tag, linestring_tag>
153 : public detail::within::multi_point_single_geometry<true>
156 template <typename MultiPoint, typename MultiLinestring>
157 struct within<MultiPoint, MultiLinestring, multi_point_tag, multi_linestring_tag>
158 : public detail::within::multi_point_multi_geometry<true>
163 template <typename Point, typename Ring>
164 struct within<Point, Ring, point_tag, ring_tag>
165 : public detail::within::use_point_in_geometry
168 template <typename Point, typename Polygon>
169 struct within<Point, Polygon, point_tag, polygon_tag>
170 : public detail::within::use_point_in_geometry
173 template <typename Point, typename MultiPolygon>
174 struct within<Point, MultiPolygon, point_tag, multi_polygon_tag>
175 : public detail::within::use_point_in_geometry
178 template <typename MultiPoint, typename Ring>
179 struct within<MultiPoint, Ring, multi_point_tag, ring_tag>
180 : public detail::within::multi_point_single_geometry<true>
183 template <typename MultiPoint, typename Polygon>
184 struct within<MultiPoint, Polygon, multi_point_tag, polygon_tag>
185 : public detail::within::multi_point_single_geometry<true>
188 template <typename MultiPoint, typename MultiPolygon>
189 struct within<MultiPoint, MultiPolygon, multi_point_tag, multi_polygon_tag>
190 : public detail::within::multi_point_multi_geometry<true>
195 template <typename Linestring1, typename Linestring2>
196 struct within<Linestring1, Linestring2, linestring_tag, linestring_tag>
197 : public detail::within::use_relate
200 template <typename Linestring, typename MultiLinestring>
201 struct within<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
202 : public detail::within::use_relate
205 template <typename MultiLinestring, typename Linestring>
206 struct within<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
207 : public detail::within::use_relate
210 template <typename MultiLinestring1, typename MultiLinestring2>
211 struct within<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
212 : public detail::within::use_relate
217 template <typename Linestring, typename Ring>
218 struct within<Linestring, Ring, linestring_tag, ring_tag>
219 : public detail::within::use_relate
222 template <typename MultiLinestring, typename Ring>
223 struct within<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
224 : public detail::within::use_relate
227 template <typename Linestring, typename Polygon>
228 struct within<Linestring, Polygon, linestring_tag, polygon_tag>
229 : public detail::within::use_relate
232 template <typename MultiLinestring, typename Polygon>
233 struct within<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
234 : public detail::within::use_relate
237 template <typename Linestring, typename MultiPolygon>
238 struct within<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
239 : public detail::within::use_relate
242 template <typename MultiLinestring, typename MultiPolygon>
243 struct within<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
244 : public detail::within::use_relate
249 template <typename Ring1, typename Ring2>
250 struct within<Ring1, Ring2, ring_tag, ring_tag>
251 : public detail::within::use_relate
254 template <typename Ring, typename Polygon>
255 struct within<Ring, Polygon, ring_tag, polygon_tag>
256 : public detail::within::use_relate
259 template <typename Polygon, typename Ring>
260 struct within<Polygon, Ring, polygon_tag, ring_tag>
261 : public detail::within::use_relate
264 template <typename Polygon1, typename Polygon2>
265 struct within<Polygon1, Polygon2, polygon_tag, polygon_tag>
266 : public detail::within::use_relate
269 template <typename Ring, typename MultiPolygon>
270 struct within<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
271 : public detail::within::use_relate
274 template <typename MultiPolygon, typename Ring>
275 struct within<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
276 : public detail::within::use_relate
279 template <typename Polygon, typename MultiPolygon>
280 struct within<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
281 : public detail::within::use_relate
284 template <typename MultiPolygon, typename Polygon>
285 struct within<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
286 : public detail::within::use_relate
289 template <typename MultiPolygon1, typename MultiPolygon2>
290 struct within<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
291 : public detail::within::use_relate
294 } // namespace dispatch
295 #endif // DOXYGEN_NO_DISPATCH
298 }} // namespace boost::geometry
300 #include <boost/geometry/index/rtree.hpp>
302 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP