mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-16 00:10:38 +08:00
lib: Fix panic in table progress calculation
This commit is contained in:
@@ -208,16 +208,16 @@ impl<A> Table<A> {
|
||||
let len = len as f64;
|
||||
|
||||
let lines = page_size + step.saturating_sub(page_size as usize) as f64;
|
||||
let progress = (lines / len * 100_f64).ceil() as usize;
|
||||
let progress = (lines / len * 100.0).ceil();
|
||||
|
||||
if progress > 97 {
|
||||
Self::map_range((0, progress), (0, 100), progress)
|
||||
if progress > 97.0 {
|
||||
Self::map_range((0.0, progress), (0.0, 100.0), progress) as usize
|
||||
} else {
|
||||
progress
|
||||
progress as usize
|
||||
}
|
||||
}
|
||||
|
||||
fn map_range(from: (usize, usize), to: (usize, usize), value: usize) -> usize {
|
||||
fn map_range(from: (f64, f64), to: (f64, f64), value: f64) -> f64 {
|
||||
to.0 + (value - from.0) * (to.1 - to.0) / (from.1 - from.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user