summaryrefslogtreecommitdiff
path: root/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp')
-rw-r--r--boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp87
1 files changed, 60 insertions, 27 deletions
diff --git a/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp b/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp
index dbf3770357..790819917c 100644
--- a/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp
+++ b/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp
@@ -22,7 +22,9 @@
#include <boost/geometry/algorithms/convert.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/util/range.hpp>
-#include <boost/geometry/views/detail/normalized_view.hpp>
+#include <boost/geometry/iterators/ever_circling_iterator.hpp>
+#include <boost/geometry/views/closeable_view.hpp>
+#include <boost/geometry/views/reversible_view.hpp>
namespace boost { namespace geometry
@@ -38,25 +40,33 @@ template <typename Range, bool Reverse, typename SegmentIdentifier, typename Poi
struct copy_segment_point_range
{
static inline bool apply(Range const& range,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point)
{
- detail::normalized_view<Range const> view(range);
+ typedef typename closeable_view
+ <
+ Range const,
+ closure<Range>::value
+ >::type cview_type;
- signed_size_type const n = boost::size(view);
- signed_size_type index = seg_id.segment_index;
- if (second)
+ typedef typename reversible_view
+ <
+ cview_type const,
+ Reverse ? iterate_reverse : iterate_forward
+ >::type rview_type;
+
+ cview_type cview(range);
+ rview_type view(cview);
+
+ typedef typename boost::range_iterator<rview_type>::type iterator;
+ geometry::ever_circling_iterator<iterator> it(boost::begin(view), boost::end(view),
+ boost::begin(view) + seg_id.segment_index, true);
+
+ for (signed_size_type i = 0; i < offset; ++i, ++it)
{
- index++;
- if (index >= n)
- {
- index = 0;
- }
}
- BOOST_GEOMETRY_ASSERT(index >= 0 && index < n);
-
- geometry::convert(*(boost::begin(view) + index), point);
+ geometry::convert(*it, point);
return true;
}
};
@@ -66,7 +76,7 @@ template <typename Polygon, bool Reverse, typename SegmentIdentifier, typename P
struct copy_segment_point_polygon
{
static inline bool apply(Polygon const& polygon,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point)
{
// Call ring-version with the right ring
@@ -81,7 +91,7 @@ struct copy_segment_point_polygon
seg_id.ring_index < 0
? geometry::exterior_ring(polygon)
: range::at(geometry::interior_rings(polygon), seg_id.ring_index),
- seg_id, second,
+ seg_id, offset,
point
);
}
@@ -92,11 +102,11 @@ template <typename Box, bool Reverse, typename SegmentIdentifier, typename Point
struct copy_segment_point_box
{
static inline bool apply(Box const& box,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point)
{
signed_size_type index = seg_id.segment_index;
- if (second)
+ for (int i = 0; i < offset; i++)
{
index++;
}
@@ -119,7 +129,7 @@ template
struct copy_segment_point_multi
{
static inline bool apply(MultiGeometry const& multi,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point)
{
@@ -130,7 +140,7 @@ struct copy_segment_point_multi
);
// Call the single-version
- return Policy::apply(range::at(multi, seg_id.multi_index), seg_id, second, point);
+ return Policy::apply(range::at(multi, seg_id.multi_index), seg_id, offset, point);
}
};
@@ -271,7 +281,7 @@ struct copy_segment_point
*/
template<bool Reverse, typename Geometry, typename SegmentIdentifier, typename PointOut>
inline bool copy_segment_point(Geometry const& geometry,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point_out)
{
concept::check<Geometry const>();
@@ -283,7 +293,7 @@ inline bool copy_segment_point(Geometry const& geometry,
Reverse,
SegmentIdentifier,
PointOut
- >::apply(geometry, seg_id, second, point_out);
+ >::apply(geometry, seg_id, offset, point_out);
}
@@ -300,7 +310,7 @@ template
typename PointOut
>
inline bool copy_segment_point(Geometry1 const& geometry1, Geometry2 const& geometry2,
- SegmentIdentifier const& seg_id, bool second,
+ SegmentIdentifier const& seg_id, int offset,
PointOut& point_out)
{
concept::check<Geometry1 const>();
@@ -317,7 +327,7 @@ inline bool copy_segment_point(Geometry1 const& geometry1, Geometry2 const& geom
Reverse1,
SegmentIdentifier,
PointOut
- >::apply(geometry1, seg_id, second, point_out);
+ >::apply(geometry1, seg_id, offset, point_out);
}
else if (seg_id.source_index == 1)
{
@@ -328,7 +338,7 @@ inline bool copy_segment_point(Geometry1 const& geometry1, Geometry2 const& geom
Reverse2,
SegmentIdentifier,
PointOut
- >::apply(geometry2, seg_id, second, point_out);
+ >::apply(geometry2, seg_id, offset, point_out);
}
// Exception?
return false;
@@ -354,10 +364,33 @@ inline bool copy_segment_points(Geometry1 const& geometry1, Geometry2 const& geo
concept::check<Geometry1 const>();
concept::check<Geometry2 const>();
- return copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, false, point1)
- && copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, true, point2);
+ return copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, 0, point1)
+ && copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, 1, point2);
}
+/*!
+ \brief Helper function, copies three points: two from the specified segment
+ (from, to) and the next one
+ \ingroup overlay
+ */
+template
+<
+ bool Reverse1, bool Reverse2,
+ typename Geometry1, typename Geometry2,
+ typename SegmentIdentifier,
+ typename PointOut
+>
+inline bool copy_segment_points(Geometry1 const& geometry1, Geometry2 const& geometry2,
+ SegmentIdentifier const& seg_id,
+ PointOut& point1, PointOut& point2, PointOut& point3)
+{
+ concept::check<Geometry1 const>();
+ concept::check<Geometry2 const>();
+
+ return copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, 0, point1)
+ && copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, 1, point2)
+ && copy_segment_point<Reverse1, Reverse2>(geometry1, geometry2, seg_id, 2, point3);
+}