(sorted: &[f64], p: f64)
| 55 | } |
| 56 | |
| 57 | fn percentile(sorted: &[f64], p: f64) -> f64 { |
| 58 | if sorted.is_empty() { |
| 59 | return 0.0; |
| 60 | } |
| 61 | let idx = (p / 100.0) * (sorted.len() as f64 - 1.0); |
| 62 | let lo = idx.floor() as usize; |
| 63 | let hi = (lo + 1).min(sorted.len() - 1); |
| 64 | let frac = idx - lo as f64; |
| 65 | sorted[lo] * (1.0 - frac) + sorted[hi] * frac |
| 66 | } |
| 67 | |
| 68 | /// `slot_width` is the per-group horizontal slice; `box_width` is the rendered |
| 69 | /// box width within the slot, narrowed when grouped so adjacent boxes don't touch. |