Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Fix File Info showing 1/1 s for exposures just under one second

NetterSilverff2db1b83b49
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index 2299aa3e4..2cf3ce6fb 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -765,7 +765,7 @@ fn exposure_text(t: f64) -> Option<String> {
return None;
}
let r = 1.0 / t;
- if t < 1.0 && (r - r.round()).abs() <= r * 0.01 {
+ if t < 1.0 && r.round() > 1.0 && (r - r.round()).abs() <= r * 0.01 {
return Some(format!("1/{} s", r.round()));
}
Some(format!("{} s", short_num(t, if t < 1.0 { 2 } else { 1 })))
diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rs
index b07c64985..d00719b2b 100644
--- a/crates/engine/src/file_cmds/tests.rs
+++ b/crates/engine/src/file_cmds/tests.rs
@@ -1354,3 +1354,10 @@ fn batch_naming_rejects_outputs_that_replace_inputs_before_processing() {
assert_eq!(std::fs::read(&first).unwrap(), before[0]);
assert_eq!(std::fs::read(&second).unwrap(), before[1]);
}
+
+#[test]
+fn exposure_text_near_one_second_is_not_one_over_one() {
+ assert_eq!(exposure_text(0.996).as_deref(), Some("1 s"));
+ assert_eq!(exposure_text(0.99).as_deref(), Some("0.99 s"));
+ assert_eq!(exposure_text(1.0 / 250.0).as_deref(), Some("1/250 s"));
+}