]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/geometry/algorithms/detail/overlay/get_ring.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / overlay / get_ring.hpp
index 1cf5b1e9d1a9a5cd83375e23c423bec863638d59..f93cb23f59f032444f380bbbc3c9a7f86bf55b40 100644 (file)
@@ -117,16 +117,48 @@ struct get_ring<multi_polygon_tag>
     }
 };
 
-
+// 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