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-2014.
9 // Modifications copyright (c) 2013-2014, 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/tags.hpp>
36 #include <boost/geometry/algorithms/covered_by.hpp>
37 #include <boost/geometry/algorithms/not_implemented.hpp>
38 #include <boost/geometry/algorithms/detail/point_on_border.hpp>
40 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
41 #include <boost/geometry/algorithms/detail/disjoint/point_box.hpp>
42 #include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
43 #include <boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp>
45 #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
48 namespace boost { namespace geometry
52 #ifndef DOXYGEN_NO_DETAIL
53 namespace detail { namespace disjoint
57 template<typename Geometry1, typename Geometry2>
58 struct disjoint_linear_areal
60 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2)
62 // if there are intersections - return false
63 if ( !disjoint_linear<Geometry1, Geometry2>::apply(g1, g2) )
66 typedef typename point_type<Geometry1>::type point1_type;
68 geometry::point_on_border(p, g1);
69 return !geometry::covered_by(p, g2);
80 typename Tag = typename tag<Areal>::type
82 struct disjoint_segment_areal
83 : not_implemented<Segment, Areal>
87 template <typename Segment, typename Polygon>
88 class disjoint_segment_areal<Segment, Polygon, polygon_tag>
91 template <typename RingIterator>
92 static inline bool check_interior_rings(RingIterator first,
94 Segment const& segment)
96 for (RingIterator it = first; it != beyond; ++it)
98 if ( !disjoint_range_segment_or_box
100 typename std::iterator_traits
104 closure<Polygon>::value,
106 >::apply(*it, segment) )
115 template <typename InteriorRings>
117 bool check_interior_rings(InteriorRings const& interior_rings,
118 Segment const& segment)
120 return check_interior_rings(boost::begin(interior_rings),
121 boost::end(interior_rings),
127 static inline bool apply(Segment const& segment, Polygon const& polygon)
129 typedef typename geometry::ring_type<Polygon>::type ring;
131 if ( !disjoint_range_segment_or_box
133 ring, closure<Polygon>::value, Segment
134 >::apply(geometry::exterior_ring(polygon), segment) )
139 if ( !check_interior_rings(geometry::interior_rings(polygon), segment) )
144 typename point_type<Segment>::type p;
145 detail::assign_point_from_index<0>(segment, p);
147 return !geometry::covered_by(p, polygon);
152 template <typename Segment, typename MultiPolygon>
153 struct disjoint_segment_areal<Segment, MultiPolygon, multi_polygon_tag>
156 bool apply(Segment const& segment, MultiPolygon const& multipolygon)
158 return disjoint_multirange_segment_or_box
160 MultiPolygon, Segment
161 >::apply(multipolygon, segment);
166 template <typename Segment, typename Ring>
167 struct disjoint_segment_areal<Segment, Ring, ring_tag>
169 static inline bool apply(Segment const& segment, Ring const& ring)
171 if ( !disjoint_range_segment_or_box
173 Ring, closure<Ring>::value, Segment
174 >::apply(ring, segment) )
179 typename point_type<Segment>::type p;
180 detail::assign_point_from_index<0>(segment, p);
182 return !geometry::covered_by(p, ring);
187 }} // namespace detail::disjoint
188 #endif // DOXYGEN_NO_DETAIL
193 #ifndef DOXYGEN_NO_DISPATCH
198 template <typename Linear, typename Areal>
199 struct disjoint<Linear, Areal, 2, linear_tag, areal_tag, false>
200 : public detail::disjoint::disjoint_linear_areal<Linear, Areal>
204 template <typename Areal, typename Linear>
205 struct disjoint<Areal, Linear, 2, areal_tag, linear_tag, false>
208 bool apply(Areal const& areal, Linear const& linear)
210 return detail::disjoint::disjoint_linear_areal
213 >::apply(linear, areal);
218 template <typename Areal, typename Segment>
219 struct disjoint<Areal, Segment, 2, areal_tag, segment_tag, false>
221 static inline bool apply(Areal const& g1, Segment const& g2)
223 return detail::disjoint::disjoint_segment_areal
231 template <typename Segment, typename Areal>
232 struct disjoint<Segment, Areal, 2, segment_tag, areal_tag, false>
233 : detail::disjoint::disjoint_segment_areal<Segment, Areal>
237 } // namespace dispatch
238 #endif // DOXYGEN_NO_DISPATCH
241 }} // namespace boost::geometry
244 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP