Skip to content

Commit

Permalink
refactor!(core): remove orbit structure in favor of map methods (#294)
Browse files Browse the repository at this point in the history
* replace Orbit2 by generic function

* replace Orbit3 with generic method

* fix 2D tests

* fix the rest of core

* move tests out of orbits module

* fix kernels and render

* fix last stuff

* fix clippy lints

* rewrite internal code to be clearer
  • Loading branch information
imrn99 authored Mar 6, 2025
1 parent 5d7fd43 commit 9a4b00a
Show file tree
Hide file tree
Showing 22 changed files with 594 additions and 595 deletions.
6 changes: 3 additions & 3 deletions benches/benches/triangulate/quads.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use honeycomb::prelude::{
CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy,
CMap2, CMapBuilder, DartIdType, OrbitPolicy,
triangulation::{TriangulateError, earclip_cell, fan_cell},
};

Expand All @@ -15,7 +15,7 @@ fn fan_bench() -> Result<(), TriangulateError> {
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)
.map(|id| (map.orbit(OrbitPolicy::Face, *id as DartIdType).count() - 3) * 2)
.collect();
let n_tot: usize = n_darts_per_face.iter().sum();
let tmp = map.add_free_darts(n_tot) as usize;
Expand Down Expand Up @@ -49,7 +49,7 @@ fn earclip_bench() -> Result<(), TriangulateError> {
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)
.map(|id| (map.orbit(OrbitPolicy::Face, *id as DartIdType).count() - 3) * 2)
.collect();
let n_tot: usize = n_darts_per_face.iter().sum();
let tmp = map.add_free_darts(n_tot) as usize;
Expand Down
4 changes: 2 additions & 2 deletions benches/src/cut_edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub fn bench_cut_edges<T: CoordsFloat>(args: CutEdgesArgs) -> CMap2<T> {
};
#[cfg(debug_assertions)] // check input
{
use honeycomb::prelude::{Orbit2, OrbitPolicy};
use honeycomb::prelude::OrbitPolicy;
assert!(
map.iter_faces()
.all(|f| { Orbit2::new(&map, OrbitPolicy::Face, f as DartIdType).count() == 3 }),
.all(|f| { map.orbit(OrbitPolicy::Face, f as DartIdType).count() == 3 }),
"Input mesh isn't a triangle mesh"
);
}
Expand Down
4 changes: 2 additions & 2 deletions benches/src/grid_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant};

