diff --git a/Cargo.toml b/Cargo.toml index 87e6d3c9..e0563a5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ honeycomb-render = { version = "0.6.0", path = "./honeycomb-render" } # common cfg-if = "1" +itertools = "0.13.0" rayon = "1.10.0" rustversion = "1.0.18" thiserror = "2.0.3" diff --git a/benches/benches/core/cmap2/constructors.rs b/benches/benches/core/cmap2/constructors.rs index 35cb918d..9d53af21 100644 --- a/benches/benches/core/cmap2/constructors.rs +++ b/benches/benches/core/cmap2/constructors.rs @@ -67,32 +67,32 @@ library_benchmark_group!( #[bench::small(&mut get_map(16))] #[bench::medium(&mut get_map(64))] #[bench::large(&mut get_map(256))] -fn fetch_vertices(map: &mut CMap2) { - black_box(map.fetch_vertices()); +fn iter_vertices(map: &mut CMap2) { + black_box(map.iter_vertices().collect::>()); } #[library_benchmark] #[bench::small(&mut get_map(16))] #[bench::medium(&mut get_map(64))] #[bench::large(&mut get_map(256))] -fn fetch_edges(map: &mut CMap2) { - black_box(map.fetch_edges()); +fn iter_edges(map: &mut CMap2) { + black_box(map.iter_edges().collect::>()); } #[library_benchmark] #[bench::small(&mut get_map(16))] #[bench::medium(&mut get_map(64))] #[bench::large(&mut get_map(256))] -fn fetch_faces(map: &mut CMap2) { - black_box(map.fetch_faces()); +fn iter_faces(map: &mut CMap2) { + black_box(map.iter_faces().collect::>()); } library_benchmark_group!( name = bench_fetches; benchmarks = - fetch_vertices, - fetch_edges, - fetch_faces, + iter_vertices, + iter_edges, + iter_faces, ); // --- i-cell group diff --git a/benches/benches/core/cmap2/fetch_icells.rs b/benches/benches/core/cmap2/fetch_icells.rs index e24c2e01..ee91f3c3 100644 --- a/benches/benches/core/cmap2/fetch_icells.rs +++ b/benches/benches/core/cmap2/fetch_icells.rs @@ -15,19 +15,19 @@ pub fn criterion_benchmark(c: &mut Criterion) { group.bench_with_input(BenchmarkId::new("fetch-vertices", ""), &map, |b, m| { b.iter(|| { - let mut vertices = m.fetch_vertices(); + let mut vertices: Vec<_> = m.iter_vertices().collect(); black_box(&mut vertices); }) }); group.bench_with_input(BenchmarkId::new("fetch-edges", ""), &map, |b, m| { b.iter(|| { - let mut edges = m.fetch_edges(); + let mut edges: Vec<_> = m.iter_edges().collect(); black_box(&mut edges); }) }); group.bench_with_input(BenchmarkId::new("fetch-faces", ""), &map, |b, m| { b.iter(|| { - let mut faces = m.fetch_faces(); + let mut faces: Vec<_> = m.iter_faces().collect(); black_box(&mut faces); }) }); diff --git a/benches/benches/triangulate/quads.rs b/benches/benches/triangulate/quads.rs index 9fad1018..b387574e 100644 --- a/benches/benches/triangulate/quads.rs +++ b/benches/benches/triangulate/quads.rs @@ -15,7 +15,7 @@ fn fan_bench() -> Result<(), TriangulateError> { let mut map: CMap2 = CMapBuilder::default().vtk_file(PATH).build().unwrap(); // prealloc darts - let faces = map.fetch_faces().identifiers.clone(); + let faces: Vec<_> = map.iter_faces().collect(); let n_darts_per_face: Vec<_> = faces .iter() .map(|id| (Orbit2::new(&map, OrbitPolicy::Face, *id as DartIdType).count() - 3) * 2) @@ -49,7 +49,7 @@ fn earclip_bench() -> Result<(), TriangulateError> { let mut map: CMap2 = CMapBuilder::default().vtk_file(PATH).build().unwrap(); // prealloc darts - let faces = map.fetch_faces().identifiers.clone(); + let faces: Vec<_> = map.iter_faces().collect(); let n_darts_per_face: Vec<_> = faces .iter() .map(|id| (Orbit2::new(&map, OrbitPolicy::Face, *id as DartIdType).count() - 3) * 2) diff --git a/benches/src/shift.rs b/benches/src/shift.rs index 0045d515..6e51da45 100644 --- a/benches/src/shift.rs +++ b/benches/src/shift.rs @@ -50,9 +50,7 @@ fn main() { // fetch all vertices that are not on the boundary of the map let tmp: Vec<(VertexIdType, Vec)> = map - .fetch_vertices() - .identifiers - .into_iter() + .iter_vertices() .filter_map(|v| { if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) .any(|d| map.beta::<2>(d) == NULL_DART_ID) diff --git a/benches/src/shift_no_conflict.rs b/benches/src/shift_no_conflict.rs index 4bff8bb8..29fbaa6f 100644 --- a/benches/src/shift_no_conflict.rs +++ b/benches/src/shift_no_conflict.rs @@ -53,24 +53,20 @@ fn main() { let map: CMap2 = CMapBuilder::unit_grid(n_squares).build().unwrap(); // fetch all vertices that are not on the boundary of the map - let tmp = map - .fetch_vertices() - .identifiers - .into_iter() - .filter_map(|v| { - if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) - .any(|d| map.beta::<2>(d) == NULL_DART_ID) - { - None - } else { - Some(( - v, - Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) - .map(|d| map.vertex_id(map.beta::<2>(d))) - .collect(), - )) - } - }); + let tmp = map.iter_vertices().filter_map(|v| { + if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .any(|d| map.beta::<2>(d) == NULL_DART_ID) + { + None + } else { + Some(( + v, + Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .map(|d| map.vertex_id(map.beta::<2>(d))) + .collect(), + )) + } + }); #[allow(clippy::type_complexity)] let (first_batch, second_batch): ( diff --git a/examples/examples/io/write.rs b/examples/examples/io/write.rs index 7a937754..6453c02b 100644 --- a/examples/examples/io/write.rs +++ b/examples/examples/io/write.rs @@ -26,8 +26,8 @@ fn main() { println!("I: Start quad split process..."); let now = Instant::now(); - map.fetch_faces() - .identifiers + let faces: Vec<_> = map.iter_faces().collect(); + faces .iter() .filter(|square| splits[**square as usize % n_split]) .for_each(|square| { diff --git a/examples/examples/parallel_shift.rs b/examples/examples/parallel_shift.rs index 637bebd0..67fa3e8c 100644 --- a/examples/examples/parallel_shift.rs +++ b/examples/examples/parallel_shift.rs @@ -47,9 +47,7 @@ fn main() { // fetch all vertices that are not on the boundary of the map let nodes: Vec<(VertexIdType, Vec)> = map - .fetch_vertices() - .identifiers - .into_iter() + .iter_vertices() .filter_map(|v| { // the condition detects if we're on the boundary if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) diff --git a/honeycomb-core/Cargo.toml b/honeycomb-core/Cargo.toml index c005a487..6fc2d111 100644 --- a/honeycomb-core/Cargo.toml +++ b/honeycomb-core/Cargo.toml @@ -20,6 +20,7 @@ utils = [] [dependencies] downcast-rs.workspace = true +itertools.workspace = true loom.workspace= true num-traits.workspace = true stm.workspace = true diff --git a/honeycomb-core/src/cmap/builder/grid/building_routines.rs b/honeycomb-core/src/cmap/builder/grid/building_routines.rs index bbe170b9..c1c9179b 100644 --- a/honeycomb-core/src/cmap/builder/grid/building_routines.rs +++ b/honeycomb-core/src/cmap/builder/grid/building_routines.rs @@ -95,7 +95,7 @@ pub fn build_2d_grid( // check the number of built faces // this is set as debug only because the operation cost scales with map size // this can quickly overshadow the exectime of all previous code - debug_assert_eq!(map.fetch_faces().identifiers.len(), n_square_x * n_square_y); + debug_assert_eq!(map.iter_faces().count(), n_square_x * n_square_y); map } @@ -202,10 +202,7 @@ pub fn build_2d_splitgrid( // check the number of built faces // this is set as debug only because the operation cost scales with map size // this can quickly overshadow the exectime of all previous code - debug_assert_eq!( - map.fetch_faces().identifiers.len(), - 2 * n_square_x * n_square_y - ); + debug_assert_eq!(map.iter_faces().count(), 2 * n_square_x * n_square_y); map } diff --git a/honeycomb-core/src/cmap/builder/io/tests.rs b/honeycomb-core/src/cmap/builder/io/tests.rs index 8acf3a52..d4463a43 100644 --- a/honeycomb-core/src/cmap/builder/io/tests.rs +++ b/honeycomb-core/src/cmap/builder/io/tests.rs @@ -13,13 +13,12 @@ fn io_read() { let cmap: CMap2 = super::build_2d_from_vtk(vtk, AttrStorageManager::default()).unwrap(); // check result - let faces = cmap.fetch_faces(); - assert_eq!(faces.identifiers.len(), 4); - assert_eq!(cmap.fetch_edges().identifiers.len(), 12); - assert_eq!(cmap.fetch_vertices().identifiers.len(), 9); + let faces: Vec<_> = cmap.iter_faces().collect(); + assert_eq!(faces.len(), 4); + assert_eq!(cmap.iter_edges().count(), 12); + assert_eq!(cmap.iter_vertices().count(), 9); let mut n_vertices_per_face: Vec = faces - .identifiers .iter() .map(|id| Orbit2::new(&cmap, OrbitPolicy::Face, *id as DartIdType).count()) .collect(); diff --git a/honeycomb-core/src/cmap/components/collections.rs b/honeycomb-core/src/cmap/components/collections.rs deleted file mode 100644 index 53f055b6..00000000 --- a/honeycomb-core/src/cmap/components/collections.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! i-cell collection implementation -//! -//! This module contains all code used to model collection structures for i-cell identifiers. The -//! need for a specific structure stems from the need to ensure the validity of identifiers. - -// ------ IMPORTS - -use crate::cmap::{EdgeIdType, FaceIdType, VertexIdType}; -use crate::geometry::CoordsFloat; -use crate::prelude::CMap2; - -// ------ CONTENT - -macro_rules! collection_constructor { - ($coll: ident, $idty: ty) => { - impl<'a, T: CoordsFloat> $coll<'a, T> { - /// Constructor - pub(crate) fn new(_: &'a CMap2, ids: impl IntoIterator) -> Self { - Self { - lifetime_indicator: std::marker::PhantomData::default(), - identifiers: ids.into_iter().collect(), - } - } - } - }; -} - -// --- vertices - -/// Vertex ID collection -/// -/// # Generics -/// -/// - `'a` -- Lifetime of a reference to the associated map. -/// - `T: CoordsFloat` -- Generic of the associated map. -/// -/// # Example -/// -/// See the [`CMap2`] quickstart example. -/// -pub struct VertexCollection<'a, T: CoordsFloat> { - /// Lifetime holder - /// - /// This is used to ensure that the collection is only used while valid, i.e. it is invalidated - /// if the original map is used in a mutable context. - lifetime_indicator: std::marker::PhantomData<&'a CMap2>, - /// Collection of vertex identifiers. - pub identifiers: Vec, -} - -unsafe impl Send for VertexCollection<'_, T> {} -unsafe impl Sync for VertexCollection<'_, T> {} - -collection_constructor!(VertexCollection, VertexIdType); - -// --- edges - -/// Edge ID collection -/// -/// # Generics -/// -/// - `'a` -- Lifetime of a reference to the associated map. -/// - `T: CoordsFloat` -- Generic of the associated map. -/// -/// # Example -/// -/// See the [`CMap2`] quickstart example. -/// -pub struct EdgeCollection<'a, T: CoordsFloat> { - /// Lifetime holder - /// - /// This is used to ensure that the collection is only used while valid, i.e. it is invalidated - /// if the original map is used in a mutable context. - lifetime_indicator: std::marker::PhantomData<&'a CMap2>, - /// Collection of vertex identifiers. - pub identifiers: Vec, -} - -unsafe impl Send for EdgeCollection<'_, T> {} -unsafe impl Sync for EdgeCollection<'_, T> {} - -collection_constructor!(EdgeCollection, EdgeIdType); - -// --- faces - -/// Face ID collection -/// -/// # Generics -/// -/// - `'a` -- Lifetime of a reference to the associated map. -/// - `T: CoordsFloat` -- Generic of the associated map. -/// -/// # Example -/// -/// See the [`CMap2`] quickstart example. -/// -pub struct FaceCollection<'a, T: CoordsFloat> { - /// Lifetime holder - /// - /// This is used to ensure that the collection is only used while valid, i.e. it is invalidated - /// if the original map is used in a mutable context. - lifetime_indicator: std::marker::PhantomData<&'a CMap2>, - /// Collection of vertex identifiers. - pub identifiers: Vec, -} - -unsafe impl Send for FaceCollection<'_, T> {} -unsafe impl Sync for FaceCollection<'_, T> {} - -collection_constructor!(FaceCollection, FaceIdType); - -// --- volumes diff --git a/honeycomb-core/src/cmap/components/mod.rs b/honeycomb-core/src/cmap/components/mod.rs index aef842e3..ca890ca5 100644 --- a/honeycomb-core/src/cmap/components/mod.rs +++ b/honeycomb-core/src/cmap/components/mod.rs @@ -1,7 +1,6 @@ //! Common components of the `CMap2` implementation pub mod betas; -pub mod collections; pub mod identifiers; pub mod orbits; pub mod unused; diff --git a/honeycomb-core/src/cmap/dim2/basic_ops.rs b/honeycomb-core/src/cmap/dim2/basic_ops.rs index 889727bf..49a9e81c 100644 --- a/honeycomb-core/src/cmap/dim2/basic_ops.rs +++ b/honeycomb-core/src/cmap/dim2/basic_ops.rs @@ -12,11 +12,8 @@ use crate::prelude::{ CMap2, DartIdType, EdgeIdType, FaceIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID, }; -use crate::{ - attributes::UnknownAttributeStorage, - cmap::{EdgeCollection, FaceCollection, VertexCollection}, - geometry::CoordsFloat, -}; +use crate::{attributes::UnknownAttributeStorage, geometry::CoordsFloat}; +use itertools::Itertools; use std::collections::{BTreeSet, VecDeque}; use stm::{atomically, StmError, Transaction}; @@ -436,16 +433,10 @@ impl CMap2 { } } - /// Return a collection of all the map's vertices. - /// - /// # Return - /// - /// Return a [`VertexCollection`] object containing a list of vertex identifiers, whose validity - /// is ensured through an implicit lifetime condition on the structure and original map. - /// + /// Return an iterator over IDs of all the map's faces. #[must_use = "returned value is not used, consider removing this method call"] - pub fn fetch_vertices(&self) -> VertexCollection { - let vids: BTreeSet = (1..self.n_darts as DartIdType) + pub fn iter_vertices(&self) -> impl Iterator + '_ { + (1..self.n_darts() as DartIdType) .zip(self.unused_darts.iter().skip(1)) .filter_map(|(d, unused)| { if unused.read_atomic() { @@ -454,20 +445,13 @@ impl CMap2 { Some(self.vertex_id(d)) } }) - .collect(); // duplicates are automatically handled when colelcting into a set - VertexCollection::<'_, T>::new(self, vids) + .unique() } - /// Return a collection of all the map's edges. - /// - /// # Return - /// - /// Return an [`EdgeCollection`] object containing a list of edge identifiers, whose validity - /// is ensured through an implicit lifetime condition on the structure and original map. - /// + /// Return an iterator over IDs of all the map's edges. #[must_use = "returned value is not used, consider removing this method call"] - pub fn fetch_edges(&self) -> EdgeCollection { - let eids: BTreeSet = (1..self.n_darts as DartIdType) + pub fn iter_edges(&self) -> impl Iterator + '_ { + (1..self.n_darts() as DartIdType) .zip(self.unused_darts.iter().skip(1)) .filter_map(|(d, unused)| { if unused.read_atomic() { @@ -476,20 +460,13 @@ impl CMap2 { Some(self.edge_id(d)) } }) - .collect(); // duplicates are automatically handled when colelcting into a set - EdgeCollection::<'_, T>::new(self, eids) + .unique() } - /// Return a collection of all the map's faces. - /// - /// # Return - /// - /// Return a [`FaceCollection`] object containing a list of face identifiers, whose validity - /// is ensured through an implicit lifetime condition on the structure and original map. - /// + /// Return an iterator over IDs of all the map's faces. #[must_use = "returned value is not used, consider removing this method call"] - pub fn fetch_faces(&self) -> FaceCollection { - let fids: BTreeSet = (1..self.n_darts as DartIdType) + pub fn iter_faces(&self) -> impl Iterator + '_ { + (1..self.n_darts() as DartIdType) .zip(self.unused_darts.iter().skip(1)) .filter_map(|(d, unused)| { if unused.read_atomic() { @@ -498,7 +475,6 @@ impl CMap2 { Some(self.face_id(d)) } }) - .collect(); // duplicates are automatically handled when colelcting into a set - FaceCollection::<'_, T>::new(self, fids) + .unique() } } diff --git a/honeycomb-core/src/cmap/dim2/io.rs b/honeycomb-core/src/cmap/dim2/io.rs index c8f318ed..fb241836 100644 --- a/honeycomb-core/src/cmap/dim2/io.rs +++ b/honeycomb-core/src/cmap/dim2/io.rs @@ -7,6 +7,7 @@ // ------ IMPORTS +use crate::cmap::{EdgeIdType, FaceIdType}; use crate::geometry::CoordsFloat; use crate::prelude::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID}; @@ -84,7 +85,7 @@ where T: CoordsFloat + 'static, { // common data - let vertex_ids: Vec = map.fetch_vertices().identifiers; + let vertex_ids: Vec = map.iter_vertices().collect(); let mut id_map: BTreeMap = BTreeMap::new(); vertex_ids.iter().enumerate().for_each(|(id, vid)| { id_map.insert(*vid, id); @@ -100,7 +101,7 @@ where // ------ cells data let mut n_cells = 0; // --- faces - let face_ids = map.fetch_faces().identifiers; + let face_ids: Vec = map.iter_faces().collect(); let face_data = face_ids.into_iter().map(|id| { let mut count: u32 = 0; // VecDeque will be useful later @@ -114,7 +115,7 @@ where }); // --- borders - let edge_ids = map.fetch_edges().identifiers; + let edge_ids: Vec = map.iter_edges().collect(); // because we do not model boundaries, we can get edges // from filtering isolated darts making up edges let edge_data = edge_ids diff --git a/honeycomb-core/src/cmap/dim2/structure.rs b/honeycomb-core/src/cmap/dim2/structure.rs index 34e45794..4969ace4 100644 --- a/honeycomb-core/src/cmap/dim2/structure.rs +++ b/honeycomb-core/src/cmap/dim2/structure.rs @@ -97,15 +97,15 @@ use crate::{ /// map.force_write_vertex(6, (1.0, 1.0)); /// /// // there should be two faces now -/// let faces = map.fetch_faces(); -/// assert_eq!(&faces.identifiers, &[1, 4]); +/// let faces: Vec<_> = map.iter_faces().collect(); +/// assert_eq!(&faces, &[1, 4]); /// /// // sew both triangles /// map.force_two_sew(2, 4); /// /// // there are 5 edges now, making up a square & its diagonal -/// let edges = map.fetch_edges(); -/// assert_eq!(&edges.identifiers, &[1, 2, 3, 5, 6]); +/// let edges: Vec<_> = map.iter_edges().collect(); +/// assert_eq!(&edges, &[1, 2, 3, 5, 6]); /// /// // adjust bottom-right & top-left vertex position /// // the returned values were the average of the sewn vertices @@ -132,11 +132,11 @@ use crate::{ /// map.force_one_sew(6, 3); /// /// // there's only the square face left -/// let faces = map.fetch_faces(); -/// assert_eq!(&faces.identifiers, &[1]); +/// let faces: Vec<_> = map.iter_faces().collect(); +/// assert_eq!(&faces, &[1]); /// // we can check the vertices -/// let vertices = map.fetch_vertices(); -/// let mut value_iterator = vertices.identifiers.iter().map(|vertex_id| map.force_read_vertex(*vertex_id).unwrap()); +/// let vertices = map.iter_vertices(); +/// let mut value_iterator = vertices.map(|vertex_id| map.force_read_vertex(vertex_id).unwrap()); /// assert_eq!(value_iterator.next(), Some(Vertex2::from((0.0, 0.0)))); // vertex ID 1 /// assert_eq!(value_iterator.next(), Some(Vertex2::from((0.0, 1.0)))); // vertex ID 3 /// assert_eq!(value_iterator.next(), Some(Vertex2::from((1.0, 0.0)))); // vertex ID 5 diff --git a/honeycomb-core/src/cmap/dim2/tests.rs b/honeycomb-core/src/cmap/dim2/tests.rs index 0361717b..1977abb8 100644 --- a/honeycomb-core/src/cmap/dim2/tests.rs +++ b/honeycomb-core/src/cmap/dim2/tests.rs @@ -22,9 +22,9 @@ fn example_test() { map.force_write_vertex(3, (0.0, 1.0)); // checks - let faces = map.fetch_faces(); - assert_eq!(faces.identifiers.len(), 1); - assert_eq!(faces.identifiers[0], 1); + let faces: Vec<_> = map.iter_faces().collect(); + assert_eq!(faces.len(), 1); + assert_eq!(faces[0], 1); let mut face = Orbit2::new(&map, OrbitPolicy::Face, 1); assert_eq!(face.next(), Some(1)); assert_eq!(face.next(), Some(2)); @@ -41,8 +41,8 @@ fn example_test() { map.force_write_vertex(6, (1.0, 1.0)); // checks - let faces = map.fetch_faces(); - assert_eq!(&faces.identifiers, &[1, 4]); + let faces: Vec<_> = map.iter_faces().collect(); + assert_eq!(&faces, &[1, 4]); let mut face = Orbit2::new(&map, OrbitPolicy::Face, 4); assert_eq!(face.next(), Some(4)); assert_eq!(face.next(), Some(5)); @@ -60,8 +60,8 @@ fn example_test() { assert_eq!(map.vertex_id(3), 3); assert_eq!(map.vertex_id(4), 3); assert_eq!(map.force_read_vertex(3).unwrap(), Vertex2::from((0.0, 1.5))); - let edges = map.fetch_edges(); - assert_eq!(&edges.identifiers, &[1, 2, 3, 5, 6]); + let edges: Vec<_> = map.iter_edges().collect(); + assert_eq!(&edges, &[1, 2, 3, 5, 6]); // adjust bottom-right & top-left vertex position assert_eq!( @@ -89,12 +89,12 @@ fn example_test() { map.force_one_sew(6, 3); // i-cells - let faces = map.fetch_faces(); - assert_eq!(&faces.identifiers, &[1]); - let edges = map.fetch_edges(); - assert_eq!(&edges.identifiers, &[1, 3, 5, 6]); - let vertices = map.fetch_vertices(); - assert_eq!(&vertices.identifiers, &[1, 3, 5, 6]); + let faces: Vec<_> = map.iter_faces().collect(); + assert_eq!(&faces, &[1]); + let edges: Vec<_> = map.iter_edges().collect(); + assert_eq!(&edges, &[1, 3, 5, 6]); + let vertices: Vec<_> = map.iter_vertices().collect(); + assert_eq!(&vertices, &[1, 3, 5, 6]); assert_eq!(map.force_read_vertex(1).unwrap(), Vertex2::from((0.0, 0.0))); assert_eq!(map.force_read_vertex(5).unwrap(), Vertex2::from((1.0, 0.0))); assert_eq!(map.force_read_vertex(6).unwrap(), Vertex2::from((1.0, 1.0))); diff --git a/honeycomb-core/src/cmap/mod.rs b/honeycomb-core/src/cmap/mod.rs index d8886532..e1138a8a 100644 --- a/honeycomb-core/src/cmap/mod.rs +++ b/honeycomb-core/src/cmap/mod.rs @@ -7,7 +7,6 @@ mod error; pub use builder::{BuilderError, CMapBuilder}; pub use components::{ - collections::{EdgeCollection, FaceCollection, VertexCollection}, identifiers::{ DartIdType, EdgeIdType, FaceIdType, VertexIdType, VolumeIdType, NULL_DART_ID, NULL_EDGE_ID, NULL_FACE_ID, NULL_VERTEX_ID, NULL_VOLUME_ID, diff --git a/honeycomb-kernels/src/grisubal/tests.rs b/honeycomb-kernels/src/grisubal/tests.rs index 79b526f6..71947769 100644 --- a/honeycomb-kernels/src/grisubal/tests.rs +++ b/honeycomb-kernels/src/grisubal/tests.rs @@ -234,30 +234,31 @@ fn regular_intersections() { // | | | // +-----+-----+ - let faces = cmap.fetch_faces(); - assert_eq!(faces.identifiers.len(), 8); + let faces: Vec<_> = cmap.iter_faces().collect(); + assert_eq!(faces.len(), 8); // bottom left - assert!(faces.identifiers.contains(&1)); + assert!(faces.contains(&1)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 1).count(), 6); - assert!(faces.identifiers.contains(&3)); + assert!(faces.contains(&3)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 3).count(), 4); // bottom right - assert!(faces.identifiers.contains(&5)); + assert!(faces.contains(&5)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 5).count(), 6); - assert!(faces.identifiers.contains(&8)); + assert!(faces.contains(&8)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 8).count(), 4); // top right - assert!(faces.identifiers.contains(&9)); + assert!(faces.contains(&9)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 9).count(), 6); - assert!(faces.identifiers.contains(&10)); + assert!(faces.contains(&10)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 10).count(), 4); // top left - assert!(faces.identifiers.contains(&14)); + assert!(faces.contains(&14)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 14).count(), 6); - assert!(faces.identifiers.contains(&13)); + assert!(faces.contains(&13)); assert_eq!(Orbit2::new(&cmap, OrbitPolicy::Face, 13).count(), 4); } +#[allow(clippy::too_many_lines)] #[test] fn corner_intersection() { use num_traits::Float; @@ -357,10 +358,10 @@ fn corner_intersection() { // | | | // +-----+-----+ - let faces = cmap.fetch_faces(); - assert_eq!(faces.identifiers.len(), 7); - let edges = cmap.fetch_edges(); - assert_eq!(edges.identifiers.len(), 20); + let faces = cmap.iter_faces(); + assert_eq!(faces.count(), 7); + let edges = cmap.iter_edges(); + assert_eq!(edges.count(), 20); let face1_vertices: Vec> = Orbit2::new(&cmap, OrbitPolicy::Face, 1) .map(|d| { diff --git a/honeycomb-render/src/capture/mod.rs b/honeycomb-render/src/capture/mod.rs index bdf9678d..c0e1a547 100644 --- a/honeycomb-render/src/capture/mod.rs +++ b/honeycomb-render/src/capture/mod.rs @@ -51,22 +51,21 @@ pub struct Capture { impl Capture { #[allow(clippy::too_many_lines)] pub fn new(cap_id: usize, cmap: &CMap2) -> Self { - let map_vertices = cmap.fetch_vertices(); - let map_edges = cmap.fetch_edges(); - let map_faces = cmap.fetch_faces(); + let map_vertices: Vec<_> = cmap.iter_vertices().collect(); + let map_edges: Vec<_> = cmap.iter_edges().collect(); + let map_faces: Vec<_> = cmap.iter_faces().collect(); let metadata = CaptureMD { capture_id: cap_id, n_darts: cmap.n_darts() - cmap.n_unused_darts(), n_vertices: cmap.n_vertices(), - n_edges: map_edges.identifiers.len(), - n_faces: map_faces.identifiers.len(), + n_edges: map_edges.len(), + n_faces: map_faces.len(), n_volumes: 0, }; let mut index_map: HashMap = HashMap::with_capacity(cmap.n_vertices()); let vertex_vals: Vec = map_vertices - .identifiers .iter() .enumerate() .map(|(idx, vid)| { @@ -80,13 +79,11 @@ impl Capture { .collect(); let vertices: Vec = map_vertices - .identifiers .iter() .map(|id| VertexBundle::new(cap_id, *id, index_map[id])) .collect(); let edges: Vec = map_edges - .identifiers .iter() .map(|id| { let v1id = cmap.vertex_id(*id as DartIdType); @@ -103,7 +100,6 @@ impl Capture { let mut darts: Vec<(DartHeadBundle, DartBodyBundle)> = Vec::new(); let faces: Vec = map_faces - .identifiers .iter() .map(|id| { let vertex_ids: Vec = diff --git a/user-guide/src/usage/stm.md b/user-guide/src/usage/stm.md index b56132a5..1aa15c9d 100644 --- a/user-guide/src/usage/stm.md +++ b/user-guide/src/usage/stm.md @@ -48,8 +48,6 @@ fn main() { // fetch all vertices that are not on the boundary of the map let nodes: Vec<(VertexIdType, Vec)> = map .fetch_vertices() - .identifiers - .into_iter() .filter_map(|v| { // the condition detects if we're on the boundary if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)