SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Preferences: Z up orientation figure is drawn right-handed (#5680) (#5741)
rlartot77c77829e329
diff --git a/crates/ui-egui/src/ui_kit/preferences_figures.rs b/crates/ui-egui/src/ui_kit/preferences_figures.rsindex ef46340ee7..bb68d703bc 100644--- a/crates/ui-egui/src/ui_kit/preferences_figures.rs+++ b/crates/ui-egui/src/ui_kit/preferences_figures.rs@@ -121,6 +121,17 @@ pub(crate) fn paint_orbit(p: &Painter, rect: Rect, pivot: usize) {}}+/// Axis tips of the orientation figure on its 120 x 100 canvas, as `(x, y, triad index, label)`,+/// drawn from the centre `(60, 48)`. Z up has X toward the viewer on the right and Y away on the+/// right, as the view's axis gizmo draws them (#5680).+fn orientation_axes(y_up: bool) -> [(f32, f32, usize, &'static str); 3] {+ if y_up {+ [(94.0, 65.0, 0, "X"), (60.0, 13.0, 1, "Y"), (26.0, 65.0, 2, "Z")]+ } else {+ [(94.0, 65.0, 0, "X"), (94.0, 31.0, 1, "Y"), (60.0, 13.0, 2, "Z")]+ }+}+/// Orientation uses the same 30-degree ground plane as the model cards, with unmistakable/// axis arrows and readable labels rather than an unrelated generic cube.pub(crate) fn paint_orientation(p: &Painter, rect: Rect, y_up: bool) {@@ -131,12 +142,7 @@ pub(crate) fn paint_orientation(p: &Painter, rect: Rect, y_up: bool) {let ground = [c.at(60.0, 32.0), c.at(97.0, 50.5), c.at(60.0, 69.0), c.at(23.0, 50.5)];face(&p, ground, t.form_dim.gamma_multiply(0.035));p.add(Shape::closed_line(ground.to_vec(), Stroke::new(c.width(0.8), t.form_dim.gamma_multiply(0.20))));- let axes = if y_up {- [(94.0, 65.0, 0, "X"), (60.0, 13.0, 1, "Y"), (26.0, 65.0, 2, "Z")]- } else {- [(94.0, 65.0, 0, "X"), (26.0, 65.0, 1, "Y"), (60.0, 13.0, 2, "Z")]- };- for (x, y, index, label) in axes {+ for (x, y, index, label) in orientation_axes(y_up) {let colour = t.triad.get(index).copied().unwrap_or(t.form_ink);let end = c.at(x, y);// A halo keeps every shaft distinct from the subtle ground and the other axes.@@ -251,3 +257,26 @@ pub(crate) fn paint_layout(ui: &mut egui::Ui, state: super::preferences::LayoutPcrate::scenario::publish_rect("prefs:layout_preview", outer);super::text(ui, crate::i18n::tr("prefs.preview_choices"), super::Text::Note("preview"));}++#[cfg(test)]+mod tests {+ use super::orientation_axes;++ /// Both orientation figures draw right-handed axes (#5680): seen from above, the turn from X+ /// to Y and from Y to Z is counter-clockwise on screen (negative cross product, as the canvas y+ /// axis points down), the way the view's axis gizmo draws them. (Z to X is not tested: with Z+ /// up, Y points away from the viewer and that turn is clockwise.)+ #[test]+ fn orientation_figures_are_right_handed() {+ for y_up in [false, true] {+ let axes = orientation_axes(y_up);+ let v: Vec<(f32, f32)> = axes.iter().map(|(x, y, _, _)| (x - 60.0, y - 48.0)).collect();+ assert_eq!(axes.map(|a| a.3), ["X", "Y", "Z"]);+ for i in 0..2 {+ let (a, b) = (v[i], v[i + 1]);+ let cross = a.0 * b.1 - a.1 * b.0;+ assert!(cross < 0.0, "y_up {y_up}: {} to {} turns clockwise (mirrored figure)", axes[i].3, axes[i + 1].3);+ }+ }+ }+}