mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 10:56:51 -06:00
List binary fractions in the Units precision drop-down for Architectural and Fractional (#1861) (#1952)
This commit is contained in:
@@ -235,6 +235,17 @@ fn pick(ui: &mut egui::Ui, salt: &str, value: &mut i64, options: &[(i64, String)
|
||||
});
|
||||
}
|
||||
|
||||
/// Length precision choices for a LUNITS format. Architectural (4) and Fractional (5) step through
|
||||
/// binary fractions of an inch (LUPREC n is 1/2^n, 0 is whole inches); the other formats show a decimal sample.
|
||||
fn length_precisions(lunits: i64) -> Vec<(i64, String)> {
|
||||
use cadcraft_engine::units::format_distance;
|
||||
if matches!(lunits, 4 | 5) {
|
||||
(0..=8).map(|p| (p, if p == 0 { "1\"".to_string() } else { format!("1/{}\"", 1i64 << p) })).collect()
|
||||
} else {
|
||||
(0..=8).map(|p| (p, format_distance(1.5, lunits, p))).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Drawing Units (UNITS): edits a copy of LUNITS/LUPREC/AUNITS/AUPREC/INSUNITS and applies it
|
||||
/// through the `units` command on OK.
|
||||
fn units(app: &mut CadApp, ctx: &egui::Context, open: &mut bool) {
|
||||
@@ -260,7 +271,7 @@ fn units(app: &mut CadApp, ctx: &egui::Context, open: &mut bool) {
|
||||
pick(ui, "units_lunits", lu, &types(&LENGTH_TYPES));
|
||||
ui.end_row();
|
||||
ui.label("Precision");
|
||||
pick(ui, "units_luprec", lp, &(0..=8).map(|p| (p, format_distance(1.5, *lu, p))).collect::<Vec<_>>());
|
||||
pick(ui, "units_luprec", lp, &length_precisions(*lu));
|
||||
ui.end_row();
|
||||
ui.strong("Angle");
|
||||
ui.end_row();
|
||||
@@ -433,6 +444,15 @@ mod tests {
|
||||
|
||||
use crate::{CadApp, Services};
|
||||
|
||||
#[test]
|
||||
fn fractional_length_precisions_list_binary_fractions() {
|
||||
let labels = ["1\"", "1/2\"", "1/4\"", "1/8\"", "1/16\"", "1/32\"", "1/64\"", "1/128\"", "1/256\""];
|
||||
let want: Vec<(i64, String)> = labels.iter().enumerate().map(|(k, l)| (k as i64, l.to_string())).collect();
|
||||
assert_eq!(super::length_precisions(4), want);
|
||||
assert_eq!(super::length_precisions(5), want);
|
||||
assert_eq!(super::length_precisions(2).len(), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picking_a_block_starts_insert_with_its_name() {
|
||||
let mut app = CadApp::new(Session::new(), Services::default());
|
||||
|
||||
Reference in New Issue
Block a user