explain the remaining float conversions at their use sites
This commit is contained in:
@@ -351,9 +351,15 @@ pub(crate) fn codec_availability(ffmpeg: &Path) -> CodecAvailability {
|
||||
}
|
||||
|
||||
fn video_bitrate_kbps(req: &TranscodeRequest) -> Result<u64> {
|
||||
// Byte and bitrate budgets are far below 2^53, so f64 represents them
|
||||
// exactly; these casts are the only way to get u64 into the f64 maths.
|
||||
#[allow(
|
||||
clippy::cast_precision_loss,
|
||||
reason = "target sizes and bitrates are many orders of magnitude below f64's exact-integer range"
|
||||
)]
|
||||
let target_bits = (req.target_bytes as f64) * 8.0 * 0.95;
|
||||
let audio_bits = if req.keep_audio {
|
||||
AUDIO_BITRATE_KBPS as f64 * 1000.0 * req.duration_secs
|
||||
(AUDIO_BITRATE_KBPS as f64) * 1000.0 * req.duration_secs
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
@@ -1417,7 +1423,7 @@ mod tests {
|
||||
#[test]
|
||||
fn click_filters_capped_at_max() {
|
||||
let clicks: Vec<Click> = (0..100)
|
||||
.map(|i| Click { time_secs: i as f64, x: i, y: i, button: crate::clicks::MouseButton::Left })
|
||||
.map(|i| Click { time_secs: f64::from(i), x: i, y: i, button: crate::clicks::MouseButton::Left })
|
||||
.collect();
|
||||
let filter = click_filters(&clicks, 1920, 1080).unwrap();
|
||||
let count = filter.matches("drawbox").count();
|
||||
@@ -1484,7 +1490,7 @@ mod tests {
|
||||
#[test]
|
||||
fn gif_color_factor_matches_comment_values() {
|
||||
// comment claims: 256=1.0x, 128=~0.71x, 64=0.5x, 32=~0.35x, 16=0.25x
|
||||
let cf = |colors: u16| (colors as f64 / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
let cf = |colors: u16| (f64::from(colors) / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
assert!((cf(256) - 1.0).abs() < 1e-9);
|
||||
assert!((cf(128) - 2f64.sqrt() / 2.0).abs() < 1e-9); // ~0.707
|
||||
assert!((cf(64) - 0.5).abs() < 1e-9);
|
||||
|
||||
Reference in New Issue
Block a user