1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015, Oracle and/or its affiliates.
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_POINTLIKE_LINEAR_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_POINTLIKE_LINEAR_HPP
17 #include <boost/range.hpp>
19 #include <boost/geometry/core/tags.hpp>
21 #include <boost/geometry/geometries/box.hpp>
23 #include <boost/geometry/iterators/segment_iterator.hpp>
25 #include <boost/geometry/algorithms/disjoint.hpp>
26 #include <boost/geometry/algorithms/envelope.hpp>
27 #include <boost/geometry/algorithms/expand.hpp>
28 #include <boost/geometry/algorithms/not_implemented.hpp>
30 #include <boost/geometry/algorithms/detail/not.hpp>
31 #include <boost/geometry/algorithms/detail/partition.hpp>
32 #include <boost/geometry/algorithms/detail/relate/less.hpp>
33 #include <boost/geometry/algorithms/detail/disjoint/point_geometry.hpp>
34 #include <boost/geometry/algorithms/detail/equals/point_point.hpp>
35 #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
36 #include <boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp>
39 namespace boost { namespace geometry
43 #ifndef DOXYGEN_NO_DETAIL
44 namespace detail { namespace overlay
48 // action struct for pointlike-linear difference/intersection
49 // it works the same as its pointlike-pointlike counterpart, hence the
51 template <typename PointOut, overlay_type OverlayType>
52 struct action_selector_pl_l
53 : action_selector_pl_pl<PointOut, OverlayType>
56 // difference/intersection of point-linear
62 overlay_type OverlayType,
65 struct point_linear_point
67 template <typename RobustPolicy, typename OutputIterator, typename Strategy>
68 static inline OutputIterator apply(Point const& point,
77 >::apply(point, Policy::apply(point, linear), oit);
82 // difference/intersection of multipoint-segment
88 overlay_type OverlayType,
91 struct multipoint_segment_point
93 template <typename RobustPolicy, typename OutputIterator, typename Strategy>
94 static inline OutputIterator apply(MultiPoint const& multipoint,
95 Segment const& segment,
100 for (typename boost::range_iterator<MultiPoint const>::type
101 it = boost::begin(multipoint);
102 it != boost::end(multipoint);
107 PointOut, OverlayType
108 >::apply(*it, Policy::apply(*it, segment), oit);
116 // difference/intersection of multipoint-linear
122 overlay_type OverlayType,
125 class multipoint_linear_point
128 // structs for partition -- start
131 template <typename Box, typename Geometry>
132 static inline void apply(Box& total, Geometry const& geometry)
134 geometry::expand(total, geometry::return_envelope<Box>(geometry));
141 template <typename Box, typename Geometry>
142 static inline bool apply(Box const& box, Geometry const& geometry)
144 return ! geometry::disjoint(geometry, box);
148 template <typename OutputIterator>
149 class item_visitor_type
152 item_visitor_type(OutputIterator& oit) : m_oit(oit) {}
154 template <typename Item1, typename Item2>
155 inline void apply(Item1 const& item1, Item2 const& item2)
159 PointOut, overlay_intersection
160 >::apply(item1, Policy::apply(item1, item2), m_oit);
164 OutputIterator& m_oit;
166 // structs for partition -- end
171 typedef geometry::segment_iterator<Linear const> const_iterator;
172 typedef const_iterator iterator;
174 segment_range(Linear const& linear)
178 const_iterator begin() const
180 return geometry::segments_begin(m_linear);
183 const_iterator end() const
185 return geometry::segments_end(m_linear);
189 Linear const& m_linear;
192 template <typename OutputIterator>
193 static inline OutputIterator get_common_points(MultiPoint const& multipoint,
194 Linear const& linear,
197 item_visitor_type<OutputIterator> item_visitor(oit);
199 segment_range rng(linear);
205 typename boost::range_value<MultiPoint>::type
209 >::apply(multipoint, rng, item_visitor);
215 template <typename RobustPolicy, typename OutputIterator, typename Strategy>
216 static inline OutputIterator apply(MultiPoint const& multipoint,
217 Linear const& linear,
218 RobustPolicy const& robust_policy,
220 Strategy const& strategy)
224 typename boost::range_value<MultiPoint>::type
227 point_vector_type common_points;
229 // compute the common points
230 get_common_points(multipoint, linear,
231 std::back_inserter(common_points));
233 return multipoint_multipoint_point
235 MultiPoint, point_vector_type, PointOut, OverlayType
236 >::apply(multipoint, common_points, robust_policy, oit, strategy);
241 }} // namespace detail::overlay
242 #endif // DOXYGEN_NO_DETAIL
245 #ifndef DOXYGEN_NO_DISPATCH
246 namespace detail_dispatch { namespace overlay
249 // dispatch struct for pointlike-linear difference/intersection computation
255 overlay_type OverlayType,
259 struct pointlike_linear_point
260 : not_implemented<PointLike, Linear, PointOut>
269 overlay_type OverlayType
271 struct pointlike_linear_point
273 Point, Linear, PointOut, OverlayType, point_tag, linear_tag
274 > : detail::overlay::point_linear_point
276 Point, Linear, PointOut, OverlayType,
277 detail::not_<detail::disjoint::reverse_covered_by>
287 overlay_type OverlayType
289 struct pointlike_linear_point
291 Point, Segment, PointOut, OverlayType, point_tag, segment_tag
292 > : detail::overlay::point_linear_point
294 Point, Segment, PointOut, OverlayType,
295 detail::not_<detail::disjoint::reverse_covered_by>
305 overlay_type OverlayType
307 struct pointlike_linear_point
309 MultiPoint, Linear, PointOut, OverlayType, multi_point_tag, linear_tag
310 > : detail::overlay::multipoint_linear_point
312 MultiPoint, Linear, PointOut, OverlayType,
313 detail::not_<detail::disjoint::reverse_covered_by>
323 overlay_type OverlayType
325 struct pointlike_linear_point
327 MultiPoint, Segment, PointOut, OverlayType, multi_point_tag, segment_tag
328 > : detail::overlay::multipoint_segment_point
330 MultiPoint, Segment, PointOut, OverlayType,
331 detail::not_<detail::disjoint::reverse_covered_by>
336 }} // namespace detail_dispatch::overlay
337 #endif // DOXYGEN_NO_DISPATCH
340 }} // namespace boost::geometry
343 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_POINTLIKE_LINEAR_HPP