SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 339/509: Sketch: a sketch's bounds reach its circles' and arcs' extremes (and 3 more)
jyvikoaba58faeffe2
diff --git a/assets/locales/pending/help-menu-version.json b/assets/locales/pending/help-menu-version.jsonindex 41c8d34fda..ef569008af 100644--- a/assets/locales/pending/help-menu-version.json+++ b/assets/locales/pending/help-menu-version.json@@ -1,7 +1,13 @@{+ "ar": {+ "help.version": "الإصدار {version}"+ },"en": {"help.version": "Version {version}"},+ "he": {+ "help.version": "גרסה {version}"+ },"ja": {"help.version": "バージョン {version}"},diff --git a/assets/locales/pending/section-hatch-by-part.json b/assets/locales/pending/section-hatch-by-part.jsonindex 85c32ee634..240a79979d 100644--- a/assets/locales/pending/section-hatch-by-part.json+++ b/assets/locales/pending/section-hatch-by-part.json@@ -1,9 +1,19 @@{+ "ar": {+ "prefs.section_hatch": "تهشير المقطع",+ "prefs.section_hatch_by_part": "حسب الجزء",+ "prefs.section_hatch_one": "نمط واحد"+ },"en": {"prefs.section_hatch": "Section hatch","prefs.section_hatch_by_part": "By part","prefs.section_hatch_one": "One style"},+ "he": {+ "prefs.section_hatch": "קווקוו חתך",+ "prefs.section_hatch_by_part": "לפי חלק",+ "prefs.section_hatch_one": "סגנון אחד"+ },"ja": {"prefs.section_hatch": "断面ハッチング","prefs.section_hatch_by_part": "部品ごと",diff --git a/crates/sketch/src/model.rs b/crates/sketch/src/model.rsindex d426826c45..29190e515d 100644--- a/crates/sketch/src/model.rs+++ b/crates/sketch/src/model.rs@@ -1716,9 +1716,29 @@ impl Sketch {}}- /// Axis-aligned bounds of all geometry (for views).+ /// Axis-aligned bounds of all geometry (for views). An arc's are exact: its polyline's points+ /// need not reach the circle's extremes (a whole circle is one arc, whose chords start at its+ /// start angle), so the quarter points it sweeps through are added.pub fn bounds(&self) -> Option<(Vec2, Vec2)> {- let b: Aabb2 = (0..self.curves.len()).flat_map(|i| self.segs(i)).flat_map(|s| s.polyline(0.5)).collect();+ let extremes = |s: &Seg2| -> Vec<Vec2> {+ let Seg2::Arc { center, radius, start, sweep } = *s else { return Vec::new() };+ let (lo, hi) = if sweep >= 0.0 { (start, start + sweep) } else { (start + sweep, start) };+ let quarter = std::f64::consts::FRAC_PI_2;+ let first = (lo / quarter).ceil() as i64;+ let last = (hi / quarter).floor() as i64;+ if !(lo.is_finite() && hi.is_finite()) || last - first > 4 {+ return Vec::new();+ }+ (first..=last).map(|k| center + Vec2::from_angle(k as f64 * quarter) * radius).collect()+ };+ let b: Aabb2 = (0..self.curves.len())+ .flat_map(|i| self.segs(i))+ .flat_map(|s| {+ let mut pts = s.polyline(0.5);+ pts.extend(extremes(&s));+ pts+ })+ .collect();(!b.is_empty()).then_some((b.min, b.max))}}diff --git a/crates/sketch/src/tests.rs b/crates/sketch/src/tests.rsindex 29a58496ed..1e5e61f093 100644--- a/crates/sketch/src/tests.rs+++ b/crates/sketch/src/tests.rs@@ -1279,3 +1279,19 @@ fn a_fillet_folded_through_flat_is_refused_like_a_fold() {}assert!(refused.is_some_and(|s| (7..=9).contains(&s)), "refused at {refused:?}");}++/// A sketch's bounds reach a circle's and an arc's extremes, not only the points of their+/// polylines: a whole circle is one arc whose chords start at its start angle, and a circle of+/// radius 5 at (-300, 0) spans x from -305 exactly.+#[test]+fn bounds_reach_the_extremes_of_circles_and_arcs() {+ let mut sk = Sketch::new();+ sk.add_circle(v(-300.0, 0.0), 5.0, None, None).unwrap();+ let (lo, hi) = sk.bounds().unwrap();+ assert!(lo.dist(v(-305.0, -5.0)) < 1e-9 && hi.dist(v(-295.0, 5.0)) < 1e-9, "{lo:?} {hi:?}");+ // A quarter arc from (10, 0) to (0, 10) about the origin: its corners, no more.+ let mut sk = Sketch::new();+ sk.add_arc(v(0.0, 0.0), v(10.0, 0.0), v(0.0, 10.0), [None; 3], None).unwrap();+ let (lo, hi) = sk.bounds().unwrap();+ assert!(lo.dist(v(0.0, 0.0)) < 1e-9 && hi.dist(v(10.0, 10.0)) < 1e-9, "{lo:?} {hi:?}");+}diff --git a/crates/ui-egui/src/colour_tokens_tests.rs b/crates/ui-egui/src/colour_tokens_tests.rsindex fe4343871b..f315fe1971 100644--- a/crates/ui-egui/src/colour_tokens_tests.rs+++ b/crates/ui-egui/src/colour_tokens_tests.rs@@ -274,9 +274,10 @@ fn every_engine_colour_tag_is_placed() {"AXIS_Y","AXIS_Z",];- // Bodies, edges, profiles, the grid and the background: the GPU viewport draws these from- // their own tokens; the engine's values are only the headless snapshot's.- const NEUTRAL: &[&str] = &["BODY", "BODY_SELECTED", "EDGE", "PROFILE", "GRID", "GRID_MAJOR", "BG_TOP", "BG_BOTTOM", "SECTION_CAP"];+ // Bodies, edges, profiles, the grid, the background and Isocurve Analysis curves (the accent):+ // the GPU viewport draws these from their own tokens; the engine's values are only the+ // headless snapshot's.+ const NEUTRAL: &[&str] = &["BODY", "BODY_SELECTED", "EDGE", "PROFILE", "GRID", "GRID_MAJOR", "BG_TOP", "BG_BOTTOM", "SECTION_CAP", "ISOCURVE"];let src = include_str!("../../engine/src/view.rs");let start = src.find("pub mod colors {").unwrap_or(0);let block = &src[start..];diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rsindex faa4ea9363..396ebf9b0a 100644--- a/crates/ui-egui/src/ui_kit/gallery.rs+++ b/crates/ui-egui/src/ui_kit/gallery.rs@@ -3,6 +3,7 @@ use super::*;use crate::ui_kit::{Container, Surface};use crate::{scenario, theme::Tokens};use egui::{Ui, vec2};+use solidcraft_engine::kernel::Continuity;struct Sample {value: String,@@ -839,6 +840,35 @@ const ELEMENTS: &[Element] = &[hint_field(ui, &mut s.value, "Length");});}),+ element!("checked_field", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, s| {+ row(ui, "Gallery", |ui| {+ checked_field(ui, &mut s.value, "Length", s.checked);+ });+ }),+ element!("checked_row", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, s| {+ checked_row(ui, "Gallery", &mut s.value, "Length", Some("Too small"));+ }),+ element!("warning_caption", "dialog:caption:Gallery", None, |ui, _| {+ warning_caption(ui, "Gallery", "Too small");+ }),+ element!("text_field_tip", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, s| {+ row(ui, "Gallery", |ui| {+ text_field_tip(ui, &mut s.value, "Name", "What it is called");+ });+ }),+ element!("continuity_row", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, _| {+ let mut order = Continuity::G1;+ continuity_row(ui, "Gallery", "gallery_continuity", &mut order, &[Continuity::G0, Continuity::G1, Continuity::G2]);+ }),+ element!("continuity_row_explained", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, _| {+ let mut order = Continuity::G2;+ let allowed = [Continuity::G1, Continuity::G2];+ continuity_row_explained(ui, "Gallery", "gallery_continuity", &mut order, &allowed, &continuity_tip(&allowed));+ }),+ element!("continuity_tip", "dialog:row:Gallery", None, |ui, _| {+ let tip = continuity_tip(&[Continuity::G0, Continuity::G1]);+ row(ui, "Gallery", |ui| ui.label(tip));+ }),element!("text_field", "dialog:row:Gallery", Some("dialog:Gallery"), |ui, s| {row(ui, "Gallery", |ui| {text_field(ui, &mut s.value, "Name");@@ -1021,6 +1051,9 @@ const ELEMENTS: &[Element] = &[element!("progress", "dialog:progress:gallery", None, |ui, _| {progress(ui, "gallery", 0.4);}),+ element!("steps", "dialog:step:gallery:0:done", None, |ui, _| {+ steps(ui, "gallery", &["Read", "Mesh", "Show"], 1, Some("40%"));+ }),element!("hint", "dialog:hint:gallery", Some("dialog:hint:gallery"), |ui, _| {text(ui, "Pick a point", Text::Hint("gallery"));}),