From ad56dd6a938e75db72a866e7606835d7d97fa4b2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 21:40:17 +0000 Subject: [PATCH] Box window: a picked point fills Corner and Center in the design's unit (#12051) (#12052) * Box window: a picked point fills Corner and Center in the design's unit A vertex, edge or face picked into the Box window's Point input wrote its X, Y and Z as millimetre text whatever the design's length unit was, so an inch design showed "50.8 mm" where the other fields read inches. The fields now take the point through length_input::model, as Move and the Hole references do, so they read "2 in" there and stay "50.8 mm" in a millimetre design. The same applies to the Sphere and Torus centre. Co-Authored-By: Claude Opus 5.5 * Box window: a picked point reads to a millionth of the design's unit length_input::model divides without rounding, so a vertex at 38.1 mm read "1.5000000000000002 in" in an inch design. length_input::shown rounds to a millionth of the design's unit, as the millimetre text did before, and the test pins that case. Co-Authored-By: Claude Opus 5.5 * Box window: a picked point keeps the micrometre in every design unit length_input::shown rounds to a millionth of the design's unit, and the picked point's text is what OK sends, so in a metre design a vertex could move by up to half a millimetre. Document::design_length keeps the micrometre in every unit and still writes 38.1 mm as "1.5 in". The test now covers a metre design with a point that is not round in mm, and the Sphere and Torus centre. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/primitive_placement.rs | 10 +++-- crates/ui-egui/src/primitive_units_tests.rs | 49 +++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/primitive_placement.rs b/crates/ui-egui/src/primitive_placement.rs index c09fbf603..4fa37488c 100644 --- a/crates/ui-egui/src/primitive_placement.rs +++ b/crates/ui-egui/src/primitive_placement.rs @@ -101,12 +101,14 @@ pub(crate) fn rows(ui: &mut egui::Ui, s: &Session, cmd: &str, extra: &mut Map String { +/// A coordinate of a picked point (mm) as a field shows it and OK sends it: in the design's +/// length unit, kept to the micrometre in every unit, so a vertex at 38.1 mm reads "1.5 in", not +/// "1.5000000000000002 in", and one in a metre design does not move by a rounded millimetre. +fn coord(s: &Session, v: f64) -> String { let v = (v * 1e6).round() / 1e6; // No "-0 mm". let v = if v == 0.0 { 0.0 } else { v }; - format!("{v} mm") + s.doc.design_length(v).1 } /// Where a pick is in the world: a vertex, or a point on an edge or face, where it was picked; a @@ -132,7 +134,7 @@ pub(crate) fn picked(s: &Session, cmd: &str, at: &mut Option<(Vec3, Option return; } let Some((index, _)) = current(s, cmd, extra) else { return }; - store(cmd, extra, index, &[mm(point.x), mm(point.y), mm(point.z)]); + store(cmd, extra, index, &[coord(s, point.x), coord(s, point.y), coord(s, point.z)]); *at = None; } diff --git a/crates/ui-egui/src/primitive_units_tests.rs b/crates/ui-egui/src/primitive_units_tests.rs index 89802635d..755cbbeaf 100644 --- a/crates/ui-egui/src/primitive_units_tests.rs +++ b/crates/ui-egui/src/primitive_units_tests.rs @@ -620,6 +620,55 @@ fn a_point_picked_in_the_box_dialog_becomes_its_corner_or_centre() { assert_near(made[1].0, [-10.0, -10.0, -10.0]); } +#[test] +fn a_point_picked_in_the_box_dialog_reads_in_the_design_unit() { + use solidcore_record::Vec3; + use solidcraft_engine::Sel; + let mut h = design("in"); + h.app.preferences.auto_operation = false; + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20, "body_name": "Base"})).unwrap(); + h.frames(2); + h.app.start("solid.box"); + h.frames(3); + let mut d = h.app.dialog.take().unwrap(); + d.pick(&h.app.session, Sel::Face { body: "Base".into(), index: 0, point: Vec3::new(25.4, 38.1, 12.7) }); + h.app.dialog = Some(d); + h.frames(2); + // 38.1 / 25.4 is 1.5000000000000002 in floating point: the field reads 1.5 in. + assert_shown(&h, &[("X", "1 in".into()), ("Y", "1.5 in".into()), ("Z", "0.5 in".into())]); + assert_eq!(sent(&h)["corner"], json!(["1 in", "1.5 in", "0.5 in"])); + ok(&mut h); + assert_near(bounds(&mut h.app.session)[1].0, [25.4, 38.1, 12.7]); + // The Sphere and Torus centre take the point the same way. + for cmd in ["solid.sphere", "solid.torus"] { + h.app.start(cmd); + h.frames(3); + let mut d = h.app.dialog.take().unwrap(); + d.pick(&h.app.session, Sel::Vertex { body: "Base".into(), point: Vec3::new(25.4, 38.1, 12.7) }); + h.app.dialog = Some(d); + h.frames(2); + assert_shown(&h, &[("X", "1 in".into()), ("Y", "1.5 in".into()), ("Z", "0.5 in".into())]); + assert_eq!(sent(&h)["center"], json!(["1 in", "1.5 in", "0.5 in"]), "{cmd}"); + h.app.dialog = None; + } + // In a metre design the text keeps the micrometre: a point that is not round in mm lands + // where it was picked, not rounded to a millionth of a metre (a millimetre). + let mut h = design("m"); + h.app.preferences.auto_operation = false; + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20, "body_name": "Base"})).unwrap(); + h.frames(2); + h.app.start("solid.box"); + h.frames(3); + let at = [12.345678, -23.456789, 5.000123]; + let mut d = h.app.dialog.take().unwrap(); + d.pick(&h.app.session, Sel::Face { body: "Base".into(), index: 0, point: Vec3::new(at[0], at[1], at[2]) }); + h.app.dialog = Some(d); + h.frames(2); + assert_eq!(sent(&h)["corner"], json!(["0.012345678 m", "-0.023456789 m", "0.005000123 m"])); + ok(&mut h); + assert_near(bounds(&mut h.app.session)[1].0, at); +} + #[test] fn the_sphere_torus_and_cone_dialogs_take_their_placement() { let mut h = design("mm");