Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dynamics/island_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl IslandManager {
}

pub(crate) fn num_islands(&self) -> usize {
self.active_islands.len() - 1
self.active_islands.len().saturating_sub(1)
}

/// Update this data-structure after one or multiple rigid-bodies have been removed for `bodies`.
Expand Down Expand Up @@ -244,8 +244,8 @@ impl IslandManager {
self.active_islands.clear();
self.active_islands.push(0);

// The max avoid underflow when the stack is empty.
let mut island_marker = self.stack.len().max(1) - 1;
// saturating_sub(1) prevents underflow when the stack is empty.
let mut island_marker = self.stack.len().saturating_sub(1);

// NOTE: islands containing a body with non-standard number of iterations won’t
// be merged with another island, unless another island with standard
Expand Down
3 changes: 2 additions & 1 deletion src/dynamics/solver/interaction_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ impl ParallelInteractionGroups {
let range = self.groups[i]..self.groups[i + 1];
&self.sorted_interactions[range]
}

pub fn num_groups(&self) -> usize {
self.groups.len() - 1
self.groups.len().saturating_sub(1)
}

pub fn group_interactions<Interaction: PairInteraction>(
Expand Down