Wave 339/509: Sketch: a sketch's bounds reach its circles' and arcs' extremes (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- 43c1b7b88 jyviko: UI tests: Isocurve Analysis's engine colour is drawn from the theme's accent
- 7bb5bb3d5 jyviko: Locales: Arabic and Hebrew for the version and section hatch labels
- e657e4086 jyviko: UI kit gallery: entries for the controls added without one
- 6a6cd8f56 jyviko: Sketch: a sketch's bounds reach its circles' and arcs' extremes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-28 22:27:39 -04:00
parent 74a97586a8
commit aba58faeff
6 changed files with 91 additions and 5 deletions
@@ -1,7 +1,13 @@
{
"ar": {
"help.version": "الإصدار {version}"
},
"en": {
"help.version": "Version {version}"
},
"he": {
"help.version": "גרסה {version}"
},
"ja": {
"help.version": "バージョン {version}"
},
@@ -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": "部品ごと",
+22 -2
View File
@@ -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))
}
}
+16
View File
@@ -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:?}");
}
+4 -3
View File
@@ -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..];
+33
View File
@@ -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"));
}),