Wave 115/509: brep: a spline's closedness is worked out once, not on every evaluation (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 6e17d26dd jyviko: brep: a spline's closedness is worked out once, not on every evaluation - 51d7fc413 jyviko: kernel: IGES trimmed surfaces close their loops and split into separate bodies - f71cb3d99 jyviko: engine: revolve about a construction axis given by name - 85da7d6c2 jyviko: engine: count a face pick's work as it is done Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -61,35 +61,14 @@ impl Turn {
|
||||
pub(crate) struct Rules {
|
||||
pub tol: f64,
|
||||
pub max_len: f64,
|
||||
/// The body's extent (see [`extent`]); 0 when it has none. Tolerances that measure the
|
||||
/// body's own geometry rather than the mesh are fractions of it.
|
||||
pub extent: f64,
|
||||
pub turn: Option<Turn>,
|
||||
/// How far the body's boundaries may lie off their surfaces (mm), as the file the body was
|
||||
/// read from declares; `None` for a body this kernel built (see
|
||||
/// [`crate::body::Body::boundary_tol`]). It raises the planner's bound (a hundredth of the
|
||||
/// extent) where it is larger, never lowers it.
|
||||
pub boundary_tol: Option<f64>,
|
||||
}
|
||||
|
||||
impl Rules {
|
||||
/// The same rules with a chord tolerance `k` times finer.
|
||||
pub(crate) fn finer(self, k: f64) -> Rules {
|
||||
Rules { tol: self.tol / k, ..self }
|
||||
}
|
||||
|
||||
/// Rules for a body of extent `extent` (see [`extent`]). `boundary_tol`: the body's declared
|
||||
/// off-surface budget (mm), `None` for a body this kernel built.
|
||||
pub(crate) fn new(tol: f64, extent: f64, turn: Option<Turn>, boundary_tol: Option<f64>) -> Rules {
|
||||
let sound = extent.is_finite() && extent > 0.0;
|
||||
let max_len = if sound { extent * MAX_LEN_FRACTION } else { f64::INFINITY };
|
||||
Rules {
|
||||
tol,
|
||||
max_len: max_len.max(tol),
|
||||
extent: if sound { extent } else { 0.0 },
|
||||
turn,
|
||||
boundary_tol: boundary_tol.filter(|t| t.is_finite() && *t > 0.0),
|
||||
}
|
||||
/// Rules for a body of extent `extent` (see [`extent`]).
|
||||
pub(crate) fn new(tol: f64, extent: f64, turn: Option<Turn>) -> Rules {
|
||||
let max_len = if extent.is_finite() && extent > 0.0 { extent * MAX_LEN_FRACTION } else { f64::INFINITY };
|
||||
Rules { tol, max_len: max_len.max(tol), turn }
|
||||
}
|
||||
|
||||
/// The side length for a curvature `k` (1/mm): the chord sags at most the tolerance across
|
||||
@@ -199,36 +178,37 @@ mod tests {
|
||||
swap: false,
|
||||
};
|
||||
// A 20 mm body: sides from 1 mm (the floor, a quarter of the longest) to 4 mm.
|
||||
let rules = Rules::new(0.01, 20.0, THIRTY, None);
|
||||
let rules = Rules::new(0.01, 20.0, THIRTY);
|
||||
let (h, speed) = face_size(&s, &super::super::uv::domain(&s), &rules);
|
||||
// r = 3: 30° of turn is 1.57 mm; the 0.01 mm sag chord is √(8·3·0.01) = 0.49 mm, times the
|
||||
// aspect, unless that is under the floor.
|
||||
assert!((h - (ASPECT * (8.0 * 3.0 * 0.01f64).sqrt()).max(20.0 * MAX_LEN_FRACTION * MIN_LEN_FRACTION)).abs() < 0.01, "{h}");
|
||||
assert!((speed[0] - 40.0).abs() < 1e-6 && (speed[1] - 3.0).abs() < 1e-6, "{speed:?}");
|
||||
// Coarser: the turn limit governs.
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, THIRTY, None));
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, THIRTY));
|
||||
assert!((h - (ASPECT * 3.0 * std::f64::consts::PI / 6.0).max(100.0 * MAX_LEN_FRACTION * MIN_LEN_FRACTION)).abs() < 0.01, "{h}");
|
||||
// Without a facet angle the sag alone: √(8·3·0.5) = 3.46 mm, four times along.
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, None, None));
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, None));
|
||||
assert!((h - ASPECT * (8.0 * 3.0 * 0.5f64).sqrt()).abs() < 0.01, "{h}");
|
||||
// A turn that sags below its floor does not divide.
|
||||
let floored = Some(Turn { angle: std::f64::consts::PI / 6.0, floor: 1.0 });
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, floored, None));
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &Rules::new(0.5, 100.0, floored));
|
||||
assert!((h - ASPECT * (8.0 * 3.0 * 0.5f64).sqrt()).abs() < 0.01, "{h}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_flat_spline_is_planar_and_a_bent_one_is_not() {
|
||||
let patch = |z: f64| EvalSurface::Nurbs {
|
||||
degree: [1, 1],
|
||||
knots: [vec![0.0, 0.0, 1.0, 1.0], vec![0.0, 0.0, 1.0, 1.0]],
|
||||
count: [2, 2],
|
||||
ctrl: vec![[0.0, 0.0, 0.0, 1.0], [4.0, 0.0, 0.0, 1.0], [0.0, 3.0, 0.0, 1.0], [4.0, 3.0, z, 1.0]],
|
||||
closed: [false, false],
|
||||
let patch = |z: f64| {
|
||||
EvalSurface::nurbs(
|
||||
[1, 1],
|
||||
[vec![0.0, 0.0, 1.0, 1.0], vec![0.0, 0.0, 1.0, 1.0]],
|
||||
[2, 2],
|
||||
vec![[0.0, 0.0, 0.0, 1.0], [4.0, 0.0, 0.0, 1.0], [0.0, 3.0, 0.0, 1.0], [4.0, 3.0, z, 1.0]],
|
||||
)
|
||||
};
|
||||
assert!(planar(&patch(0.0)));
|
||||
assert!(!planar(&patch(0.5)));
|
||||
let rules = Rules::new(0.01, 100.0, THIRTY, None);
|
||||
let rules = Rules::new(0.01, 100.0, THIRTY);
|
||||
let (h, speed) = face_size(&patch(0.0), &super::super::uv::domain(&patch(0.0)), &rules);
|
||||
assert_eq!(h, rules.max_len);
|
||||
assert!((speed[0] - 4.0).abs() < 1e-9 && (speed[1] - 3.0).abs() < 1e-9, "{speed:?}");
|
||||
@@ -245,7 +225,7 @@ mod tests {
|
||||
transform: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0]],
|
||||
swap: false,
|
||||
};
|
||||
let rules = Rules::new(0.1, 100.0, THIRTY, None);
|
||||
let rules = Rules::new(0.1, 100.0, THIRTY);
|
||||
let (h, _) = face_size(&s, &super::super::uv::domain(&s), &rules);
|
||||
assert!((h - rules.max_len * MIN_LEN_FRACTION).abs() < 1e-9, "{h}");
|
||||
}
|
||||
@@ -253,7 +233,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_plane_takes_the_longest_side() {
|
||||
let s = EvalSurface::Plane { origin: Vec3::ZERO, du: Vec3::X, dv: Vec3::Y };
|
||||
let rules = Rules::new(0.01, 100.0, THIRTY, None);
|
||||
let rules = Rules::new(0.01, 100.0, THIRTY);
|
||||
assert_eq!(face_size(&s, &super::super::uv::domain(&s), &rules).0, 20.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user