123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_COPY_SEGMENTS_HPP
- #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_COPY_SEGMENTS_HPP
- #include <array>
- #include <type_traits>
- #include <vector>
- #include <boost/range/begin.hpp>
- #include <boost/range/end.hpp>
- #include <boost/range/size.hpp>
- #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
- #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
- #include <boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp>
- #include <boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp>
- #include <boost/geometry/algorithms/not_implemented.hpp>
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/core/exterior_ring.hpp>
- #include <boost/geometry/core/interior_rings.hpp>
- #include <boost/geometry/core/ring_type.hpp>
- #include <boost/geometry/core/tags.hpp>
- #include <boost/geometry/geometries/concepts/check.hpp>
- #include <boost/geometry/iterators/ever_circling_iterator.hpp>
- #include <boost/geometry/util/range.hpp>
- #include <boost/geometry/views/detail/closed_clockwise_view.hpp>
- namespace boost { namespace geometry
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace copy_segments
- {
- template <bool Reverse>
- struct copy_segments_ring
- {
- template
- <
- typename Ring,
- typename SegmentIdentifier,
- typename Strategy,
- typename RobustPolicy,
- typename RangeOut
- >
- static inline void apply(Ring const& ring,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- Strategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& current_output)
- {
- using view_type = detail::closed_clockwise_view
- <
- Ring const,
- closure<Ring>::value,
- Reverse ? counterclockwise : clockwise
- >;
- using iterator = typename boost::range_iterator<view_type const>::type;
- using ec_iterator = geometry::ever_circling_iterator<iterator>;
- view_type view(ring);
-
-
-
-
- signed_size_type const from_index = seg_id.segment_index + 1;
-
- BOOST_GEOMETRY_ASSERT(from_index < static_cast<signed_size_type>(boost::size(view)));
- ec_iterator it(boost::begin(view), boost::end(view),
- boost::begin(view) + from_index);
-
-
-
- signed_size_type const count = from_index <= to_index
- ? to_index - from_index + 1
- : static_cast<signed_size_type>(boost::size(view))
- - from_index + to_index + 1;
- for (signed_size_type i = 0; i < count; ++i, ++it)
- {
- detail::overlay::append_no_dups_or_spikes(current_output, *it, strategy, robust_policy);
- }
- }
- };
- template <bool Reverse, bool RemoveSpikes = true>
- class copy_segments_linestring
- {
- private:
-
- template <typename RangeOut, typename Point, typename Strategy, typename RobustPolicy>
- static inline void append_to_output(RangeOut& current_output,
- Point const& point,
- Strategy const& strategy,
- RobustPolicy const& robust_policy,
- std::true_type const&)
- {
- detail::overlay::append_no_dups_or_spikes(current_output, point,
- strategy,
- robust_policy);
- }
-
- template <typename RangeOut, typename Point, typename Strategy, typename RobustPolicy>
- static inline void append_to_output(RangeOut& current_output,
- Point const& point,
- Strategy const& strategy,
- RobustPolicy const&,
- std::false_type const&)
- {
- detail::overlay::append_no_duplicates(current_output, point, strategy);
- }
- public:
- template
- <
- typename LineString,
- typename SegmentIdentifier,
- typename SideStrategy,
- typename RobustPolicy,
- typename RangeOut
- >
- static inline void apply(LineString const& ls,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- SideStrategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& current_output)
- {
- signed_size_type const from_index = seg_id.segment_index + 1;
-
- if ( from_index > to_index
- || from_index < 0
- || to_index >= static_cast<signed_size_type>(boost::size(ls)) )
- {
- return;
- }
- signed_size_type const count = to_index - from_index + 1;
- auto it = boost::begin(ls) + from_index;
- for (signed_size_type i = 0; i < count; ++i, ++it)
- {
- append_to_output(current_output, *it, strategy, robust_policy,
- std::integral_constant<bool, RemoveSpikes>());
- }
- }
- };
- template <bool Reverse>
- struct copy_segments_polygon
- {
- template
- <
- typename Polygon,
- typename SegmentIdentifier,
- typename SideStrategy,
- typename RobustPolicy,
- typename RangeOut
- >
- static inline void apply(Polygon const& polygon,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- SideStrategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& current_output)
- {
-
- copy_segments_ring<Reverse>::apply
- (
- seg_id.ring_index < 0
- ? geometry::exterior_ring(polygon)
- : range::at(geometry::interior_rings(polygon), seg_id.ring_index),
- seg_id, to_index,
- strategy,
- robust_policy,
- current_output
- );
- }
- };
- template <bool Reverse>
- struct copy_segments_box
- {
- template
- <
- typename Box,
- typename SegmentIdentifier,
- typename SideStrategy,
- typename RobustPolicy,
- typename RangeOut
- >
- static inline void apply(Box const& box,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- SideStrategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& current_output)
- {
- signed_size_type index = seg_id.segment_index + 1;
- BOOST_GEOMETRY_ASSERT(index < 5);
- signed_size_type const count = index <= to_index
- ? to_index - index + 1
- : 5 - index + to_index + 1;
-
- std::array<typename point_type<Box>::type, 5> bp;
- assign_box_corners_oriented<Reverse>(box, bp);
- bp[4] = bp[0];
-
-
- for (signed_size_type i = 0; i < count; i++, index++)
- {
- detail::overlay::append_no_dups_or_spikes(current_output,
- bp[index % 5], strategy, robust_policy);
- }
- }
- };
- template<typename Policy>
- struct copy_segments_multi
- {
- template
- <
- typename MultiGeometry,
- typename SegmentIdentifier,
- typename SideStrategy,
- typename RobustPolicy,
- typename RangeOut
- >
- static inline void apply(MultiGeometry const& multi_geometry,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- SideStrategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& current_output)
- {
- BOOST_GEOMETRY_ASSERT
- (
- seg_id.multi_index >= 0
- && static_cast<std::size_t>(seg_id.multi_index) < boost::size(multi_geometry)
- );
-
- Policy::apply(range::at(multi_geometry, seg_id.multi_index),
- seg_id, to_index,
- strategy,
- robust_policy,
- current_output);
- }
- };
- }}
- #endif
- #ifndef DOXYGEN_NO_DISPATCH
- namespace dispatch
- {
- template
- <
- typename Tag,
- bool Reverse
- >
- struct copy_segments : not_implemented<Tag>
- {};
- template <bool Reverse>
- struct copy_segments<ring_tag, Reverse>
- : detail::copy_segments::copy_segments_ring<Reverse>
- {};
- template <bool Reverse>
- struct copy_segments<linestring_tag, Reverse>
- : detail::copy_segments::copy_segments_linestring<Reverse>
- {};
- template <bool Reverse>
- struct copy_segments<polygon_tag, Reverse>
- : detail::copy_segments::copy_segments_polygon<Reverse>
- {};
- template <bool Reverse>
- struct copy_segments<box_tag, Reverse>
- : detail::copy_segments::copy_segments_box<Reverse>
- {};
- template<bool Reverse>
- struct copy_segments<multi_polygon_tag, Reverse>
- : detail::copy_segments::copy_segments_multi
- <
- detail::copy_segments::copy_segments_polygon<Reverse>
- >
- {};
- }
- #endif
- template
- <
- bool Reverse,
- typename Geometry,
- typename SegmentIdentifier,
- typename SideStrategy,
- typename RobustPolicy,
- typename RangeOut
- >
- inline void copy_segments(Geometry const& geometry,
- SegmentIdentifier const& seg_id,
- signed_size_type to_index,
- SideStrategy const& strategy,
- RobustPolicy const& robust_policy,
- RangeOut& range_out)
- {
- concepts::check<Geometry const>();
- dispatch::copy_segments
- <
- typename tag<Geometry>::type,
- Reverse
- >::apply(geometry, seg_id, to_index, strategy, robust_policy, range_out);
- }
- }}
- #endif
|