Wave 272/509: Fillet dialog: plain words for continuity, Corners with Setback out of Advanced (and 2 more)
3 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. -4f6f254d0jyviko: smlib: a setback left open is a profiler span like every other SMLib call -676919d4djyviko: tess: a face no method plans is filled leniently in (u, v), and named in the stats -1acbe2806jyviko: Fillet dialog: plain words for continuity, Corners with Setback out of Advanced Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
1 parent
0968a2a42d
commit
cf8ad08ec3
9 files changed
+575
-63
No files matched your search
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"en": {
|
||||
"ui.fillet_corner_ball": "Ball",
|
||||
"ui.fillet_corner_ball_tip": "A piece of the rolling ball's sphere, tangent (G1) to each round.",
|
||||
"ui.fillet_corner_needs_constant": "Smooth patch corners (G2) need Constant radius and Exact fit.",
|
||||
"ui.fillet_corner_patch": "Smooth patch",
|
||||
"ui.fillet_corner_patch_tip": "Curvature-continuous (G2): the corner is set back along each edge and filled with a patch, so reflections run through it without a kink.",
|
||||
"ui.fillet_fit_needs_constant": "Radius fit needs Constant radius.",
|
||||
"ui.fillet_setback": "Setback",
|
||||
"ui.fillet_setback_hint": "{factor} × radius",
|
||||
"ui.fillet_setback_tip": "How far along each edge from the corner the patch starts. Empty: {factor} × the radius.",
|
||||
"ui.fillet_smooth_radius": "Smooth radius change",
|
||||
"ui.fillet_type_curvature": "Curvature continuous",
|
||||
"ui.fillet_type_tip": "The section across the edge. Curvature continuous: a curvature-continuous (G2) section between planar faces, so reflections run from the faces into the round without a kink."
|
||||
},
|
||||
"ar": {
|
||||
"ui.fillet_corner_ball": "كرة",
|
||||
"ui.fillet_corner_ball_tip": "جزء من سطح الكرة المتدحرجة، مماسّ (G1) لكل تقويس.",
|
||||
"ui.fillet_corner_needs_constant": "زوايا الرقعة الناعمة (G2) تتطلب نصف قطر ثابتًا وملاءمة دقيقة لنصف القطر.",
|
||||
"ui.fillet_corner_patch": "رقعة ناعمة",
|
||||
"ui.fillet_corner_patch_tip": "متصل الانحناء (G2): تُرجَع الزاوية على طول كل حافة وتُملأ برقعة، فتمر الانعكاسات عبرها دون انكسار.",
|
||||
"ui.fillet_fit_needs_constant": "ملاءمة نصف القطر تتطلب نصف قطر ثابتًا.",
|
||||
"ui.fillet_setback": "مسافة الإرجاع",
|
||||
"ui.fillet_setback_hint": "{factor} × نصف القطر",
|
||||
"ui.fillet_setback_tip": "المسافة على طول كل حافة من الزاوية التي تبدأ عندها الرقعة. فارغ: {factor} ضعف نصف القطر.",
|
||||
"ui.fillet_smooth_radius": "تغيّر ناعم لنصف القطر",
|
||||
"ui.fillet_type_curvature": "متصل الانحناء",
|
||||
"ui.fillet_type_tip": "المقطع عبر الحافة. متصل الانحناء: مقطع متصل الانحناء (G2) بين وجوه مستوية، فتمر الانعكاسات من الوجوه إلى التقويس دون انكسار."
|
||||
},
|
||||
"de": {
|
||||
"ui.fillet_corner_ball": "Kugel",
|
||||
"ui.fillet_corner_ball_tip": "Ein Stück der Kugel des rollenden Balls, tangential (G1) zu jeder Rundung.",
|
||||
"ui.fillet_corner_needs_constant": "Ecken mit glattem Flächenstück (G2) brauchen einen konstanten Radius und exakte Radiusanpassung.",
|
||||
"ui.fillet_corner_patch": "Glattes Flächenstück",
|
||||
"ui.fillet_corner_patch_tip": "Krümmungsstetig (G2): Die Ecke wird entlang jeder Kante zurückgesetzt und mit einem Flächenstück gefüllt, sodass Spiegelungen ohne Knick hindurchlaufen.",
|
||||
"ui.fillet_fit_needs_constant": "Radiusanpassung braucht einen konstanten Radius.",
|
||||
"ui.fillet_setback": "Rücksprung",
|
||||
"ui.fillet_setback_hint": "{factor} × Radius",
|
||||
"ui.fillet_setback_tip": "Wie weit von der Ecke entlang jeder Kante das Flächenstück beginnt. Leer: {factor} × der Radius.",
|
||||
"ui.fillet_smooth_radius": "Radius glatt ändern",
|
||||
"ui.fillet_type_curvature": "Krümmungsstetig",
|
||||
"ui.fillet_type_tip": "Der Querschnitt über die Kante. Krümmungsstetig: ein krümmungsstetiger Querschnitt (G2) zwischen ebenen Flächen, sodass Spiegelungen ohne Knick von den Flächen in die Rundung laufen."
|
||||
},
|
||||
"he": {
|
||||
"ui.fillet_corner_ball": "כדור",
|
||||
"ui.fillet_corner_ball_tip": "חלק מספירת הכדור המתגלגל, משיק (G1) לכל עיגול.",
|
||||
"ui.fillet_corner_needs_constant": "פינות עם טלאי חלק (G2) דורשות רדיוס קבוע והתאמת רדיוס מדויקת.",
|
||||
"ui.fillet_corner_patch": "טלאי חלק",
|
||||
"ui.fillet_corner_patch_tip": "רציף בעקמומיות (G2): הפינה נסוגה לאורך כל קצה ומתמלאת בטלאי, כך שההשתקפויות עוברות בה בלי שבר.",
|
||||
"ui.fillet_fit_needs_constant": "התאמת רדיוס דורשת רדיוס קבוע.",
|
||||
"ui.fillet_setback": "נסיגה",
|
||||
"ui.fillet_setback_hint": "{factor} × רדיוס",
|
||||
"ui.fillet_setback_tip": "המרחק לאורך כל קצה מהפינה שבו הטלאי מתחיל. ריק: פי {factor} מהרדיוס.",
|
||||
"ui.fillet_smooth_radius": "שינוי רדיוס חלק",
|
||||
"ui.fillet_type_curvature": "רציף בעקמומיות",
|
||||
"ui.fillet_type_tip": "החתך לרוחב הקצה. רציף בעקמומיות: חתך רציף בעקמומיות (G2) בין פאות מישוריות, כך שההשתקפויות עוברות מהפאות אל העיגול בלי שבר."
|
||||
},
|
||||
"ja": {
|
||||
"ui.fillet_corner_ball": "ボール",
|
||||
"ui.fillet_corner_ball_tip": "転がるボールの球面の一部で、各フィレットに接します (G1)。",
|
||||
"ui.fillet_corner_needs_constant": "スムーズパッチのコーナー (G2) には、一定の半径と厳密な半径フィットが必要です。",
|
||||
"ui.fillet_corner_patch": "スムーズパッチ",
|
||||
"ui.fillet_corner_patch_tip": "曲率連続 (G2): コーナーを各エッジに沿って後退させてパッチで埋め、映り込みが折れずに通ります。",
|
||||
"ui.fillet_fit_needs_constant": "半径フィットには一定の半径が必要です。",
|
||||
"ui.fillet_setback": "セットバック",
|
||||
"ui.fillet_setback_hint": "{factor} × 半径",
|
||||
"ui.fillet_setback_tip": "パッチが始まる、コーナーから各エッジに沿った距離。空欄のときは半径の {factor} 倍。",
|
||||
"ui.fillet_smooth_radius": "半径をなめらかに変化",
|
||||
"ui.fillet_type_curvature": "曲率連続",
|
||||
"ui.fillet_type_tip": "エッジを横切る断面。曲率連続: 平面の間の曲率連続 (G2) 断面で、映り込みが面からフィレットへ折れずにつながります。"
|
||||
},
|
||||
"ko": {
|
||||
"ui.fillet_corner_ball": "볼",
|
||||
"ui.fillet_corner_ball_tip": "굴러가는 볼의 구면 일부로, 각 라운드에 접합니다(G1).",
|
||||
"ui.fillet_corner_needs_constant": "부드러운 패치 코너(G2)에는 일정한 반지름과 정확한 반지름 맞춤이 필요합니다.",
|
||||
"ui.fillet_corner_patch": "부드러운 패치",
|
||||
"ui.fillet_corner_patch_tip": "곡률 연속(G2): 코너를 각 모서리를 따라 물려 패치로 채우므로, 반사가 꺾임 없이 지나갑니다.",
|
||||
"ui.fillet_fit_needs_constant": "반지름 맞춤에는 일정한 반지름이 필요합니다.",
|
||||
"ui.fillet_setback": "셋백",
|
||||
"ui.fillet_setback_hint": "{factor} × 반지름",
|
||||
"ui.fillet_setback_tip": "패치가 시작되는, 코너에서 각 모서리를 따른 거리. 비워 두면 반지름의 {factor}배.",
|
||||
"ui.fillet_smooth_radius": "반지름 부드럽게 변화",
|
||||
"ui.fillet_type_curvature": "곡률 연속",
|
||||
"ui.fillet_type_tip": "모서리를 가로지르는 단면. 곡률 연속: 평면 사이의 곡률 연속(G2) 단면으로, 반사가 면에서 라운드로 꺾임 없이 이어집니다."
|
||||
},
|
||||
"zh": {
|
||||
"ui.fillet_corner_ball": "球面",
|
||||
"ui.fillet_corner_ball_tip": "滚球球面的一部分,与每个圆角相切 (G1)。",
|
||||
"ui.fillet_corner_needs_constant": "平滑曲面片角点 (G2) 需要恒定半径和精确的半径拟合。",
|
||||
"ui.fillet_corner_patch": "平滑曲面片",
|
||||
"ui.fillet_corner_patch_tip": "曲率连续 (G2):角点沿每条边后退,并用曲面片填充,反射穿过时没有折痕。",
|
||||
"ui.fillet_fit_needs_constant": "半径拟合需要恒定半径。",
|
||||
"ui.fillet_setback": "后退距离",
|
||||
"ui.fillet_setback_hint": "{factor} × 半径",
|
||||
"ui.fillet_setback_tip": "曲面片从角点沿每条边开始的距离。留空:半径的 {factor} 倍。",
|
||||
"ui.fillet_smooth_radius": "半径平滑变化",
|
||||
"ui.fillet_type_curvature": "曲率连续",
|
||||
"ui.fillet_type_tip": "横跨边的截面。曲率连续:平面之间的曲率连续 (G2) 截面,反射从面平滑过渡到圆角,没有折痕。"
|
||||
}
|
||||
}
|
||||
@@ -950,7 +950,13 @@ impl Body {
|
||||
return Err(KernelError::Invalid("a mesh body has no surfaces to mesh".into()));
|
||||
}
|
||||
let (tol, turn) = t.rules(self.size());
|
||||
guard("mesh", || crate::tess::plan(&self.record, tol, turn).map(|(plan, _)| plan))
|
||||
let (plan, stats) = guard("mesh", || crate::tess::plan(&self.record, tol, turn))?;
|
||||
// A face filled leniently has no hole on screen, but its pcurves or seams are still wrong:
|
||||
// it is reported, never silent.
|
||||
for f in &stats.lenient {
|
||||
log::warn!("display plan: face {} filled leniently in (u, v), a defect in its pcurves or seams: {}", f.face, f.reason);
|
||||
}
|
||||
Ok(plan)
|
||||
}
|
||||
|
||||
/// The mesh of `plan`, a plan [`Body::mesh_plan`] made of this body: what [`Body::mesh`]
|
||||
|
||||
@@ -50,6 +50,10 @@ pub(crate) struct Fill<'a> {
|
||||
/// varies: a plane is shaded the same by any triangles, so planar faces skip it (around many
|
||||
/// small holes it grades out from each rim and multiplies the triangles).
|
||||
pub shape: bool,
|
||||
/// A side crossing one already kept is left out instead of refusing the loops: the last
|
||||
/// resort for a face whose boundary crosses itself in (u, v), so the display has no hole
|
||||
/// (the planner names the face in its stats as a defect upstream).
|
||||
pub lenient: bool,
|
||||
}
|
||||
|
||||
/// Triangulate the region bounded by `loops` (ranges of `boundary`, each closed). Boundary
|
||||
@@ -83,6 +87,9 @@ pub(crate) fn triangulate(boundary: &[[f64; 2]], loops: &[std::ops::Range<usize>
|
||||
continue;
|
||||
}
|
||||
if !cdt.can_add_constraint(a, b) {
|
||||
if fill.lenient {
|
||||
continue;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
cdt.add_constraint(a, b);
|
||||
@@ -476,7 +483,7 @@ mod tests {
|
||||
for refine in [false, true] {
|
||||
let refine = refine.then_some((Sag { eval: &flat, tol: 1e-3, h: 0.1, turn: None, scale: [2.0, 1.0] }, 2000));
|
||||
let label = refine.is_some();
|
||||
let Some((extra, tris)) = triangulate(&b, &loops, Fill { seeds: &[[0.2, 0.2], [0.5, 0.5]], refine, shape: true }) else {
|
||||
let Some((extra, tris)) = triangulate(&b, &loops, Fill { seeds: &[[0.2, 0.2], [0.5, 0.5]], refine, shape: true, lenient: false }) else {
|
||||
panic!("meshes")
|
||||
};
|
||||
let mut uv = b.clone();
|
||||
@@ -496,10 +503,15 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crossing_loops_are_refused() {
|
||||
fn crossing_loops_are_refused_unless_lenient() {
|
||||
let b = [[0.0, 0.0], [1.0, 1.0], [1.0, 0.0], [0.0, 1.0]];
|
||||
let whole = std::slice::from_ref(&(0..4));
|
||||
assert!(triangulate(&b, whole, Fill { seeds: &[], refine: None, shape: false }).is_none());
|
||||
assert!(triangulate(&b, whole, Fill { seeds: &[], refine: None, shape: false, lenient: false }).is_none());
|
||||
// Lenient, the crossing side is left out and what the rest encloses is filled.
|
||||
let Some((_, tris)) = triangulate(&b, whole, Fill { seeds: &[], refine: None, shape: false, lenient: true }) else {
|
||||
panic!("a lenient fill")
|
||||
};
|
||||
assert!(!tris.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -523,7 +535,7 @@ mod tests {
|
||||
// A parameter that is zero in exact arithmetic, left at 1e-300 by projection.
|
||||
let b = [[1e-300, 0.0], [1.0, -1e-310], [1.0, 1.0], [0.0, 1.0]];
|
||||
let whole = std::slice::from_ref(&(0..4));
|
||||
let Some((extra, tris)) = triangulate(&b, whole, Fill { seeds: &[], refine: None, shape: false }) else { panic!("meshes") };
|
||||
let Some((extra, tris)) = triangulate(&b, whole, Fill { seeds: &[], refine: None, shape: false, lenient: false }) else { panic!("meshes") };
|
||||
assert!(extra.is_empty());
|
||||
assert_eq!(tris.len(), 2);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@
|
||||
//! 2. otherwise, the general method for every face: constrained Delaunay in the face's (u, v),
|
||||
//! with interior seeds and Ruppert refinement, every node then evaluated on the exact
|
||||
//! surface (and refined where a triangle sags off it);
|
||||
//! 3. a face even that refuses (its loops cross or do not close in (u, v), or wind round a
|
||||
//! seam or pole), or whose pcurves do not lie on its edges, is an error naming the face (and
|
||||
//! the edge) and why. Its cause is upstream, in the record's pcurves or seams, and is fixed
|
||||
//! there; there is no other mesher to fall back to.
|
||||
//! 3. a face even that refuses because its loops cross in (u, v) (a cusp, a sliver whose sides
|
||||
//! sag across each other) is still a defect upstream, in the record's pcurves or seams, and is
|
||||
//! named in the plan's stats ([`PlanStats::lenient`], with why it was refused) so it is
|
||||
//! reported and fixed there; it is filled leniently in (u, v) (the sides crossing one already
|
||||
//! kept are left out, see [`Lenient`]) so the display has no hole. A face that refuses even
|
||||
//! that (its loops do not close in (u, v), or wind round a seam or pole), or whose pcurves do
|
||||
//! not lie on its edges, is an error naming the face (and the edge) and why; there is no
|
||||
//! other mesher to fall back to.
|
||||
|
||||
pub(crate) mod cdt;
|
||||
pub(crate) mod collar;
|
||||
@@ -41,12 +45,33 @@ use solidcraft_geom::tess::{EvalSurface, FacePlan, TessPlan};
|
||||
|
||||
use crate::{KernelError, Result};
|
||||
|
||||
/// Whether [`plan_face`] may leave out of its constrained Delaunay the boundary sides that cross
|
||||
/// a side already kept, and not hold the triangles to every side: the last resort for a face
|
||||
/// that crosses itself in (u, v) (a cusp, a sliver whose sides sag across each other), so the
|
||||
/// display has no hole. Its points stay in (u, v), so a curved face is still drawn on its
|
||||
/// surface. Such a face is named in [`PlanStats::lenient`]: its pcurves or seams are wrong.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Lenient {
|
||||
No,
|
||||
Yes,
|
||||
}
|
||||
|
||||
/// How the faces of a plan were meshed.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct PlanStats {
|
||||
pub planar: usize,
|
||||
pub structured: usize,
|
||||
pub delaunay: usize,
|
||||
/// Faces every method refused, filled leniently in (u, v) (see [`Lenient`]) so the display
|
||||
/// has no hole: each still a defect upstream, in its pcurves or seams.
|
||||
pub lenient: Vec<LenientFace>,
|
||||
}
|
||||
|
||||
/// A face filled leniently: its index in the record and why the strict plan refused it.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LenientFace {
|
||||
pub face: usize,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
/// Curved faces from which their sizes are worked out on the worker pool.
|
||||
@@ -171,8 +196,7 @@ pub(crate) fn plan(b: &brep::Brep, tol: f64, turn: Option<size::Turn>) -> Result
|
||||
let (Some(face), Some(eval), Some(size), Some(fb)) = (faces.get(fi), evals.get(fi), sizes.get(fi), boundaries.get(fi)) else {
|
||||
return Err(unsupported(format!("face {fi}: missing")));
|
||||
};
|
||||
let mut stats = PlanStats::default();
|
||||
let fp = plan_face(fi, kind(face.parameters()), eval, &fb.loops, &rules, *size, &mut stats)?;
|
||||
let (fp, stats) = plan_or_fill(fi, kind(face.parameters()), eval, &fb.loops, &rules, *size)?;
|
||||
let fwd = forward.get(fi).copied().unwrap_or(true);
|
||||
let fp =
|
||||
FacePlan { flip: !fwd, triangles: if fwd { fp.triangles } else { fp.triangles.into_iter().map(|[a, b, c]| [a, c, b]).collect() }, ..fp };
|
||||
@@ -188,6 +212,7 @@ pub(crate) fn plan(b: &brep::Brep, tol: f64, turn: Option<size::Turn>) -> Result
|
||||
stats.planar += s.planar;
|
||||
stats.structured += s.structured;
|
||||
stats.delaunay += s.delaunay;
|
||||
stats.lenient.extend(s.lenient);
|
||||
}
|
||||
plan.edges = nodes.into_iter().map(|n| n.points).collect();
|
||||
plan.edge_faces = edge_faces.into_iter().map(|fs| fs.into_iter().map(|f| u32::try_from(f).unwrap_or(u32::MAX)).collect()).collect();
|
||||
@@ -564,8 +589,38 @@ fn holes_beside_outer(dom: &uv::Domain, loops: &mut [seam::Loop]) {
|
||||
}
|
||||
}
|
||||
|
||||
/// One face, planned by [`plan_face`]; a face it refuses because its loops cross in (u, v) is
|
||||
/// planned once more leniently (see [`Lenient`]) and named in the stats with the first refusal,
|
||||
/// so the defect upstream is still reported. When the lenient fill refuses too, the first
|
||||
/// refusal is the error.
|
||||
fn plan_or_fill(
|
||||
fi: usize,
|
||||
kind: &str,
|
||||
s: &EvalSurface,
|
||||
loops: &[seam::Loop],
|
||||
rules: &size::Rules,
|
||||
size: (f64, [f64; 2]),
|
||||
) -> Result<(FacePlan, PlanStats)> {
|
||||
let mut stats = PlanStats::default();
|
||||
match plan_face(fi, kind, s, loops, rules, size, &mut stats, Lenient::No) {
|
||||
Ok(fp) => Ok((fp, stats)),
|
||||
Err(first) => {
|
||||
let mut stats = PlanStats::default();
|
||||
match plan_face(fi, kind, s, loops, rules, size, &mut stats, Lenient::Yes) {
|
||||
Ok(fp) => {
|
||||
stats.lenient.push(LenientFace { face: fi, reason: first.to_string() });
|
||||
Ok((fp, stats))
|
||||
}
|
||||
Err(_) => Err(first),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One face: boundary loops in 3D (shared edge nodes) to parameters and triangles.
|
||||
/// `size`: the face's target side length (mm) and the surface's mean speed along u and v.
|
||||
/// `lenient`: the last resort for a face no method could plan (see [`Lenient`]).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn plan_face(
|
||||
fi: usize,
|
||||
kind: &str,
|
||||
@@ -574,6 +629,7 @@ fn plan_face(
|
||||
rules: &size::Rules,
|
||||
size: (f64, [f64; 2]),
|
||||
stats: &mut PlanStats,
|
||||
lenient: Lenient,
|
||||
) -> Result<FacePlan> {
|
||||
let tol = rules.tol;
|
||||
let (h, speed) = size;
|
||||
@@ -659,13 +715,21 @@ fn plan_face(
|
||||
let seeds = cdt::lattice(bbox, step, &polys, speed);
|
||||
let eval = |u: f64, v: f64| s.derivs(u, v).map(|(p, su, sv)| (p, su.cross(sv).normalized()));
|
||||
let sag = cdt::Sag { eval: &eval, tol, h, turn: rules.turn, scale: speed };
|
||||
let fill = cdt::Fill { seeds: &seeds, refine: Some((sag, MAX_REFINE)), shape: !matches!(s, EvalSurface::Plane { .. }) };
|
||||
let fill = cdt::Fill {
|
||||
seeds: &seeds,
|
||||
refine: Some((sag, MAX_REFINE)),
|
||||
shape: !matches!(s, EvalSurface::Plane { .. }),
|
||||
lenient: lenient == Lenient::Yes,
|
||||
};
|
||||
cdt::triangulate(&uvs, &ranges, fill).ok_or_else(|| fail("boundary crosses itself"))
|
||||
};
|
||||
// Planar and curved faces alike: a structured grid where the boundary runs along the
|
||||
// parameter box (a rectangle, a cylinder half), a Coons grid on four corners, else Delaunay.
|
||||
let planar = matches!(s, EvalSurface::Plane { .. });
|
||||
let (extra, triangles) = {
|
||||
// The lenient fill is the constrained Delaunay alone: the caller names the face in the stats.
|
||||
let (extra, triangles) = if lenient == Lenient::Yes {
|
||||
delaunay()?
|
||||
} else {
|
||||
let mut us = uv::divide(s, 0, bbox[0], bbox[1], rules, h, MAX_LINES);
|
||||
let mut vs = uv::divide(s, 1, bbox[1], bbox[0], rules, h, MAX_LINES);
|
||||
grid::thin(&mut us, &mut vs, grid::MAX_FACE_GRID);
|
||||
@@ -755,7 +819,8 @@ fn plan_face(
|
||||
let pole_pair = |i: u32, j: u32| i != j && fixed.get(i as usize).zip(fixed.get(j as usize)).is_some_and(|(p, q)| p == q);
|
||||
let mut triangles = triangles;
|
||||
triangles.retain(|t| !(pole_pair(t[0], t[1]) || pole_pair(t[1], t[2]) || pole_pair(t[2], t[0])));
|
||||
if !closed_boundary(&ranges, &fixed, &uvs, &triangles) {
|
||||
// A lenient fill leaves out the sides that cross: the boundary is followed everywhere else.
|
||||
if lenient == Lenient::No && !closed_boundary(&ranges, &fixed, &uvs, &triangles) {
|
||||
return Err(fail("triangulation does not follow the boundary"));
|
||||
}
|
||||
let mut all = uvs;
|
||||
@@ -896,7 +961,7 @@ fn plan_pieces(f: &Region) -> Option<(Vec<[f64; 2]>, Vec<[u32; 3]>)> {
|
||||
let seeds = cdt::lattice(bbox, [f.h / f.speed[0], f.h / f.speed[1]], &polys, f.speed);
|
||||
let eval = |u: f64, v: f64| s.derivs(u, v).map(|(p, su, sv)| (p, su.cross(sv).normalized()));
|
||||
let sag = cdt::Sag { eval: &eval, tol: f.rules.tol, h: f.h, turn: f.rules.turn, scale: f.speed };
|
||||
cdt::triangulate(&luv, &ranges, cdt::Fill { seeds: &seeds, refine: Some((sag, MAX_REFINE)), shape: true })
|
||||
cdt::triangulate(&luv, &ranges, cdt::Fill { seeds: &seeds, refine: Some((sag, MAX_REFINE)), shape: true, lenient: false })
|
||||
})?;
|
||||
let (lextra, ltris) = local;
|
||||
let base = u32::try_from(n + extra.len()).ok()?;
|
||||
|
||||
@@ -99,7 +99,7 @@ fn a_box_is_a_regular_grid_on_every_face() {
|
||||
fn primitives_are_watertight_with_the_right_volume() {
|
||||
for tol in [0.05, 0.005] {
|
||||
let s = check("box", &ok(crate::box_solid(Vec3::ZERO, Vec3::new(10.0, 6.0, 4.0))), tol, 240.0);
|
||||
assert_eq!(s, PlanStats { planar: 6, structured: 0, delaunay: 0 });
|
||||
assert_eq!(s, PlanStats { planar: 6, structured: 0, delaunay: 0, lenient: Vec::new() });
|
||||
let s = check("cylinder", &ok(crate::cylinder(Vec3::new(1.0, 2.0, 3.0), Vec3::new(0.0, 1.0, 1.0), 2.5, 7.0)), tol, PI * 2.5 * 2.5 * 7.0);
|
||||
assert_eq!(s.delaunay, 0, "cylinder walls are structured");
|
||||
let s = check("torus", &ok(crate::torus(Vec3::ZERO, 6.0, 1.5)), tol, 2.0 * PI * PI * 6.0 * 1.5 * 1.5);
|
||||
@@ -645,7 +645,7 @@ fn loops_touching_at_a_shared_vertex_bound_the_face() {
|
||||
let uvs: Vec<[f64; 2]> = outer.iter().chain(&left).chain(&right).copied().collect();
|
||||
let fixed: Vec<Vec3> = uvs.iter().map(|q| Vec3::new(q[0], q[1], 0.0)).collect();
|
||||
let ranges = vec![0..4, 4..7, 7..10];
|
||||
let fill = cdt::Fill { seeds: &[], refine: None, shape: false };
|
||||
let fill = cdt::Fill { seeds: &[], refine: None, shape: false, lenient: false };
|
||||
let Some((_, triangles)) = cdt::triangulate(&uvs, &ranges, fill) else { panic!("triangulates") };
|
||||
assert!(closed_boundary(&ranges, &fixed, &uvs, &triangles), "the triangles follow both holes through their shared vertex");
|
||||
}
|
||||
@@ -683,3 +683,70 @@ fn a_thin_lune_whose_chords_cross_meshes() {
|
||||
assert_watertight(&m, "lune");
|
||||
assert!(m.measure().volume > 0.0, "inside out");
|
||||
}
|
||||
|
||||
/// A doubly curved patch 40 mm across, and a loop on it in (u, v) whose right side folds back
|
||||
/// past itself near the top: the last chord of the fold crosses the side, as a cusp or a sliver
|
||||
/// whose sides sag across each other leaves a face's boundary.
|
||||
fn a_face_crossing_itself() -> (EvalSurface, seam::Loop, size::Rules) {
|
||||
let mut ctrl = Vec::new();
|
||||
for j in 0..3 {
|
||||
for i in 0..3 {
|
||||
let bump = if i == 1 && j == 1 { 12.0 } else { 0.0 };
|
||||
ctrl.push([20.0 * f64::from(i), 20.0 * f64::from(j), bump, 1.0]);
|
||||
}
|
||||
}
|
||||
let s = EvalSurface::Nurbs {
|
||||
degree: [2, 2],
|
||||
knots: [vec![0., 0., 0., 1., 1., 1.], vec![0., 0., 0., 1., 1., 1.]],
|
||||
count: [3, 3],
|
||||
ctrl,
|
||||
closed: [false, false],
|
||||
};
|
||||
let corners = [[0.1, 0.1], [0.9, 0.1], [0.9, 0.7], [0.7, 0.95], [0.86, 0.8], [0.1, 0.9]];
|
||||
let mut uv: Vec<[f64; 2]> = Vec::new();
|
||||
for k in 0..corners.len() {
|
||||
let (a, b) = (corners[k], corners[(k + 1) % corners.len()]);
|
||||
for t in 0..8 {
|
||||
let f = f64::from(t) / 8.0;
|
||||
uv.push([a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f]);
|
||||
}
|
||||
}
|
||||
let pts: Vec<Vec3> = uv.iter().filter_map(|q| s.derivs(q[0], q[1]).map(|(p, _, _)| p)).collect();
|
||||
assert_eq!(pts.len(), uv.len());
|
||||
(s, seam::Loop { uv, pts }, size::Rules::new(0.05, 40.0, None))
|
||||
}
|
||||
|
||||
/// A curved face crossing itself in (u, v) is refused by every method; the lenient fill leaves
|
||||
/// the crossing side out and plans the rest in (u, v), with points inside the face on its surface
|
||||
/// (the GPU evaluates them there), not flat between boundary nodes.
|
||||
#[test]
|
||||
fn a_curved_face_crossing_itself_is_filled_on_its_surface() {
|
||||
let (s, l, rules) = a_face_crossing_itself();
|
||||
let size = size::face_size(&s, &uv::domain(&s), &rules);
|
||||
let loops = std::slice::from_ref(&l);
|
||||
let mut stats = PlanStats::default();
|
||||
assert!(plan_face(0, "spline", &s, loops, &rules, size, &mut stats, Lenient::No).is_err());
|
||||
let Ok(fp) = plan_face(0, "spline", &s, loops, &rules, size, &mut stats, Lenient::Yes) else { panic!("a lenient fill") };
|
||||
assert!(!fp.triangles.is_empty());
|
||||
assert!(fp.uv.len() > fp.fixed.len(), "{} points, {} on the boundary", fp.uv.len(), fp.fixed.len());
|
||||
// Each point inside the face on the surface where its parameters put it.
|
||||
let mesh = TessPlan { surfaces: vec![s.clone()], faces: vec![FacePlan { surface: Some(0), ..fp.clone() }], ..TessPlan::default() }.evaluate();
|
||||
for (q, p) in fp.uv.iter().zip(&mesh.positions).skip(fp.fixed.len()) {
|
||||
let Some((on, _, _)) = s.derivs(q[0], q[1]) else { panic!("evaluates at {q:?}") };
|
||||
assert!(on.dist(*p) < 1e-9, "{q:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The face filled leniently is named in the plan's stats with why the strict plan refused it, and
|
||||
/// counted under no method: the display has no hole, and the defect is still reported.
|
||||
#[test]
|
||||
fn a_face_filled_leniently_is_named_in_the_stats() {
|
||||
let (s, l, rules) = a_face_crossing_itself();
|
||||
let size = size::face_size(&s, &uv::domain(&s), &rules);
|
||||
let Ok((fp, stats)) = plan_or_fill(7, "spline", &s, std::slice::from_ref(&l), &rules, size) else { panic!("filled leniently") };
|
||||
assert!(!fp.triangles.is_empty());
|
||||
assert_eq!((stats.planar, stats.structured, stats.delaunay), (0, 0, 0));
|
||||
let [lenient] = stats.lenient.as_slice() else { panic!("one lenient face: {:?}", stats.lenient) };
|
||||
assert_eq!(lenient.face, 7);
|
||||
assert!(lenient.reason.contains("face 7 (spline)"), "{}", lenient.reason);
|
||||
}
|
||||
@@ -389,7 +389,12 @@ fn draft_tilts_a_side_about_its_line_on_the_neutral_plane() {
|
||||
fn a_setback_corner_left_open_returns_its_hole() {
|
||||
let b = Brep::make_box([0.0; 3], [60.0, 40.0, 20.0]).unwrap();
|
||||
let edges = [[30.0, 40.0, 20.0], [60.0, 20.0, 20.0], [60.0, 40.0, 10.0]];
|
||||
solidcraft_profile::set_enabled(true);
|
||||
let mark = solidcraft_profile::mark();
|
||||
let (open, holes) = b.blend_setback_open(Blend::Round, &edges, &[5.0; 3], &[[60.0, 40.0, 20.0]], &[8.0], 0.1).unwrap();
|
||||
// The call is a profiler span like every other, timed by the C API.
|
||||
let report = mark.report();
|
||||
assert!(report.rows.iter().any(|r| r.category == "smlib" && r.name == "smlib_blend_setback_open"), "{report:?}");
|
||||
shot(&open, "setback_open");
|
||||
assert_eq!(open.counts().unwrap(), [9, 30, 22]);
|
||||
assert!(!open.is_manifold_solid().unwrap());
|
||||
|
||||
@@ -188,6 +188,9 @@ crate::dialog_descriptor::dialog_descriptors! {
|
||||
distance2: String,
|
||||
angle: String,
|
||||
flip: bool,
|
||||
/// A smooth-patch corner's setback along each edge, as typed; empty for the
|
||||
/// command's own default (1.5 × the radius).
|
||||
setback: String,
|
||||
},
|
||||
Mirror,
|
||||
/// Rectangular pattern of bodies: along one direction, optionally a second.
|
||||
@@ -1631,6 +1634,72 @@ fn fillet_edges(s: &Session, sel: &Sel, chain: bool) -> Vec<Sel> {
|
||||
picked
|
||||
}
|
||||
|
||||
/// How close two edge ends are to be one vertex (mm).
|
||||
const VERTEX_TOLERANCE: f64 = 1e-6;
|
||||
|
||||
/// The B-rep edges a Fillet dialog rounds, by body and index: the picked edges, and each edge of a
|
||||
/// picked face but its seams.
|
||||
fn fillet_edge_ids(s: &Session, items: &[Sel]) -> Vec<(String, usize)> {
|
||||
let st = crate::open_meshing::session_world(s);
|
||||
let mut ids: Vec<(String, usize)> = Vec::new();
|
||||
for x in items {
|
||||
match x {
|
||||
Sel::Edge { body, index, .. } => ids.push((body.clone(), *index)),
|
||||
Sel::Face { body, index, .. } => {
|
||||
if let Some(b) = st.body(body) {
|
||||
let m = b.mesh();
|
||||
for e in m.face_edges(u32::try_from(*index).unwrap_or(u32::MAX)) {
|
||||
if !m.seams.get(e).copied().unwrap_or(false) {
|
||||
ids.push((body.clone(), e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
ids.sort();
|
||||
ids.dedup();
|
||||
ids
|
||||
}
|
||||
|
||||
/// The corners of a Fillet dialog's edges where a smooth patch goes (`corner: g2`): each vertex
|
||||
/// where three or more of the edges meet and every other edge there is rounded too, once.
|
||||
pub(crate) fn fillet_corners(s: &Session, items: &[Sel]) -> Vec<Vec3> {
|
||||
let st = crate::open_meshing::session_world(s);
|
||||
let ids = fillet_edge_ids(s, items);
|
||||
let mut corners: Vec<Vec3> = Vec::new();
|
||||
let mut bodies: Vec<&str> = ids.iter().map(|(b, _)| b.as_str()).collect();
|
||||
bodies.dedup();
|
||||
for body in bodies {
|
||||
let Some(b) = st.body(body) else { continue };
|
||||
let m = b.mesh();
|
||||
let picked: Vec<usize> = ids.iter().filter(|(x, _)| x == body).map(|(_, e)| *e).collect();
|
||||
// An open edge's two ends (a closed one has no vertex to share).
|
||||
let ends = |e: usize| m.edges.get(e).and_then(|p| Some((*p.first()?, *p.last()?))).filter(|(a, b)| a.dist(*b) > VERTEX_TOLERANCE);
|
||||
let mut meeting: Vec<(Vec3, usize)> = Vec::new();
|
||||
for (a, b) in picked.iter().filter_map(|e| ends(*e)) {
|
||||
for v in [a, b] {
|
||||
match meeting.iter_mut().find(|(c, _)| c.dist(v) < VERTEX_TOLERANCE) {
|
||||
Some((_, n)) => *n += 1,
|
||||
None => meeting.push((v, 1)),
|
||||
}
|
||||
}
|
||||
}
|
||||
for (v, n) in meeting {
|
||||
let at = |e: &usize| ends(*e).is_some_and(|(a, b)| a.dist(v) < VERTEX_TOLERANCE || b.dist(v) < VERTEX_TOLERANCE);
|
||||
let real = |e: &usize| !m.seams.get(*e).copied().unwrap_or(false);
|
||||
if n >= 3
|
||||
&& (0..m.edges.len()).filter(real).filter(at).all(|e| picked.contains(&e))
|
||||
&& !corners.iter().any(|c| c.dist(v) < VERTEX_TOLERANCE)
|
||||
{
|
||||
corners.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
corners
|
||||
}
|
||||
|
||||
/// Profiles of the sketch a feature would use, when there is just one: the active sketch's, else
|
||||
/// the last sketch's while no feature builds from it yet. A used profile (a cube's sketch on its
|
||||
/// bottom face) is only taken when it is picked.
|
||||
@@ -3381,7 +3450,16 @@ pub(crate) const CHAMFER_TYPES: [&str; 3] = ["Equal Distance", "Two Distances",
|
||||
|
||||
/// A new Fillet or Chamfer dialog's values.
|
||||
fn fillet_kind(size: &str, chamfer: bool) -> Kind {
|
||||
Kind::Fillet { radius: size.into(), chamfer, chain: true, ctype: 0, distance2: size.into(), angle: "45 deg".into(), flip: false }
|
||||
Kind::Fillet {
|
||||
radius: size.into(),
|
||||
chamfer,
|
||||
chain: true,
|
||||
ctype: 0,
|
||||
distance2: size.into(),
|
||||
angle: "45 deg".into(),
|
||||
flip: false,
|
||||
setback: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// A length field's first text: `number` in the design's units, with the unit written out so the
|
||||
@@ -3913,7 +3991,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
}
|
||||
("solid.revolve", p)
|
||||
}
|
||||
Kind::Fillet { radius, chamfer, ctype, distance2, angle, flip, .. } => {
|
||||
Kind::Fillet { radius, chamfer, ctype, distance2, angle, flip, setback, .. } => {
|
||||
need(0, "edges")?;
|
||||
// Faces stand for all their edges.
|
||||
let st = crate::open_meshing::session_world(s);
|
||||
@@ -3977,6 +4055,14 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
}
|
||||
}
|
||||
}
|
||||
// A smooth patch's setback, typed once, goes to each of the dialog's corners; left
|
||||
// empty, the command sets them back by its default (1.5 × the radius).
|
||||
if d.extra.get("corner").and_then(Value::as_str) == Some("g2") && !setback.trim().is_empty() {
|
||||
let corners = fillet_corners(s, sels(d, 0));
|
||||
if !corners.is_empty() {
|
||||
p["setbacks"] = Value::Array(corners.into_iter().map(|v| json!({"vertex": pt3(v), "distance": setback.trim()})).collect());
|
||||
}
|
||||
}
|
||||
("solid.fillet", p)
|
||||
}
|
||||
}
|
||||
@@ -5274,6 +5360,23 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
inp.items = edges.iter().enumerate().filter_map(|(i, p)| edge_pick(i, p.0)).collect();
|
||||
d.picked_edges = inp.items.clone();
|
||||
}
|
||||
// Setbacks: one distance at exactly the dialog's smooth-patch corners shows in Setback;
|
||||
// any other list (from the command) is kept as saved.
|
||||
if let FeatureKind::Fillet { setbacks, corner, .. } = &f.kind
|
||||
&& let Some(first) = setbacks.first()
|
||||
{
|
||||
let corners = fillet_corners(s, sels(&d, 0));
|
||||
let uniform = setbacks.iter().all(|c| c.distance == first.distance);
|
||||
let at_corners =
|
||||
corners.len() == setbacks.len() && setbacks.iter().all(|c| corners.iter().any(|v| v.dist(c.vertex.0) < VERTEX_TOLERANCE));
|
||||
match &mut d.kind {
|
||||
Kind::Fillet { setback, .. } if !corner.is_rolling() && uniform && at_corners => *setback = first.distance.to_string(),
|
||||
_ => {
|
||||
let saved = setbacks.iter().map(|c| json!({"vertex": pt3(c.vertex.0), "distance": c.distance.to_string()}));
|
||||
d.extra.insert("setbacks".into(), Value::Array(saved.collect()));
|
||||
}
|
||||
}
|
||||
}
|
||||
d.chain_applied = false;
|
||||
d
|
||||
}
|
||||
|
||||
@@ -103,10 +103,61 @@ const FILLET_TYPES: [(&str, &str); 5] = [
|
||||
("Constant radius", "constant"),
|
||||
("Chord length", "chord"),
|
||||
("Variable radius", "variable"),
|
||||
("Curvature continuous (G2)", "curvature"),
|
||||
("ui.fillet_type_curvature", "curvature"),
|
||||
("Spline", "spline"),
|
||||
];
|
||||
|
||||
/// What fills a fillet's corners where three or more rounded edges meet (labels and hover texts,
|
||||
/// in the order of the `corner` words `rolling` and `g2`).
|
||||
const FILLET_CORNERS: [(&str, &str); 2] =
|
||||
[("ui.fillet_corner_ball", "ui.fillet_corner_ball_tip"), ("ui.fillet_corner_patch", "ui.fillet_corner_patch_tip")];
|
||||
|
||||
/// A fillet's Corners row (`corner`) and, with a smooth patch, its Setback (`setbacks`, one
|
||||
/// distance for every corner). Shown only while the edges have a corner where three or more
|
||||
/// rounded edges meet, or the fillet already has a smooth patch; a patch takes Constant radius
|
||||
/// and Exact fit.
|
||||
fn fillet_corner_rows(
|
||||
ui: &mut egui::Ui,
|
||||
s: &solidcraft_engine::Session,
|
||||
extra: &mut serde_json::Map<String, Value>,
|
||||
inputs: &[selection::SelInput],
|
||||
rtype: usize,
|
||||
setback: &mut String,
|
||||
) -> bool {
|
||||
let patch = extra.get("corner").and_then(Value::as_str) == Some("g2");
|
||||
if !patch && fillet_corners(s, selection::items(inputs, 0)).is_empty() {
|
||||
return false;
|
||||
}
|
||||
let exact = extra.get("fit").and_then(Value::as_str).is_none_or(|fit| fit == "exact");
|
||||
let mut enter = false;
|
||||
ui.add_enabled_ui(rtype == 0 && exact, |ui| {
|
||||
form_row(ui, "ui.corners", |ui| {
|
||||
let mut choice = usize::from(patch);
|
||||
let response = ui_kit::dropdown(ui, "fi_corner", &mut choice, &FILLET_CORNERS.map(|(label, _)| label));
|
||||
if choice != usize::from(patch) {
|
||||
if choice == 1 {
|
||||
extra.insert("corner".into(), json!("g2"));
|
||||
} else {
|
||||
extra.remove("corner");
|
||||
}
|
||||
}
|
||||
response
|
||||
})
|
||||
.on_hover_text(FILLET_CORNERS.map(|(_, tip)| tr(tip)).join("\n"));
|
||||
if extra.get("corner").and_then(Value::as_str) == Some("g2") {
|
||||
ui.scope(|ui| {
|
||||
let hint = crate::i18n::format("ui.fillet_setback_hint", &[("factor", "1.5")]);
|
||||
enter |= hint_row(ui, "ui.fillet_setback", setback, &hint);
|
||||
})
|
||||
.response
|
||||
.on_hover_text(crate::i18n::format("ui.fillet_setback_tip", &[("factor", "1.5")]));
|
||||
}
|
||||
})
|
||||
.response
|
||||
.on_disabled_hover_text(tr("ui.fillet_corner_needs_constant"));
|
||||
enter
|
||||
}
|
||||
|
||||
/// The most instances a solid pattern makes in one direction (the document's own limit).
|
||||
const MAX_PATTERN_INSTANCES: i64 = 1000;
|
||||
|
||||
@@ -133,6 +184,7 @@ fn choose_fillet_type(extra: &mut serde_json::Map<String, Value>, index: usize,
|
||||
if index != 0 {
|
||||
extra.remove("fit");
|
||||
extra.remove("corner");
|
||||
extra.remove("setbacks");
|
||||
}
|
||||
if index == 2 {
|
||||
extra.entry("radius2").or_insert_with(|| json!("1 mm"));
|
||||
@@ -341,7 +393,7 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
}
|
||||
});
|
||||
}
|
||||
Kind::Fillet { radius, chamfer, chain, ctype, distance2, angle, flip } => {
|
||||
Kind::Fillet { radius, chamfer, chain, ctype, distance2, angle, flip, setback } => {
|
||||
if *chamfer {
|
||||
choice_row(ui, "Chamfer Type", "ch_type", ctype, &CHAMFER_TYPES);
|
||||
}
|
||||
@@ -350,21 +402,14 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
if !*chamfer {
|
||||
form_row(ui, "Type", |ui| {
|
||||
let previous = rtype;
|
||||
combo(ui, "fi_type", &FILLET_TYPES.map(|(label, _)| label), &mut rtype);
|
||||
let response = ui_kit::dropdown(ui, "fi_type", &mut rtype, &FILLET_TYPES.map(|(label, _)| label));
|
||||
if previous != rtype {
|
||||
choose_fillet_type(&mut d.extra, rtype, radius);
|
||||
}
|
||||
});
|
||||
form_row(ui, "Continuity", |ui| {
|
||||
let mut continuity = usize::from(rtype == 3);
|
||||
if ui_kit::segmented(ui, &mut continuity, &["G1", "G2"], Default::default()) {
|
||||
rtype = if continuity == 1 { 3 } else { 0 };
|
||||
choose_fillet_type(&mut d.extra, rtype, radius);
|
||||
// G1 explicitly returns to rolling corners. G2 describes the edge blend,
|
||||
// whereas the separate advanced Corner control describes a vertex patch.
|
||||
d.extra.remove("corner");
|
||||
}
|
||||
});
|
||||
response
|
||||
})
|
||||
.on_hover_text(tr("ui.fillet_type_tip"));
|
||||
enter |= fillet_corner_rows(ui, &app.session, &mut d.extra, &d.inputs, rtype, setback);
|
||||
}
|
||||
if *chamfer && *ctype == 1 {
|
||||
enter |= expr_row(ui, "Distance 2", distance2);
|
||||
@@ -421,9 +466,13 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
}
|
||||
});
|
||||
d.extra.insert("mid".into(), json!(mids.iter().map(|(t, r)| json!([t, r])).collect::<Vec<_>>()));
|
||||
form_row(ui, "Smooth", |ui| {
|
||||
extra_check(ui, &mut d.extra, "smooth");
|
||||
});
|
||||
// How the radius runs between the radii: smoothly, or straight.
|
||||
let was = d.extra.get("smooth").and_then(Value::as_bool).unwrap_or(false);
|
||||
let mut smooth = was;
|
||||
ui_kit::checkbox_grid(ui, &mut [("ui.fillet_smooth_radius", &mut smooth)], 1);
|
||||
if smooth != was {
|
||||
d.extra.insert("smooth".into(), json!(smooth));
|
||||
}
|
||||
}
|
||||
if rtype == 4 {
|
||||
// The radius along the edge as a B-spline: its control radii from the
|
||||
@@ -467,16 +516,8 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
});
|
||||
}
|
||||
});
|
||||
let exact = d.extra.get("fit").and_then(Value::as_str).is_none_or(|fit| fit == "exact");
|
||||
ui.add_enabled_ui(constant && exact, |ui| {
|
||||
form_row(ui, "Corner", |ui| {
|
||||
extra_choice(ui, &mut d.extra, "fi_corner", "corner", &[("Rolling", "rolling"), ("G2", "g2")]);
|
||||
});
|
||||
})
|
||||
.response
|
||||
.on_hover_text(tr("G2 corners require a constant radius and Exact fit. G2 corner construction is not supported yet."));
|
||||
if !constant {
|
||||
ui.label(RichText::new(tr("Fit and G2 corners require Constant radius.")).color(t.text_dim).size(t.font_small));
|
||||
ui.label(RichText::new(tr("ui.fillet_fit_needs_constant")).color(t.text_dim).size(t.font_small));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1021,13 +1062,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fillet_options_and_continuity_keep_the_existing_command_parameters() {
|
||||
fn fillet_options_keep_the_existing_command_parameters() {
|
||||
let mut h = Harness::new();
|
||||
h.call("ui.resize", json!({"width":1400,"height":1000}));
|
||||
sample(&mut h);
|
||||
h.step(&json!({"start":"solid.fillet"})).unwrap();
|
||||
h.frames(4);
|
||||
h.step(&json!({"click":{"handle":"dialog:Continuity:G2"}})).unwrap();
|
||||
choose(&mut h, "Type", "ui.fillet_type_curvature");
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().extra.get("type"), Some(&json!("curvature")));
|
||||
h.step(&json!({"click":{"handle":"dialog:Tangent Chain"}})).unwrap();
|
||||
assert!(matches!(h.app.dialog.as_ref().unwrap().kind, Kind::Fillet { chain: false, .. }));
|
||||
@@ -1083,33 +1124,136 @@ mod tests {
|
||||
assert_eq!(p["knots"].as_array().unwrap().len(), 9);
|
||||
assert!(p["start"].is_array());
|
||||
}
|
||||
assert!(scenario::handle_at("dialog:Continuity:G3").is_none());
|
||||
// Type is the one place the section is chosen: no second Continuity control.
|
||||
assert!(scenario::handle_at("dialog:Continuity").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn continuity_and_advanced_controls_map_to_edge_type_fit_and_corner() {
|
||||
fn advanced_controls_map_to_fit() {
|
||||
let mut h = fillet_harness();
|
||||
assert!(scenario::handle_at("dialog:Radius Fit").is_none(), "Advanced starts collapsed");
|
||||
h.step(&json!({"click":{"handle":"dialog:section:Advanced"}})).unwrap();
|
||||
choose(&mut h, "Corner", "G2");
|
||||
assert_eq!(parameters(&h)["corner"], json!("g2"));
|
||||
choose(&mut h, "Corner", "Rolling");
|
||||
assert!(parameters(&h).get("corner").is_none());
|
||||
assert!(scenario::handle_at("dialog:Corner").is_none(), "the corner is no longer an advanced choice");
|
||||
choose(&mut h, "Radius Fit", "Reduce to Fit");
|
||||
assert_eq!(parameters(&h)["fit"], json!("reduce"));
|
||||
choose(&mut h, "Radius Fit", "Taper to Fit");
|
||||
assert_eq!(parameters(&h)["fit"], json!("taper"));
|
||||
choose(&mut h, "Radius Fit", "Exact");
|
||||
assert!(parameters(&h).get("fit").is_none());
|
||||
h.step(&json!({"click":{"handle":"dialog:Continuity:G2"}})).unwrap();
|
||||
assert_eq!(parameters(&h)["type"], json!("curvature"));
|
||||
h.step(&json!({"click":{"handle":"dialog:Continuity:G1"}})).unwrap();
|
||||
}
|
||||
|
||||
/// The three edges of the sample's corner at (10, 0, 5): top front, top right and upright.
|
||||
fn corner_edges(h: &Harness, count: usize) -> Vec<Sel> {
|
||||
[Vec3::new(5.0, 0.0, 5.0), Vec3::new(10.0, 5.0, 5.0), Vec3::new(10.0, 0.0, 2.5)]
|
||||
.into_iter()
|
||||
.take(count)
|
||||
.map(|p| edge_sel(&h.app.session, p).unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn set_edges(h: &mut Harness, count: usize) {
|
||||
let edges = corner_edges(h, count);
|
||||
h.app.dialog.as_mut().unwrap().inputs.first_mut().unwrap().items = edges;
|
||||
h.frames(3);
|
||||
}
|
||||
|
||||
/// Corners shows only once three rounded edges meet at a corner; Smooth patch then writes
|
||||
/// `corner: g2`, its Setback (empty for the command's 1.5 × radius) goes to that corner as
|
||||
/// `setbacks`, and Ball writes neither.
|
||||
#[test]
|
||||
fn corners_row_follows_the_selection_and_maps_to_corner_and_setbacks() {
|
||||
let mut h = fillet_harness();
|
||||
for count in [1, 2] {
|
||||
set_edges(&mut h, count);
|
||||
assert!(scenario::handle_at("dialog:ui.corners").is_none(), "{count} edges: no corner where three rounded edges meet");
|
||||
}
|
||||
set_edges(&mut h, 3);
|
||||
let corners = fillet_corners(&h.app.session, &h.app.dialog.as_ref().unwrap().inputs[0].items);
|
||||
assert_eq!(corners.len(), 1, "{corners:?}");
|
||||
assert!(corners[0].dist(Vec3::new(10.0, 0.0, 5.0)) < 1e-6, "{corners:?}");
|
||||
assert!(scenario::handle_at("dialog:ui.corners").is_some(), "three rounded edges meet at (10, 0, 5)");
|
||||
assert!(scenario::handle_at("dialog:ui.fillet_setback").is_none(), "Setback goes with a smooth patch");
|
||||
assert!(parameters(&h).get("corner").is_none(), "Ball is the default and writes nothing");
|
||||
choose(&mut h, "ui.corners", "ui.fillet_corner_patch");
|
||||
let p = parameters(&h);
|
||||
assert!(p.get("type").is_none() && p.get("corner").is_none());
|
||||
assert_eq!(p["corner"], json!("g2"));
|
||||
assert!(p.get("setbacks").is_none(), "an empty Setback leaves the command's default: {p}");
|
||||
assert!(scenario::handle_at("dialog:ui.fillet_setback").is_some());
|
||||
if let Some(Dialog { kind: Kind::Fillet { setback, .. }, .. }) = h.app.dialog.as_mut() {
|
||||
*setback = "3 mm".into();
|
||||
}
|
||||
assert_eq!(parameters(&h)["setbacks"], json!([{"vertex": [10.0, 0.0, 5.0], "distance": "3 mm"}]));
|
||||
choose(&mut h, "ui.corners", "ui.fillet_corner_ball");
|
||||
let p = parameters(&h);
|
||||
assert!(p.get("corner").is_none() && p.get("setbacks").is_none(), "{p}");
|
||||
assert!(scenario::handle_at("dialog:ui.fillet_setback").is_none());
|
||||
// Another type clears the patch; the row stays, disabled, saying why in its hover text.
|
||||
choose(&mut h, "ui.corners", "ui.fillet_corner_patch");
|
||||
choose(&mut h, "Type", "Chord length");
|
||||
h.step(&json!({"click":{"handle":"dialog:Continuity:G1"}})).unwrap();
|
||||
assert!(parameters(&h).get("type").is_none(), "even an already highlighted G1 explicitly selects Constant radius");
|
||||
let p = parameters(&h);
|
||||
assert!(p.get("corner").is_none() && p.get("setbacks").is_none(), "{p}");
|
||||
assert!(scenario::handle_at("dialog:ui.corners").is_some());
|
||||
}
|
||||
|
||||
/// No visible label of the fillet dialog names a continuity by its code (G0 … G3): the words
|
||||
/// are on the controls, the codes only in hover texts. Every section open, the corner row shown.
|
||||
#[test]
|
||||
fn fillet_labels_use_words_not_continuity_codes() {
|
||||
let coded = |text: &str| ["G0", "G1", "G2", "G3"].iter().any(|code| text.contains(code));
|
||||
for label in FILLET_TYPES.map(|(label, _)| label).into_iter().chain(FILLET_CORNERS.map(|(label, _)| label)) {
|
||||
assert!(!coded(crate::i18n::tr_label(label)), "{label}: {}", crate::i18n::tr_label(label));
|
||||
}
|
||||
for tip in FILLET_CORNERS.map(|(_, tip)| tip) {
|
||||
assert!(coded(crate::i18n::tr(tip)), "the hover text keeps the code for those who know it: {tip}");
|
||||
}
|
||||
let mut h = fillet_harness();
|
||||
set_edges(&mut h, 3);
|
||||
choose(&mut h, "ui.corners", "ui.fillet_corner_patch");
|
||||
for section in ["Variable Radius", "Advanced"] {
|
||||
h.step(&json!({"click":{"handle":format!("dialog:section:{section}")}})).unwrap();
|
||||
}
|
||||
h.frames(3);
|
||||
assert!(scenario::handle_at("dialog:ui.fillet_setback").is_some() && scenario::handle_at("dialog:Radius Fit").is_some());
|
||||
let tree = h.output.accesskit_update.as_ref().unwrap();
|
||||
let labels: Vec<String> = tree.nodes.iter().flat_map(|(_, node)| [node.label(), node.value()]).flatten().map(str::to_string).collect();
|
||||
assert!(labels.iter().any(|l| l == "Smooth patch"), "{labels:?}");
|
||||
let shown: Vec<&String> = labels.iter().filter(|l| coded(l)).collect();
|
||||
assert!(shown.is_empty(), "labels with a continuity code: {shown:?}");
|
||||
}
|
||||
|
||||
/// A smooth-patch fillet reopens with its corner and setback, and OK writes them as saved; a
|
||||
/// setback list the dialog cannot show as one distance is kept as it is.
|
||||
#[test]
|
||||
fn a_saved_smooth_patch_reopens_with_its_setback() {
|
||||
for (setbacks, field) in [
|
||||
(json!([{"vertex": [0, 0, 0], "distance": 7}]), "7"),
|
||||
// Named near the vertex, as the command allows, rather than at it.
|
||||
(json!([{"vertex": [0.1, 0.1, 0], "distance": 7}]), ""),
|
||||
] {
|
||||
let mut h = Harness::new();
|
||||
// The command's own smooth-patch corner: a 20 mm box, its three edges at the origin.
|
||||
h.app.run("solid.box", json!({"length": 20, "width": 20, "height": 20, "body_name": "B"})).unwrap();
|
||||
let edges = json!([[10, 0, 0], [0, 10, 0], [0, 0, 10]]);
|
||||
h.app.run("solid.fillet", json!({"edges": edges, "radius": 4, "corner": "g2", "setbacks": setbacks})).unwrap();
|
||||
let id = h.app.session.doc.features.last().unwrap().id;
|
||||
let corner_of = |h: &Harness| match &h.app.session.doc.feature(id).unwrap().kind {
|
||||
FeatureKind::Fillet { corner, setbacks, .. } => (*corner, setbacks.clone()),
|
||||
other => panic!("{other:?}"),
|
||||
};
|
||||
let saved = corner_of(&h);
|
||||
assert!(!saved.0.is_rolling() && saved.1.len() == 1, "{saved:?}");
|
||||
h.app.edit_feature(id);
|
||||
h.frames(3);
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert!(matches!(&d.kind, Kind::Fillet { setback, .. } if setback == field), "{:?}", d.kind);
|
||||
assert_eq!(d.extra.get("corner"), Some(&json!("g2")));
|
||||
for (command, params) in apply_commands(&h.app, d).unwrap() {
|
||||
crate::dialogs::roll_marker(&mut h.app, None).unwrap();
|
||||
h.app.run(&command, params).unwrap();
|
||||
}
|
||||
assert_eq!(corner_of(&h), saved, "OK keeps the corner and its setbacks");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1129,9 +1273,12 @@ mod tests {
|
||||
assert!(scenario::handle_at("dialog:End Radius").is_none(), "the section stays collapsed after a type choice");
|
||||
h.step(&json!({"click":{"handle":"dialog:section:Variable Radius"}})).unwrap();
|
||||
assert!(scenario::handle_at("dialog:End Radius").is_some());
|
||||
assert!(scenario::handle_at("dialog:Smooth").is_some(), "Smooth is a supported variable-radius option even before adding a middle radius");
|
||||
assert!(
|
||||
scenario::handle_at("dialog:ui.fillet_smooth_radius").is_some(),
|
||||
"Smooth radius change is a supported variable-radius option even before adding a middle radius"
|
||||
);
|
||||
h.step(&json!({"widget":"Add Mid Radius"})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:Smooth"}})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:ui.fillet_smooth_radius"}})).unwrap();
|
||||
let saved = parameters(&h);
|
||||
assert_eq!(saved["mid"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(saved["smooth"], json!(true));
|
||||
|
||||
@@ -91,7 +91,14 @@ pub(crate) fn fields<'a>(doc: &Document, kind: &'a mut crate::dialogs::Kind) ->
|
||||
use crate::dialogs_surface::Surf;
|
||||
match kind {
|
||||
D::Extrude { distance, distance2, to_offset, start, wall, wall2, .. } => vec![distance, distance2, to_offset, start, wall, wall2],
|
||||
D::Fillet { radius, distance2, .. } => vec![radius, distance2],
|
||||
D::Fillet { radius, distance2, setback, .. } => {
|
||||
// An empty setback stands for the command's default and stays empty.
|
||||
let mut lengths = vec![radius, distance2];
|
||||
if !setback.trim().is_empty() {
|
||||
lengths.push(setback);
|
||||
}
|
||||
lengths
|
||||
}
|
||||
D::Shell { thickness } => vec![thickness],
|
||||
D::PatternRect { spacing, spacing2, .. } => vec![spacing, spacing2],
|
||||
D::OffsetPlane { offset } | D::Section { offset, .. } => vec![offset],
|
||||
|
||||
Reference in new issue
Block a user