Skip to content

Commit

Permalink
Fix NaN in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Sep 4, 2024
1 parent 946115e commit 5139b51
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/trigger/progress/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ impl ProgressActive {

/// Returns the current progress between `0.0` and `1.0`.
pub fn progress(&self, now: u32) -> Option<f32> {
self.current(now)
.map(|current| current as f32 / self.max() as f32)
self.current(now).map(|current| {
match (current, self.max()) {
(0, 0) => 0.0, // treat 0/0 as 0% progress
(_, 0) => 1.0, // treat x/0 as 100% progress
(current, max) => current as f32 / max as f32,
}
})
}

/// Returns the current progress between `0.0` and `1.0`.
Expand Down

0 comments on commit 5139b51

Please sign in to comment.