mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
13bbf0eefe
commit
8ef5337c29
1 file changed
+14
-5
@@ -30,14 +30,12 @@ impl MeasurementScale {
|
||||
}
|
||||
/// Photoshop's "Scale" column text, e.g. `1 pixels = 1.0000 pixels`.
|
||||
pub fn describe(&self) -> String {
|
||||
format!("{} pixels = {:.4} {}", trim(self.pixel_length), self.logical_length, self.units)
|
||||
// f64 Display already drops a whole number's `.0` (`5`, `0.5`) and, unlike an i64 cast,
|
||||
// prints lengths past i64::MAX in full.
|
||||
format!("{} pixels = {:.4} {}", self.pixel_length, self.logical_length, self.units)
|
||||
}
|
||||
}
|
||||
|
||||
fn trim(v: f64) -> String {
|
||||
if v.fract() == 0.0 { format!("{}", v as i64) } else { format!("{v}") }
|
||||
}
|
||||
|
||||
/// One Count tool group: its numbered markers (document pixel coordinates, in click order).
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
@@ -133,6 +131,17 @@ mod tests {
|
||||
assert_eq!(MeasurementScale { pixel_length: 0.0, ..Default::default() }.factor(), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scale_text_prints_large_and_fractional_pixel_lengths() {
|
||||
let big = MeasurementScale { pixel_length: 1e20, logical_length: 1.0, units: "mm".into() };
|
||||
assert_eq!(big.describe(), "100000000000000000000 pixels = 1.0000 mm");
|
||||
assert_eq!(MeasurementScale::default().describe(), "1 pixels = 1.0000 pixels");
|
||||
let s = |p: f64| MeasurementScale { pixel_length: p, ..Default::default() }.describe();
|
||||
assert_eq!(s(5.0), "5 pixels = 1.0000 pixels");
|
||||
assert_eq!(s(0.5), "0.5 pixels = 1.0000 pixels");
|
||||
assert_eq!(s(12.25), "12.25 pixels = 1.0000 pixels");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serde_defaults_fill_missing_fields() {
|
||||
let m: Measurement = serde_json::from_str("{}").unwrap();
|
||||
|
||||
Reference in new issue
Block a user