Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Box window: a picked point fills Corner and Center in the design's unit (#12051) (#12052)

Danielad56dd6a938e
diff --git a/crates/ui-egui/src/primitive_placement.rs b/crates/ui-egui/src/primitive_placement.rs
index c09fbf603c..4fa37488c7 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<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;
}
diff --git a/crates/ui-egui/src/primitive_units_tests.rs b/crates/ui-egui/src/primitive_units_tests.rs
index 89802635d9..755cbbeaff 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");