use super::*;
#[must_use]
pub fn hz_to_millihz(hz: f64) -> u32 {
if !hz.is_finite() || hz <= 0.0 {
return 0;
}
(hz * HZ_MILLIHZ_SCALE).round().clamp(0.0, u32::MAX as f64) as u32
}
#[must_use]
pub(crate) fn sorted_percentile_f64(sorted: &[f64], percentile: f64) -> f64 {
if sorted.is_empty() {
return 0.0;
}
let clamped: f64 = percentile.clamp(0.0, 1.0);
let max_idx: usize = sorted.len().saturating_sub(1);
let idx: usize = ((clamped * (max_idx as f64)).ceil() as usize).min(max_idx);
sorted[idx]
}
#[must_use]
pub fn compute_candidate_composite_cost_ms(score: &CandidateScore) -> f64 {
let missed_penalty: f64 = score.get_missed_frame_ratio().max(0.0) * SCORE_MISSED_WEIGHT_MS;
let p95_term: f64 = score.get_p95_frame_ms().max(0.0) * SCORE_P95_WEIGHT;
let p99_term: f64 = score.get_p99_frame_ms().max(0.0) * SCORE_P99_WEIGHT;
let input_term: f64 = score.get_input_to_present_ms().max(0.0) * SCORE_INPUT_WEIGHT;
missed_penalty + p95_term + p99_term + input_term
}