Wave 328/509: Kernel: an extrusion's wall seed marks only the edges nearest it (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 5547cd98a jyviko: Blends: a picked edge is named as the blend takes it, the rim and not the seam - 1cb713c96 jyviko: Kernel: an extrusion's wall seed marks only the edges nearest it - db9cf693a jyviko: Kernel: an extrusion's cap is in its own plane however thin the extrusion - de16a6b99 jyviko: Kernel: a half turn's caps keep their roles when its end plane is its start plane Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
+10
-2
@@ -3226,7 +3226,8 @@ pub fn edge_refs(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Vec3])
|
||||
}
|
||||
|
||||
/// Persistent names of the edges picked at `pts`, each on the body it lies on (see
|
||||
/// [`picked_bodies`]).
|
||||
/// [`picked_bodies`]): of the edge a blend takes at each pick (at a vertex where a seam meets a
|
||||
/// rim, the rim), else of the nearest edge.
|
||||
pub fn edge_names_for(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Vec3]) -> Vec<String> {
|
||||
let Some(on) = picked_bodies(st, body, pts) else { return Vec::new() };
|
||||
let mut out = vec![String::new(); pts.len()];
|
||||
@@ -3240,7 +3241,14 @@ pub fn edge_names_for(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Ve
|
||||
// The body's names are worked out once for all its picks.
|
||||
let idx: Vec<usize> = on.iter().enumerate().filter(|(_, t)| **t == ti).map(|(i, _)| i).collect();
|
||||
let at: Vec<Vec3> = idx.iter().filter_map(|i| pts.get(*i).copied()).collect();
|
||||
for (i, n) in idx.into_iter().zip(crate::naming::edge_names_at(b, &at)) {
|
||||
let names = match kernel::blend_edges(&b.body, &at) {
|
||||
Ok(edges) => {
|
||||
let all = crate::naming::edge_names(b);
|
||||
edges.iter().map(|e| all.get(*e).cloned().unwrap_or_default()).collect()
|
||||
}
|
||||
Err(_) => crate::naming::edge_names_at(b, &at),
|
||||
};
|
||||
for (i, n) in idx.into_iter().zip(names) {
|
||||
if let Some(slot) = out.get_mut(i) {
|
||||
*slot = n;
|
||||
}
|
||||
|
||||
@@ -617,6 +617,13 @@ pub fn chamfer_sides(body: &Body, edges: &[Vec3], d1: f64, side: ChamferSide, fl
|
||||
crate::blend_smlib::chamfer_sides(body, edges, d1, side, flip)
|
||||
}
|
||||
|
||||
/// The edge each pick takes, as a blend takes it (an index in the body's edge order, the order
|
||||
/// of its mesh's edges): the nearest, and at a vertex where a seam or a smooth join meets a sharp
|
||||
/// edge (a cylinder's seam at its rim), the sharp edge. Picks that find no edge are refused.
|
||||
pub fn blend_edges(body: &Body, picks: &[Vec3]) -> Result<Vec<usize>> {
|
||||
crate::blend_smlib::picked_edges(body, picks).map(|(edges, _)| edges)
|
||||
}
|
||||
|
||||
/// The picked edges' tangent chains, for a blend that is to run along them: `picks` (each the
|
||||
/// nearest edge of `body` to it), then a point on every other edge that continues one of them
|
||||
/// tangentially (within 0.5° at a shared vertex), until no more do. Each pick takes its edge as a
|
||||
|
||||
@@ -27,6 +27,12 @@ fn box_certificates_are_six_construction_roles_with_dimension_stable_axes() {
|
||||
(Vec3::new(2., 3., 4.), Vec3::new(12., 23., 34.)),
|
||||
(Vec3::new(12., 23., 34.), Vec3::new(2., 3., 4.)),
|
||||
(Vec3::new(2., -8., 4.), Vec3::new(22., 43., 54.)),
|
||||
// A side far shorter than the body (a 0.3 mm label of a metre): its walls' edges lie
|
||||
// closer together than the sweep's body-sized nearness, and each keeps its own role.
|
||||
(Vec3::new(500., -0.3, 1400.), Vec3::new(1500., 0., 1800.)),
|
||||
// Far thinner than the body's flatness tolerance (0.1 µm in 14 mm): each cap is in its
|
||||
// own plane only.
|
||||
(Vec3::ZERO, Vec3::new(10., 10., 1e-4)),
|
||||
] {
|
||||
let body = crate::box_solid(a, b).unwrap().with_box_certificate(42).unwrap();
|
||||
let mut roles = std::collections::HashSet::new();
|
||||
|
||||
@@ -155,8 +155,8 @@ mod validity;
|
||||
pub mod watch;
|
||||
|
||||
pub use blend::{
|
||||
ChamferSide, chamfer, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_least_setback, fillet_max, fillet_max_each,
|
||||
fillet_setback, tangent_chain,
|
||||
ChamferSide, blend_edges, chamfer, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_least_setback, fillet_max,
|
||||
fillet_max_each, fillet_setback, tangent_chain,
|
||||
};
|
||||
pub use blend_corner::fillet_radii;
|
||||
pub use blend_variable::{RadiusSpline, Taper, fillet_chord, fillet_tapered, fillet_variable, fillet_variable_points, fillet_variable_spline, taper};
|
||||
|
||||
@@ -272,7 +272,17 @@ mod imp {
|
||||
let m = body.mesh(&crate::MeshTolerance::chord(mesh_tol))?;
|
||||
let faces = face_tris(&m);
|
||||
let n = body.face_count();
|
||||
let flat_tol = size * 1e-5 + 1e-9;
|
||||
// A cap's points lie on its plane to the evaluation's precision. Sized to the body, the
|
||||
// flatness tolerance can exceed the gap between parallel start and end planes (a box
|
||||
// 0.1 µm thick in a 14 mm body), which would put each cap in both: it stays under a
|
||||
// quarter of that gap. Planes that coincide (the ends of a half turn) are told apart by
|
||||
// the profile's edges instead.
|
||||
let gap = end
|
||||
.filter(|e| e.normal().cross(start.normal()).len() < 1e-9)
|
||||
.map(|e| start.height(e.origin).abs())
|
||||
.filter(|g| *g > size * 1e-9)
|
||||
.unwrap_or(f64::INFINITY);
|
||||
let flat_tol = (size * 1e-5 + 1e-9).min(0.25 * gap);
|
||||
let near = 3.0 * mesh_tol + flat_tol;
|
||||
let flat = |f: usize, pl: &Plane| {
|
||||
faces.get(f).is_some_and(|ft| !ft.tris.is_empty() && ft.tris.iter().all(|(t, _)| t.iter().all(|q| pl.height(*q).abs() <= flat_tol)))
|
||||
@@ -289,12 +299,22 @@ mod imp {
|
||||
let end_cap: Vec<bool> = (0..n).map(|f| end.is_some_and(|e| flat(f, e))).collect();
|
||||
let cap = |f: usize| start_cap.get(f).copied().unwrap_or(false) || end_cap.get(f).copied().unwrap_or(false);
|
||||
let mut swept: Vec<BTreeSet<usize>> = vec![BTreeSet::new(); n];
|
||||
for (poly, fs) in m.edges.iter().zip(&m.edge_faces) {
|
||||
if poly.len() < 2 || !poly.iter().all(|q| start.height(*q).abs() <= flat_tol) {
|
||||
continue;
|
||||
}
|
||||
for s in edges {
|
||||
if poly.windows(2).any(|w| s.at.dist_to_segment(w[0], w[1]) <= near) {
|
||||
// Each seed lies on its own piece's edge (within the mesh's sag on a curve); `near` is
|
||||
// sized to the body, so on a side shorter than it (a 0.3 mm wall of a 1 m label) the
|
||||
// neighbours' edges are near too. The seed marks only the edges nearest it: the one it
|
||||
// lies on, or both pieces of an edge split at its middle.
|
||||
let start_edges: Vec<(&Vec<Vec3>, &Vec<u32>)> = m
|
||||
.edges
|
||||
.iter()
|
||||
.zip(&m.edge_faces)
|
||||
.filter(|(poly, _)| poly.len() >= 2 && poly.iter().all(|q| start.height(*q).abs() <= flat_tol))
|
||||
.collect();
|
||||
for s in edges {
|
||||
let dist = |poly: &[Vec3]| poly.windows(2).map(|w| s.at.dist_to_segment(w[0], w[1])).fold(f64::INFINITY, f64::min);
|
||||
let ds: Vec<f64> = start_edges.iter().map(|(poly, _)| dist(poly)).collect();
|
||||
let nearest = ds.iter().copied().fold(f64::INFINITY, f64::min);
|
||||
for ((_, fs), d) in start_edges.iter().zip(&ds) {
|
||||
if *d <= near && *d <= nearest + flat_tol {
|
||||
for f in fs.iter().map(|f| *f as usize).filter(|f| !cap(*f)) {
|
||||
if let Some(set) = swept.get_mut(f) {
|
||||
set.insert(s.piece);
|
||||
|
||||
Reference in New Issue
Block a user