mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Fix "-0p0" for tiny negative pica/cicero values
Found while testing crates/geom/src/units.rs:276 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
15a2f3c8c8
commit
9887272efb
@@ -286,6 +286,8 @@ pub fn format_measure_prec(pt: f64, unit: Unit, decimals: usize) -> String {
|
||||
whole += 1.0;
|
||||
rest = 0.0;
|
||||
}
|
||||
// Decide the sign from the rounded value so float noise doesn't print "-0p0".
|
||||
let neg = neg && (whole > 0.0 || rest > 0.0);
|
||||
let sep = if unit == Unit::Picas { 'p' } else { 'c' };
|
||||
format!("{}{}{}{}", if neg { "-" } else { "" }, whole as i64, sep, trim(rest))
|
||||
}
|
||||
@@ -304,6 +306,14 @@ mod tests {
|
||||
(a - b).abs() < 1e-6
|
||||
}
|
||||
|
||||
/// Tiny negatives that round to zero must not print a sign.
|
||||
#[test]
|
||||
fn tiny_negative_picas_ciceros_have_no_sign() {
|
||||
assert_eq!(format_measure(-0.0004, Unit::Picas), "0p0");
|
||||
assert_eq!(format_measure(-0.0004, Unit::Ciceros), "0c0");
|
||||
assert_eq!(format_measure(-12.0, Unit::Picas), "-1p0");
|
||||
}
|
||||
|
||||
/// Inches show four decimals, as InDesign's fields do; other units three.
|
||||
#[test]
|
||||
fn inches_show_four_decimals() {
|
||||
|
||||
Reference in New Issue
Block a user