From 5139b514d43f5e01c9a95e4b58f09ca047cfc39a Mon Sep 17 00:00:00 2001 From: Zerthox Date: Wed, 4 Sep 2024 14:54:37 +0200 Subject: [PATCH] Fix NaN in progress --- src/trigger/progress/active.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/trigger/progress/active.rs b/src/trigger/progress/active.rs index e55ccc0..b1d494b 100644 --- a/src/trigger/progress/active.rs +++ b/src/trigger/progress/active.rs @@ -30,8 +30,13 @@ impl ProgressActive { /// Returns the current progress between `0.0` and `1.0`. pub fn progress(&self, now: u32) -> Option { - 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`.