use honeycomb::{
core::stm::atomically_with_err,
prelude::{CMap2, CMapBuilder, CoordsFloat, DartIdType, GridDescriptor, Orbit2, OrbitPolicy},
prelude::{CMap2, CMapBuilder, CoordsFloat, DartIdType, GridDescriptor, OrbitPolicy},
};
use rand::{
SeedableRng,
Expand Down Expand Up @@ -57,7 +57,7 @@ fn split_faces_randomly<T: CoordsFloat>(
.par_bridge()
.for_each(|((df, sl), split)| {
let square = df as DartIdType;
assert_eq!(Orbit2::new(map, OrbitPolicy::FaceLinear, df).count(), 4);
assert_eq!(map.orbit(OrbitPolicy::FaceLinear, df).count(), 4);
let (ddown, dright, dup, dleft) = (square, square + 1, square + 2, square + 3);

let &[dsplit1, dsplit2] = sl else {
Expand Down
7 changes: 4 additions & 3 deletions benches/src/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rayon::prelude::*;

use honeycomb::core::stm::{Transaction, TransactionControl};
use honeycomb::prelude::{
CMap2, CMapBuilder, CoordsFloat, DartIdType, NULL_DART_ID, Orbit2, OrbitPolicy, VertexIdType,
CMap2, CMapBuilder, CoordsFloat, DartIdType, NULL_DART_ID, OrbitPolicy, VertexIdType,
};

use crate::cli::ShiftArgs;
Expand Down Expand Up @@ -49,14 +49,15 @@ pub fn bench_shift<T: CoordsFloat>(args: ShiftArgs) -> CMap2<T> {
let tmp: Vec<(VertexIdType, Vec<VertexIdType>)> = map
.iter_vertices()
.filter_map(|v| {
if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
if map
.orbit(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.orbit(OrbitPolicy::Vertex, v as DartIdType)
.map(|d| map.vertex_id(map.beta::<2>(d)))
.collect(),
))
Expand Down
7 changes: 4 additions & 3 deletions examples/examples/parallel_shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
use honeycomb_core::cmap::{
CMap2, CMapBuilder, DartIdType, NULL_DART_ID, Orbit2, OrbitPolicy, VertexIdType,
CMap2, CMapBuilder, DartIdType, NULL_DART_ID, OrbitPolicy, VertexIdType,
};
use honeycomb_core::geometry::Vertex2;
use honeycomb_core::stm::atomically;
Expand Down Expand Up @@ -51,15 +51,16 @@ fn main() {
.iter_vertices()
.filter_map(|v| {
// the condition detects if we're on the boundary
if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
if map
.orbit(OrbitPolicy::Vertex, v as DartIdType)
.any(|d| map.beta::<2>(d) == NULL_DART_ID)
{
None
} else {
// the orbit transformation yields neighbor IDs
Some((
v,
Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
map.orbit(OrbitPolicy::Vertex, v as DartIdType)
.map(|d| map.vertex_id(map.beta::<2>(d)))
.collect(),
))
Expand Down
4 changes: 2 additions & 2 deletions honeycomb-core/src/cmap/builder/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use vtkio::Vtk;

use crate::attributes::AttrStorageManager;
use crate::cmap::{CMap2, CMapBuilder, DartIdType, GridDescriptor, Orbit2, OrbitPolicy};
use crate::cmap::{CMap2, CMapBuilder, DartIdType, GridDescriptor, OrbitPolicy};

// --- basic

Expand Down Expand Up @@ -499,7 +499,7 @@ mod vtk {

let mut n_vertices_per_face: Vec<usize> = faces
.iter()
.map(|id| Orbit2::new(&cmap, OrbitPolicy::Face, *id as DartIdType).count())
.map(|id| cmap.orbit(OrbitPolicy::Face, *id as DartIdType).count())
.collect();
let (mut three_count, mut four_count, mut six_count): (usize, usize, usize) = (0, 0, 0);
while let Some(n) = n_vertices_per_face.pop() {
Expand Down
25 changes: 1 addition & 24 deletions honeycomb-core/src/cmap/dim2/basic_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use std::cell::RefCell;
use std::collections::{HashSet, VecDeque};

use crate::attributes::UnknownAttributeStorage;
use crate::cmap::{
CMap2, DartIdType, EdgeIdType, FaceIdType, NULL_DART_ID, Orbit2, OrbitPolicy, VertexIdType,
};
use crate::cmap::{CMap2, DartIdType, EdgeIdType, FaceIdType, NULL_DART_ID, VertexIdType};
use crate::geometry::CoordsFloat;
use crate::stm::{StmClosureResult, Transaction, atomically};

Expand Down Expand Up @@ -396,27 +394,6 @@ impl<T: CoordsFloat> CMap2<T> {
})
}

/// Return the orbit defined by a dart and its `I`-cell.
///
/// # Usage
///
/// The [`Orbit2`] can be iterated upon to retrieve all dart member of the cell. Note that
/// **the dart passed as an argument is included as the first element of the returned orbit**.
///
/// # Panics
///
/// The method will panic if *I* is not 0, 1 or 2.
#[must_use = "unused return value"]
pub fn i_cell<const I: u8>(&self, dart_id: DartIdType) -> Orbit2<T> {
assert!(I < 3);
match I {
0 => Orbit2::<'_, T>::new(self, OrbitPolicy::Vertex, dart_id),
1 => Orbit2::<'_, T>::new(self, OrbitPolicy::Edge, dart_id),
2 => Orbit2::<'_, T>::new(self, OrbitPolicy::Face, dart_id),
_ => unreachable!(),
}
}

/// Return an iterator over IDs of all the map's vertices.
#[must_use = "unused return value"]
pub fn iter_vertices(&self) -> impl Iterator<Item = VertexIdType> + '_ {
Expand Down
Loading

0 comments on commit 9a4b00a

Please sign in to comment.