forked from 1b-agent/opencadstudio-upstream
Fix Architectural and Engineering inch unit formatting
Suppress leading 0 feet notation when feet = 0 in architectural (LUNITS 4) and engineering (LUNITS 3) formats. Values less than one foot should display as inches only (e.g. 9 1/4 inches instead of 0 feet 9 1/4 inches). - For Architectural: 9.25 inches now displays as 9 1/4 inch mark instead of 0 feet 9 1/4 inch mark - For Engineering: 11.94 now displays as 11.9 inch mark instead of 0 feet 11.9 inch mark - Proper feet notation is preserved for values >= 1 foot - Updated tests to reflect correct expected values Fixes issue 1066 Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
92ac3f60e5
commit
6616111fbf
1 file changed
+9
-3
@@ -142,7 +142,13 @@ pub fn format_length(value: f64) -> String {
|
||||
};
|
||||
let unit_suffix = if ctx.lunits == 4 { "\"" } else { "" };
|
||||
match feet {
|
||||
Some(f) => format!("{}{:.0}'-{:.0}{}{}", sign, f, whole, frac_str, unit_suffix),
|
||||
Some(f) => {
|
||||
if f == 0.0 && whole > 0.0 {
|
||||
format!("{}{:.0}{}{}", sign, whole, frac_str, unit_suffix)
|
||||
} else {
|
||||
format!("{}{:.0}'-{:.0}{}{}", sign, f, whole, frac_str, unit_suffix)
|
||||
}
|
||||
}
|
||||
None => format!("{}{:.0}{}", sign, whole, frac_str),
|
||||
}
|
||||
}
|
||||
@@ -1102,7 +1108,7 @@ mod length_format_tests {
|
||||
|
||||
#[test]
|
||||
fn architectural_carries_into_feet() {
|
||||
assert_eq!(with_units(4, 4, 11.99), "0'-11 63/64\"");
|
||||
assert_eq!(with_units(4, 4, 11.99), "11 63/64\"");
|
||||
assert_eq!(with_units(4, 4, 11.999), "1'-0\"");
|
||||
assert_eq!(with_units(4, 4, 23.999), "2'-0\"");
|
||||
assert_eq!(with_units(4, 4, 66.5), "5'-6 1/2\"");
|
||||
@@ -1111,7 +1117,7 @@ mod length_format_tests {
|
||||
|
||||
#[test]
|
||||
fn engineering_carries_into_feet() {
|
||||
assert_eq!(with_units(3, 1, 11.94), "0'-11.9\"");
|
||||
assert_eq!(with_units(3, 1, 11.94), "11.9\"");
|
||||
assert_eq!(with_units(3, 1, 11.99), "1'-0.0\"");
|
||||
assert_eq!(with_units(3, 1, 23.99), "2'-0.0\"");
|
||||
assert_eq!(with_units(3, 2, 11.999), "1'-0.00\"");
|
||||
|
||||
Reference in new issue
Block a user