MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / ring_edges

Function ring_edges

nodedb-spatial/src/predicates/edge.rs:148–163  ·  view source on GitHub ↗

Extract all edges from a polygon ring as segment pairs.

(ring: &[[f64; 2]])

Source from the content-addressed store, hash-verified

146
147/// Extract all edges from a polygon ring as segment pairs.
148pub fn ring_edges(ring: &[[f64; 2]]) -> Vec<([f64; 2], [f64; 2])> {
149 if ring.len() < 2 {
150 return Vec::new();
151 }
152 let mut edges = Vec::with_capacity(ring.len());
153 for i in 0..ring.len() - 1 {
154 edges.push((ring[i], ring[i + 1]));
155 }
156 // Close the ring if not explicitly closed.
157 if ring.first() != ring.last()
158 && let (Some(&first), Some(&last)) = (ring.first(), ring.last())
159 {
160 edges.push((last, first));
161 }
162 edges
163}
164
165#[cfg(test)]
166mod tests {

Callers 7

ring_edges_closedFunction · 0.85
polygons_intersectFunction · 0.85
polygon_contains_polygonFunction · 0.85

Calls 4

firstMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
lastMethod · 0.45

Tested by 1

ring_edges_closedFunction · 0.68