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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel
2026-11-04 21:40:17 +00:00
committed by GitHub
parent cafe015ef9
commit ad56dd6a93
2 changed files with 55 additions and 4 deletions
+6 -4
View File
@@ -101,12 +101,14 @@ pub(crate) fn rows(ui: &mut egui::Ui, s: &Session, cmd: &str, extra: &mut Map<St
enter
}
/// A coordinate of a picked point as a field shows it, in millimetres.
fn mm(v: f64) -> 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<Vec3>
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;
}
@@ -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");