honeycomb_kernels::splits

Function splitn_edge

Source
pub fn splitn_edge<T: CoordsFloat>(
    cmap: &mut CMap2<T>,
    edge_id: EdgeIdType,
    midpoint_vertices: impl IntoIterator<Item = T>,
) -> Result<(), SplitEdgeError>
Expand description

Split an edge into n segments.

This implementation is 2D specific.

§Arguments

  • cmap: &mut CMap2<T> – Reference to the modified map.
  • edge_id: EdgeIdentifier – Edge to split in two.
  • midpoint_vertices: I – Relative positions of new vertices, starting from the vertex of the dart sharing edge_id as its identifier.

§Generics

  • I: Iterator<Item = T> – Iterator over T values. These should be in the ]0; 1[ open range.

§Return / Errors

This method will return:

  • Ok(()) if the operation is successful & the edge was split
  • Err(SplitEdgeError) if the operation fails & the edge is left unchanged. Causes of failure are described in SplitEdgeError’s documentation.

§Example

// before
//    <--2---
//  1         2
//    ---1-->
let mut map: CMap2<f64> = CMapBuilder::default()
                            .n_darts(2)
                            .build()
                            .unwrap();
map.two_link(1, 2);
map.insert_vertex(1, (0.0, 0.0));
map.insert_vertex(2, (1.0, 0.0));
// split
assert!(splitn_edge(&mut map, 1, [0.25, 0.50, 0.75]).is_ok());
// after
//    <-<-<-<
//  1 -3-4-5- 2
//    >->->->
let new_darts = [
    map.beta::<1>(1),
    map.beta::<1>(map.beta::<1>(1)),
    map.beta::<1>(map.beta::<1>(map.beta::<1>(1))),
];
assert_eq!(&new_darts, &[3, 4, 5]);
assert_eq!(map.vertex(3), Some(Vertex2(0.25, 0.0)));
assert_eq!(map.vertex(4), Some(Vertex2(0.50, 0.0)));
assert_eq!(map.vertex(5), Some(Vertex2(0.75, 0.0)));

assert_eq!(map.beta::<1>(1), 3);
assert_eq!(map.beta::<1>(3), 4);
assert_eq!(map.beta::<1>(4), 5);
assert_eq!(map.beta::<1>(5), NULL_DART_ID);

assert_eq!(map.beta::<1>(2), 6);
assert_eq!(map.beta::<1>(6), 7);
assert_eq!(map.beta::<1>(7), 8);
assert_eq!(map.beta::<1>(8), NULL_DART_ID);

assert_eq!(map.beta::<2>(1), 8);
assert_eq!(map.beta::<2>(3), 7);
assert_eq!(map.beta::<2>(4), 6);
assert_eq!(map.beta::<2>(5), 2);