}
};
-
+// Returns the number of segments on a ring (regardless whether the ring is open or closed)
template <typename Geometry>
-inline std::size_t segment_count_on_ring(Geometry const& geometry,
- segment_identifier const& seg_id)
+inline signed_size_type segment_count_on_ring(Geometry const& geometry,
+ ring_identifier const& ring_id)
{
- typedef typename geometry::tag<Geometry>::type tag;
- ring_identifier const rid(0, seg_id.multi_index, seg_id.ring_index);
+ using tag = typename geometry::tag<Geometry>::type;
+
// A closed polygon, a triangle of 4 points, including starting point,
- // contains 3 segments. So handle as if closed and subtract one.
- return geometry::num_points(detail::overlay::get_ring<tag>::apply(rid, geometry), true) - 1;
+ // contains 3 segments. So handle as if it is closed, and subtract one.
+ return geometry::num_points(detail::overlay::get_ring<tag>::apply(ring_id, geometry), true) - 1;
+}
+
+// Returns the number of segments on a ring (regardless whether the ring is open or closed)
+template <typename Geometry>
+inline signed_size_type segment_count_on_ring(Geometry const& geometry,
+ segment_identifier const& seg_id)
+{
+ return segment_count_on_ring(geometry, ring_identifier(0, seg_id.multi_index, seg_id.ring_index));
+}
+
+
+// Returns the distance between the second and the first segment identifier (second-first)
+// It supports circular behavior and for this it is necessary to pass the geometry.
+// It will not report negative values
+template <typename Geometry>
+inline signed_size_type segment_distance(Geometry const& geometry,
+ segment_identifier const& first, segment_identifier const& second)
+{
+ // It is an internal function, make sure the preconditions are met
+ BOOST_ASSERT(second.source_index == first.source_index);
+ BOOST_ASSERT(second.multi_index == first.multi_index);
+ BOOST_ASSERT(second.ring_index == first.ring_index);
+
+ signed_size_type const result = second.segment_index - first.segment_index;
+ if (second.segment_index >= first.segment_index)
+ {
+ return result;
+ }
+ // Take wrap into account, counting segments on the ring (passing any of the ids is fine).
+ // Suppose point_count=10 (10 points, 9 segments), first.seg_id=7, second.seg_id=2,
+ // then distance=9-7+2=4, being segments 7,8,0,1
+ return segment_count_on_ring(geometry, first) + result;
}
}} // namespace detail::overlay