1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2013-2015.
9 // Modifications copyright (c) 2013-2015, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP
26 #include <boost/range.hpp>
28 #include <boost/geometry/core/closure.hpp>
29 #include <boost/geometry/core/point_type.hpp>
30 #include <boost/geometry/core/ring_type.hpp>
31 #include <boost/geometry/core/exterior_ring.hpp>
32 #include <boost/geometry/core/interior_rings.hpp>
33 #include <boost/geometry/core/tag.hpp>
34 #include <boost/geometry/core/tag_cast.hpp>
35 #include <boost/geometry/core/tags.hpp>
37 #include <boost/geometry/algorithms/covered_by.hpp>
38 #include <boost/geometry/algorithms/not_implemented.hpp>
40 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
41 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
42 #include <boost/geometry/algorithms/detail/point_on_border.hpp>
44 #include <boost/geometry/algorithms/detail/disjoint/multirange_geometry.hpp>
45 #include <boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp>
46 #include <boost/geometry/algorithms/detail/disjoint/point_box.hpp>
47 #include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
49 #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
52 namespace boost { namespace geometry
55 #ifndef DOXYGEN_NO_DETAIL
56 namespace detail { namespace disjoint
59 template <typename Geometry1, typename Geometry2,
60 typename Tag1 = typename tag<Geometry1>::type,
61 typename Tag1OrMulti = typename tag_cast<Tag1, multi_tag>::type>
62 struct disjoint_no_intersections_policy
64 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2)
66 typedef typename point_type<Geometry1>::type point1_type;
68 geometry::point_on_border(p, g1);
69 return !geometry::covered_by(p, g2);
73 template <typename Geometry1, typename Geometry2, typename Tag1>
74 struct disjoint_no_intersections_policy<Geometry1, Geometry2, Tag1, multi_tag>
76 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2)
78 // TODO: use partition or rtree on g2
79 typedef typename boost::range_iterator<Geometry1 const>::type iterator;
80 for ( iterator it = boost::begin(g1) ; it != boost::end(g1) ; ++it )
82 typedef typename boost::range_value<Geometry1 const>::type value_type;
83 if ( ! disjoint_no_intersections_policy<value_type const, Geometry2>
94 template<typename Geometry1, typename Geometry2,
95 typename NoIntersectionsPolicy
96 = disjoint_no_intersections_policy<Geometry1, Geometry2> >
97 struct disjoint_linear_areal
99 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2)
101 // if there are intersections - return false
102 if ( !disjoint_linear<Geometry1, Geometry2>::apply(g1, g2) )
107 return NoIntersectionsPolicy::apply(g1, g2);
118 typename Tag = typename tag<Areal>::type
120 struct disjoint_segment_areal
121 : not_implemented<Segment, Areal>
125 template <typename Segment, typename Polygon>
126 class disjoint_segment_areal<Segment, Polygon, polygon_tag>
129 template <typename InteriorRings>
131 bool check_interior_rings(InteriorRings const& interior_rings,
132 Segment const& segment)
134 typedef typename boost::range_value<InteriorRings>::type ring_type;
136 typedef unary_disjoint_geometry_to_query_geometry
139 disjoint_range_segment_or_box
141 ring_type, closure<ring_type>::value, Segment
143 > unary_predicate_type;
145 return check_iterator_range
148 >::apply(boost::begin(interior_rings),
149 boost::end(interior_rings),
150 unary_predicate_type(segment));
155 static inline bool apply(Segment const& segment, Polygon const& polygon)
157 typedef typename geometry::ring_type<Polygon>::type ring;
159 if ( !disjoint_range_segment_or_box
161 ring, closure<Polygon>::value, Segment
162 >::apply(geometry::exterior_ring(polygon), segment) )
167 if ( !check_interior_rings(geometry::interior_rings(polygon), segment) )
172 typename point_type<Segment>::type p;
173 detail::assign_point_from_index<0>(segment, p);
175 return !geometry::covered_by(p, polygon);
180 template <typename Segment, typename MultiPolygon>
181 struct disjoint_segment_areal<Segment, MultiPolygon, multi_polygon_tag>
184 bool apply(Segment const& segment, MultiPolygon const& multipolygon)
186 return multirange_constant_size_geometry
188 MultiPolygon, Segment
189 >::apply(multipolygon, segment);
194 template <typename Segment, typename Ring>
195 struct disjoint_segment_areal<Segment, Ring, ring_tag>
197 static inline bool apply(Segment const& segment, Ring const& ring)
199 if ( !disjoint_range_segment_or_box
201 Ring, closure<Ring>::value, Segment
202 >::apply(ring, segment) )
207 typename point_type<Segment>::type p;
208 detail::assign_point_from_index<0>(segment, p);
210 return !geometry::covered_by(p, ring);
215 }} // namespace detail::disjoint
216 #endif // DOXYGEN_NO_DETAIL
221 #ifndef DOXYGEN_NO_DISPATCH
226 template <typename Linear, typename Areal>
227 struct disjoint<Linear, Areal, 2, linear_tag, areal_tag, false>
228 : public detail::disjoint::disjoint_linear_areal<Linear, Areal>
232 template <typename Areal, typename Linear>
233 struct disjoint<Areal, Linear, 2, areal_tag, linear_tag, false>
236 bool apply(Areal const& areal, Linear const& linear)
238 return detail::disjoint::disjoint_linear_areal
241 >::apply(linear, areal);
246 template <typename Areal, typename Segment>
247 struct disjoint<Areal, Segment, 2, areal_tag, segment_tag, false>
249 static inline bool apply(Areal const& g1, Segment const& g2)
251 return detail::disjoint::disjoint_segment_areal
259 template <typename Segment, typename Areal>
260 struct disjoint<Segment, Areal, 2, segment_tag, areal_tag, false>
261 : detail::disjoint::disjoint_segment_areal<Segment, Areal>
265 } // namespace dispatch
266 #endif // DOXYGEN_NO_DISPATCH
269 }} // namespace boost::geometry
272 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP