From 064479a957b701c0ed1b906a92cbef1a8261f222 Mon Sep 17 00:00:00 2001 From: n33levo Date: Sat, 10 Oct 2026 20:46:23 -0400 Subject: [PATCH] perf: index cells during soft-body tearing --- .../soft_body/tearing/tearing_crack.rs | 23 +- src/dynamics/soft_body/tearing/tearing_cut.rs | 2 +- .../tearing/tearing_particle_split.rs | 178 +++++++++-- src/dynamics/soft_body/tearing/tests.rs | 281 +++++++++++++++++- 4 files changed, 442 insertions(+), 42 deletions(-) diff --git a/src/dynamics/soft_body/tearing/tearing_crack.rs b/src/dynamics/soft_body/tearing/tearing_crack.rs index 47aecea9a..b385f4dd5 100644 --- a/src/dynamics/soft_body/tearing/tearing_crack.rs +++ b/src/dynamics/soft_body/tearing/tearing_crack.rs @@ -9,7 +9,7 @@ use parry::utils::hashmap::HashMap; use super::super::SoftBody; use super::tearing::pair; use super::tearing_event::SoftBodyTearEvent; -use super::tearing_particle_split::{Fan, MeasureKind, SplitLog}; +use super::tearing_particle_split::{CellIndex, Fan, MeasureKind, SplitLog}; /// The mean load of the fan elements on the given side of the split plane. fn side_load(fan: &Fan, side: usize, load: impl Fn(u32) -> Real) -> Real { @@ -61,7 +61,14 @@ impl SoftBody { .map(|&c| self.cells[c as usize].vertices) .collect(); - let mut log = SplitLog::default(); + let mut log = SplitLog { + cell_index: if kind == MeasureKind::Cells { + CellIndex::new(self) + } else { + None + }, + ..SplitLog::default() + }; for &[a, b] in &edges { let first = log.split_particles.len(); // An edge an earlier split removed (a straddler) is already open. @@ -167,7 +174,7 @@ impl SoftBody { let (fa, fb) = (family(a), family(b)); for &x in &fa { for &y in &fb { - if self.measure_element_holds(&[x, y]) { + if self.measure_element_holds_indexed(&[x, y], log.cell_index.as_ref()) { return Some((x, y)); } } @@ -202,7 +209,7 @@ impl SoftBody { for (v, other) in [(a, b), (b, a)] { let origin = self.particles[v as usize].rest_position; let normal = self.particles[other as usize].rest_position - origin; - if let Some(fan) = self.plane_fan(v, origin, normal) { + if let Some(fan) = self.plane_fan(v, origin, normal, log.cell_index.as_ref()) { let load = side_load(&fan, 1, |e| match fan.kind { MeasureKind::Segments => self.edges[e as usize].stress, _ => loads[e as usize], @@ -213,7 +220,7 @@ impl SoftBody { options.sort_by(|x, y| y.0.total_cmp(&x.0).then(x.1.cmp(&y.1))); let Some((_, v, fan)) = options .into_iter() - .find(|(_, v, fan)| self.opens_without_confetti(*v, fan)) + .find(|(_, v, fan)| self.opens_without_confetti(*v, fan, log.cell_index.as_ref())) else { return false; }; @@ -266,8 +273,10 @@ impl SoftBody { order.sort_by(|x, y| x.0.total_cmp(&y.0).then(x.1.cmp(&y.1))); for (_, v) in order { let origin = self.particles[v as usize].rest_position; - if let Some(fan) = self.plane_fan(v, origin, normal) { - if self.opens_without_confetti(v, &fan) && self.split_fan(v, &fan, log) { + if let Some(fan) = self.plane_fan(v, origin, normal, log.cell_index.as_ref()) { + if self.opens_without_confetti(v, &fan, log.cell_index.as_ref()) + && self.split_fan(v, &fan, log) + { return true; } } diff --git a/src/dynamics/soft_body/tearing/tearing_cut.rs b/src/dynamics/soft_body/tearing/tearing_cut.rs index 1fa3ff963..ff8e32af2 100644 --- a/src/dynamics/soft_body/tearing/tearing_cut.rs +++ b/src/dynamics/soft_body/tearing/tearing_cut.rs @@ -122,7 +122,7 @@ impl SoftBody { blade: &[Vector; DIM], log: &mut SplitLog, ) -> bool { - let mut fan = self.fan(kind, v); + let mut fan = self.fan(kind, v, log.cell_index.as_ref()); if fan.elements.len() < 2 { return false; } diff --git a/src/dynamics/soft_body/tearing/tearing_particle_split.rs b/src/dynamics/soft_body/tearing/tearing_particle_split.rs index 7f53bcf37..8ecb7dd96 100644 --- a/src/dynamics/soft_body/tearing/tearing_particle_split.rs +++ b/src/dynamics/soft_body/tearing/tearing_particle_split.rs @@ -100,6 +100,9 @@ impl Fan { /// What the particle splits of a tear did. #[derive(Clone, Debug, Default)] pub(super) struct SplitLog { + /// Sorted cell incidence, kept only while a body of cells is being torn. Cell indices stay + /// stable during a tear; particle copies and rewired cells update these lists in place. + pub cell_index: Option, /// The particle copies, as `(copy, source)`, in creation order. pub split_particles: Vec<(u32, u32)>, /// The particle pairs of the non-measure edges removed for straddling an opened crack. @@ -109,6 +112,39 @@ pub(super) struct SplitLog { pub inserted: Vec<[u32; 4]>, } +#[derive(Clone, Debug)] +pub(super) struct CellIndex(Vec>); + +impl CellIndex { + pub(super) fn new(body: &SoftBody) -> Option { + let mut cells = vec![Vec::new(); body.particles.len()]; + for (i, cell) in body.cells.iter().enumerate() { + for (k, &v) in cell.vertices.iter().enumerate() { + // The local facet lookup assumes a simplex with distinct vertices. Preserve + // the scanning path for degenerate cells accepted by the builder. + if cell.vertices[..k].contains(&v) { + return None; + } + cells[v as usize].push(i as u32); + } + } + Some(Self(cells)) + } + + fn at(&self, v: u32) -> &[u32] { + self.0.get(v as usize).map_or(&[], Vec::as_slice) + } + + fn move_cell(&mut self, cell: u32, from: u32, to: u32) { + let source = &mut self.0[from as usize]; + let position = source.binary_search(&cell).unwrap(); + source.remove(position); + let target = &mut self.0[to as usize]; + let position = target.binary_search(&cell).unwrap_err(); + target.insert(position, cell); + } +} + /// Replaces every occurrence of `from` in `vertices` by `to`. fn replace(vertices: &mut [u32], from: u32, to: u32) { for x in vertices.iter_mut() { @@ -164,6 +200,30 @@ impl SoftBody { } } + /// Visits the elements at one particle in element-index order. Cuts and non-cell bodies + /// keep the scanning path; tears use the local incidence lists instead of scanning the body. + fn for_each_measure_element_at( + &self, + kind: MeasureKind, + v: u32, + cell_index: Option<&CellIndex>, + mut f: impl FnMut(u32, &[u32]), + ) { + if kind == MeasureKind::Cells { + if let Some(index) = cell_index { + for &i in index.at(v) { + f(i, &self.cells[i as usize].vertices); + } + return; + } + } + self.for_each_measure_element(kind, |i, vertices| { + if vertices.contains(&v) { + f(i, vertices); + } + }); + } + /// The total rest measure of this body's measure elements, by priority: the rest area (2D) or /// volume (3D) of its cells, else (3D) of its surface triangles, else the rest length of its /// structural edges, before plastic flow; `0.0` without any, and no tear or cut changes it. @@ -271,15 +331,30 @@ impl SoftBody { found } + pub(super) fn measure_element_holds_indexed( + &self, + particles: &[u32], + cell_index: Option<&CellIndex>, + ) -> bool { + if !self.cells.is_empty() { + if let (Some(index), Some(&v)) = (cell_index, particles.first()) { + return index.at(v).iter().any(|&c| { + particles + .iter() + .all(|p| self.cells[c as usize].vertices.contains(p)) + }); + } + } + self.measure_element_holds(particles) + } + /// The fan of `v`: the measure elements of the given kind containing it, in one group. - pub(super) fn fan(&self, kind: MeasureKind, v: u32) -> Fan { + pub(super) fn fan(&self, kind: MeasureKind, v: u32, cell_index: Option<&CellIndex>) -> Fan { let mut elements = Vec::new(); let mut vertices = Vec::new(); - self.for_each_measure_element(kind, |i, element| { - if element.contains(&v) { - elements.push(i); - vertices.push(element.to_vec()); - } + self.for_each_measure_element_at(kind, v, cell_index, |i, element| { + elements.push(i); + vertices.push(element.to_vec()); }); let n = elements.len(); Fan { @@ -304,7 +379,7 @@ impl SoftBody { return; }; for &v in candidates { - let mut fan = self.fan(kind, v); + let mut fan = self.fan(kind, v, log.cell_index.as_ref()); if fan.elements.len() < 2 { continue; } @@ -318,13 +393,19 @@ impl SoftBody { /// The fan of `v` split by the plane through `origin` with normal `normal`, in the rest /// shape: every element goes to the side of its rest centroid, and the groups are the /// connected components within a side. `None` when the fan lies on one side only. - pub(super) fn plane_fan(&self, v: u32, origin: Vector, normal: Vector) -> Option { + pub(super) fn plane_fan( + &self, + v: u32, + origin: Vector, + normal: Vector, + cell_index: Option<&CellIndex>, + ) -> Option { // A pinned particle is never split: the crack must open elsewhere. if self.particles[v as usize].inv_mass == 0.0 { return None; } let kind = self.measure_kind()?; - let mut fan = self.fan(kind, v); + let mut fan = self.fan(kind, v, cell_index); let rest = |i: u32| self.particles[i as usize].rest_position; for (side, vertices) in fan.sides.iter_mut().zip(&fan.vertices) { let offset: Vector = vertices.iter().map(|&w| rest(w) - origin).sum(); @@ -349,25 +430,31 @@ impl SoftBody { /// Whether the split of `v` given by `fan` leaves every group at least [`Self::min_piece`] /// measure elements reachable without passing through `v` (no chips). Tears consult it, cuts /// do not. - pub(super) fn opens_without_confetti(&self, v: u32, fan: &Fan) -> bool { + pub(super) fn opens_without_confetti( + &self, + v: u32, + fan: &Fan, + cell_index: Option<&CellIndex>, + ) -> bool { let min = self.min_piece(fan.kind); (0..fan.num_groups).all(|g| { let seeds: Vec = (0..fan.elements.len()) .filter(|&i| fan.groups[i] == g) .map(|i| fan.elements[i]) .collect(); - self.reachable_elements(fan.kind, &seeds, v, min) >= min + self.reachable_elements(fan.kind, &seeds, v, min, cell_index) >= min }) } /// Number of measure elements of the given kind reachable from `seeds` through shared facets /// not containing `pivot`, counting up to `limit`. - fn reachable_elements( + pub(super) fn reachable_elements( &self, kind: MeasureKind, seeds: &[u32], pivot: u32, limit: usize, + cell_index: Option<&CellIndex>, ) -> usize { // Calls `f` with every facet of an element not containing `pivot`: its vertices but one, // sorted and padded with `u32::MAX`. @@ -387,15 +474,19 @@ impl SoftBody { } } } - // Facet -> elements map of the whole body (a tear is a rare event). + let cell_index = cell_index.filter(|_| kind == MeasureKind::Cells); + // Non-cell bodies and cuts use the facet map. For an indexed tear, a facet's neighbors + // are the cells incident to its first vertex that also contain all its other vertices. let mut by_facet: HashMap<[u32; 3], Vec> = HashMap::default(); let mut elements: HashMap> = HashMap::default(); - self.for_each_measure_element(kind, |i, vertices| { - elements.insert(i, vertices.to_vec()); - facets(vertices, pivot, |key| { - by_facet.entry(key).or_default().push(i) + if cell_index.is_none() { + self.for_each_measure_element(kind, |i, vertices| { + elements.insert(i, vertices.to_vec()); + facets(vertices, pivot, |key| { + by_facet.entry(key).or_default().push(i) + }); }); - }); + } let mut seen: HashMap = HashMap::default(); let mut stack: Vec = seeds.to_vec(); for &s in seeds { @@ -405,14 +496,31 @@ impl SoftBody { if seen.len() >= limit { return seen.len(); } - facets(&elements[&e], pivot, |key| { - if let Some(neighbors) = by_facet.get(&key) { - for &n in neighbors { - if !seen.contains_key(&n) { - seen.insert(n, ()); - stack.push(n); + let vertices = if cell_index.is_some() { + self.cells[e as usize].vertices.as_slice() + } else { + elements[&e].as_slice() + }; + facets(vertices, pivot, |key| { + let mut visit = |n: u32| { + if let parry::utils::hashmap::Entry::Vacant(entry) = seen.entry(n) { + entry.insert(()); + stack.push(n); + } + }; + if let Some(index) = cell_index { + for &n in index.at(key[0]) { + if key[..DIM] + .iter() + .all(|w| self.cells[n as usize].vertices.contains(w)) + { + visit(n); } } + } else if let Some(neighbors) = by_facet.get(&key) { + for &n in neighbors { + visit(n); + } } }); } @@ -464,10 +572,16 @@ impl SoftBody { } /// Whether some measure element of the given kind contains both `x` and `y`. - fn share_measure_element(&self, kind: MeasureKind, x: u32, y: u32) -> bool { + fn share_measure_element( + &self, + kind: MeasureKind, + x: u32, + y: u32, + cell_index: Option<&CellIndex>, + ) -> bool { let mut found = false; - self.for_each_measure_element(kind, |_, vertices| { - found |= vertices.contains(&x) && vertices.contains(&y); + self.for_each_measure_element_at(kind, x, cell_index, |_, vertices| { + found |= vertices.contains(&y); }); found } @@ -510,6 +624,9 @@ impl SoftBody { let copy = self.particles.len() as u32 - 1; log.split_particles.push((copy, v)); copies.push(copy); + if let Some(index) = &mut log.cell_index { + index.0.push(Vec::new()); + } } } @@ -548,6 +665,11 @@ impl SoftBody { MeasureKind::Segments => &mut self.edges[e as usize].vertices, }; replace(target, v, copies[g]); + if kind == MeasureKind::Cells { + if let Some(index) = &mut log.cell_index { + index.move_cell(e, v, copies[g]); + } + } } // The other edges at `v`. One shared by fan elements of several groups (the crack ends @@ -593,7 +715,7 @@ impl SoftBody { continue; }; if gx.iter().all(|g| gy.binary_search(g).is_err()) - && !self.share_measure_element(kind, x, y) + && !self.share_measure_element(kind, x, y, log.cell_index.as_ref()) { straddling[ei] = true; log.removed_edges.push(e.vertices); diff --git a/src/dynamics/soft_body/tearing/tests.rs b/src/dynamics/soft_body/tearing/tests.rs index 63fb961ee..5acac8942 100644 --- a/src/dynamics/soft_body/tearing/tests.rs +++ b/src/dynamics/soft_body/tearing/tests.rs @@ -3,7 +3,274 @@ use crate::alloc_prelude::*; use crate::prelude::*; -use super::tearing_particle_split::{MeasureKind, SplitLog}; +use super::tearing_particle_split::{CellIndex, MeasureKind, SplitLog}; + +/// Incidence stays sorted and complete when a particle is copied more than once and the cells +/// around it move to different copies. Compare the lookup and bounded BFS to the scanning path. +#[test] +fn cell_index_matches_scans_after_splits() { + #[cfg(feature = "dim2")] + let builder = SoftBodyBuilder::grid(Vector::ZERO, Vector::splat(1.0), 5, 4); + #[cfg(feature = "dim3")] + let builder = SoftBodyBuilder::cuboid(Vector::ZERO, Vector::splat(1.0), 3, 3, 3); + let (mut world, handle) = world_with(builder.particle_mass(0.5)); + let body = world.soft_bodies.get_mut(handle).unwrap(); + let mut scanned = body.clone(); + let mut scanned_log = SplitLog::default(); + let mut log = SplitLog { + cell_index: CellIndex::new(body), + ..SplitLog::default() + }; + + fn check(body: &SoftBody, index: &CellIndex) { + for v in 0..body.num_particles() as u32 + 1 { + let actual = body.fan(MeasureKind::Cells, v, Some(index)); + let expected = body.fan(MeasureKind::Cells, v, None); + assert_eq!(actual.elements, expected.elements); + assert_eq!(actual.vertices, expected.vertices); + assert_eq!(actual.measures, expected.measures); + assert_eq!(actual.groups, expected.groups); + assert_eq!(actual.num_groups, expected.num_groups); + } + for (c, cell) in body.cells.iter().enumerate() { + for &pivot in cell.vertices.iter().chain(core::iter::once(&u32::MAX)) { + for limit in [ + 0, + 1, + body.min_piece(MeasureKind::Cells), + body.cells.len() + 1, + ] { + for seeds in [ + &[][..], + &[c as u32][..], + &[c as u32, c as u32][..], + &[c as u32, ((c + 1) % body.cells.len()) as u32][..], + ] { + let actual = body.reachable_elements( + MeasureKind::Cells, + seeds, + pivot, + limit, + Some(index), + ); + let expected = + body.reachable_elements(MeasureKind::Cells, seeds, pivot, limit, None); + assert_eq!(actual, expected); + } + } + } + for particles in [cell.vertices.as_slice(), &cell.vertices[..2], &[][..]] { + assert_eq!( + body.measure_element_holds_indexed(particles, Some(index)), + body.measure_element_holds(particles), + ); + } + } + assert!(!body.measure_element_holds_indexed(&[u32::MAX], Some(index))); + } + + check(body, log.cell_index.as_ref().unwrap()); + let original_particles = body.num_particles(); + for v in 0..original_particles as u32 { + let mut fan = body.fan(MeasureKind::Cells, v, log.cell_index.as_ref()); + if fan.elements.len() < 2 { + continue; + } + // Alternating sides also exercises splits producing more than two groups. + for (i, side) in fan.sides.iter_mut().enumerate() { + *side = i % 2; + } + fan.assign_groups(v); + assert!(body.split_fan(v, &fan, &mut log)); + assert!(scanned.split_fan(v, &fan, &mut scanned_log)); + assert_eq!(log.split_particles, scanned_log.split_particles); + assert_eq!(log.removed_edges, scanned_log.removed_edges); + assert_eq!( + std::format!( + "{:?}", + (&body.particles, &body.cells, &body.edges, &body.boundary) + ), + std::format!( + "{:?}", + ( + &scanned.particles, + &scanned.cells, + &scanned.edges, + &scanned.boundary + ) + ), + ); + check(body, log.cell_index.as_ref().unwrap()); + } + assert!(log.split_particles.len() > 2); + body.remove_straddlers_across_pieces(&mut log); + body.finish_topology_change(&log); + body.validate_topology().unwrap(); +} + +/// The builder accepts cells with repeated vertices. Their facets are multisets, not the +/// simplices the incidence lookup requires, so they must retain the original scanning path. +#[test] +fn repeated_cell_vertices_keep_the_scanning_path() { + #[cfg(feature = "dim2")] + let (positions, cells) = (vec![Vector::ZERO, Vector::X], vec![[0, 1, 1]]); + #[cfg(feature = "dim3")] + let (positions, cells) = (vec![Vector::ZERO, Vector::X, Vector::Y], vec![[0, 1, 2, 2]]); + let (world, handle) = world_with( + SoftBodyBuilder::new(positions) + .cells(cells) + .cell_model(SoftBodyCellModel::Corotational) + .no_surface_collider(), + ); + let body = &world.soft_bodies[handle]; + assert!(CellIndex::new(body).is_none()); + assert_eq!(body.fan(MeasureKind::Cells, 1, None).elements, vec![0]); +} + +/// A tear's scratch incidence must not become serialized state or survive into another tear. +#[cfg(feature = "serde-serialize")] +#[test] +fn cell_tearing_matches_after_snapshot_restore() { + #[cfg(feature = "dim2")] + let builder = SoftBodyBuilder::grid(Vector::ZERO, Vector::splat(1.0), 5, 4); + #[cfg(feature = "dim3")] + let builder = SoftBodyBuilder::cuboid(Vector::ZERO, Vector::splat(1.0), 3, 3, 3); + let (mut world, handle) = world_with(builder.particle_mass(0.5)); + let body = world.soft_bodies.get_mut(handle).unwrap(); + let mut event = SoftBodyTearEvent::default(); + assert!(body.tear_topology(&[], &[body.cells.len() as u32 / 2], &mut event)); + let bytes = bincode::serialize(body).unwrap(); + let mut restored: SoftBody = bincode::deserialize(&bytes).unwrap(); + let cells: Vec = (0..body.cells.len() as u32).collect(); + for _ in 0..3 { + let mut expected = SoftBodyTearEvent::default(); + let mut actual = SoftBodyTearEvent::default(); + assert_eq!( + body.tear_topology(&[], &cells, &mut expected), + restored.tear_topology(&[], &cells, &mut actual), + ); + assert_eq!(std::format!("{actual:?}"), std::format!("{expected:?}")); + assert_eq!( + bincode::serialize(&restored).unwrap(), + bincode::serialize(body).unwrap() + ); + restored.validate_topology().unwrap(); + } +} + +/// A repeatable public-API benchmark; timing assertions do not belong in the normal test suite. +#[cfg(feature = "std")] +#[test] +#[ignore] +fn cell_tearing_benchmark() { + use std::format; + use std::hash::{DefaultHasher, Hash, Hasher}; + use std::time::Instant; + + #[cfg(feature = "dim2")] + let sizes = [(10, 7, 1), (25, 12, 1), (45, 18, 1)]; + #[cfg(feature = "dim3")] + let sizes = [(3, 3, 3), (5, 4, 4), (7, 6, 5)]; + for (nx, ny, nz) in sizes { + #[cfg(feature = "dim2")] + let builder = SoftBodyBuilder::grid(Vector::ZERO, Vector::new(1.5, 0.6), nx, ny); + #[cfg(feature = "dim3")] + let builder = SoftBodyBuilder::cuboid(Vector::ZERO, Vector::splat(1.0), nx, ny, nz); + let _ = nz; + let builder = builder + .particle_mass(0.004) + .cell_model(SoftBodyCellModel::Corotational) + .surface_collider(ColliderBuilder::ball(0.05)); + let (template, handle) = world_with(builder.clone()); + let body = &template.soft_bodies[handle]; + let total_cells = body.cells().len(); + for pattern in ["none", "single", "band", "all"] { + let cells: Vec = body + .cells() + .iter() + .enumerate() + .filter(|(i, c)| { + let x = c + .vertices + .iter() + .map(|&v| body.particle_position(v as usize).x) + .sum::() + / (DIM + 1) as Real; + match pattern { + "none" => false, + "single" => *i == total_cells / 2, + "band" => x.abs() < 0.15, + _ => true, + } + }) + .map(|(i, _)| i as u32) + .collect(); + let mut samples = Vec::new(); + let mut fingerprint = None; + let mut counts = (0, 0); + for _ in 0..7 { + let (mut world, handle) = world_with(builder.clone()); + let start = Instant::now(); + let event = world.tear_soft_body(handle, &[], &cells); + samples.push(start.elapsed().as_secs_f64() * 1000.0); + let bodies = family(&world, handle); + counts = ( + event.as_ref().map_or(0, |e| e.torn_cells.len()), + bodies.len(), + ); + let mut hash = DefaultHasher::new(); + format!("{event:?}").hash(&mut hash); + let mut mass = 0.0; + let mut measure = 0.0; + for &piece in &bodies { + let sb = &world.soft_bodies[piece]; + sb.validate_topology().unwrap(); + mass += sb.mass(); + measure += sb.rest_measure(); + format!("{:?}", (&sb.particles, &sb.cells, &sb.edges, &sb.boundary)) + .hash(&mut hash); + } + let conserved = + |a: Real, b: Real| (a - b).abs() <= 1.0e-4 * a.abs().max(b.abs()).max(1.0); + assert!( + conserved(mass, body.mass()), + "mass: {mass} vs {}", + body.mass() + ); + assert!( + conserved(measure, body.rest_measure()), + "measure: {measure} vs {}", + body.rest_measure() + ); + // Exercise the rebuilt colliders and solver after the tear, outside the timing. + for _ in 0..3 { + world.step(); + } + for &piece in &bodies { + let sb = &world.soft_bodies[piece]; + for p in sb.particles() { + assert!(p.position.is_finite() && p.velocity.is_finite()); + } + format!("{:?}", sb.particles()).hash(&mut hash); + } + let value = hash.finish(); + if let Some(expected) = fingerprint { + assert_eq!(value, expected, "non-deterministic benchmark fixture"); + } + fingerprint = Some(value); + } + samples.sort_by(f64::total_cmp); + std::println!( + "TEARING dim={DIM} cells={total_cells} pattern={pattern} requested={} torn={} pieces={} median_ms={:.6} fingerprint={:016x}", + cells.len(), + counts.0, + counts.1, + samples[3], + fingerprint.unwrap() + ); + } + } +} /// Every structural edge of a rope, then every edge and cell of a grid (2D) or a box (3D), torn /// over and over: the bodies come apart, but no tear splits off a piece smaller than the minimum @@ -250,7 +517,7 @@ fn split_chain_at_its_middle_particle() { let origin = sb.particles[2].rest_position; let normal = sb.particles[3].rest_position - origin; - let fan = sb.plane_fan(2, origin, normal).unwrap(); + let fan = sb.plane_fan(2, origin, normal, None).unwrap(); assert_eq!(fan.elements, vec![1, 2]); assert_eq!(fan.groups, vec![0, 1]); let mut log = SplitLog::default(); @@ -301,7 +568,9 @@ fn split_kite_across_its_diagonal() { let measure = sb.rest_measure(); let origin = sb.particles[0].rest_position; - let fan = sb.plane_fan(0, origin, Vector::new(1.0, -1.0)).unwrap(); + let fan = sb + .plane_fan(0, origin, Vector::new(1.0, -1.0), None) + .unwrap(); assert_eq!(fan.elements, vec![0, 1]); assert_eq!(fan.sides, vec![1, 0]); assert_eq!(fan.groups, vec![1, 0]); @@ -366,7 +635,7 @@ fn split_tetrahedra_across_their_shared_face() { let measure = sb.rest_measure(); let origin = sb.particles[0].rest_position; - let fan = sb.plane_fan(0, origin, Vector::Z).unwrap(); + let fan = sb.plane_fan(0, origin, Vector::Z, None).unwrap(); assert_eq!(fan.sides, vec![1, 0]); assert_eq!(fan.groups, vec![1, 0]); let mut log = SplitLog::default(); @@ -439,8 +708,8 @@ fn split_cloth_quad_across_its_diagonal() { let origin = sb.particles[0].rest_position; let normal = Vector::new(1.0, 0.0, -1.0); - let fan = sb.plane_fan(0, origin, normal).unwrap(); - assert!(!sb.opens_without_confetti(0, &fan)); + let fan = sb.plane_fan(0, origin, normal, None).unwrap(); + assert!(!sb.opens_without_confetti(0, &fan, None)); assert_eq!(fan.sides, vec![1, 0]); assert_eq!(fan.groups, vec![1, 0]); let mut log = SplitLog::default();