Wave 240/509: A converted sheet takes its rule's values at its own thickness (#4328) (and 3 more)

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

- 610173e1f jyviko: combine: move each tool into its target's frame
- 3fb263d00 jyviko: hole: keep a countersink's tool within its rim above the face
- 1171c4c2a jyviko: A sheet metal body mirrored or patterned into new bodies is sheet metal (#3353)
- 5a9bf4742 jyviko: A converted sheet takes its rule's values at its own thickness (#4328)

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-26 05:55:36 -04:00
parent 7c481d281f
commit cbd7b07767
8 changed files with 179 additions and 35 deletions
+16 -8
View File
@@ -4300,8 +4300,8 @@ fn hole_tools(
}
/// The scale a hole's tools are sized by: the largest body the hole's axis meets (#2904), so a
/// large body elsewhere in the model changes neither the tool's reach above the face (and so
/// the countersink's outline) nor its depth. A hole whose axis meets no body is sized by the
/// large body elsewhere in the model changes neither the tool's reach above the face nor its
/// depth. A hole whose axis meets no body is sized by the
/// largest body of the model, as before.
fn hole_axis_size(st: &ModelState, position: &Vec3, dir: Vec3) -> f64 {
let along = |b: &ModelBody| {
@@ -4417,13 +4417,21 @@ fn hole_tools_and_prisms(
if !(rc > r && half > 1e-3 && half < std::f64::consts::FRAC_PI_2) {
return Err(DocError::Invalid("the countersink must be wider than the hole".into()));
}
// Cone from above the face to just inside the hole radius, then the hole.
let r_top = rc + top * half.tan();
// One revolved tool: the cone from its rim on the face to just inside the hole
// radius, and above the face the rim's cylinder, as the bore's own cylinder runs on
// above it. The cone widening on above the face would cut what stands beside the rim
// (#5041). The cone is the profile's first segment (`csink:side:0`).
let r_end = r * 0.9;
let len = (r_top - r_end) / half.tan();
let top_plane = plane.offset(top);
let csink = kernel::extrude_tapered(&top_plane, &disc(r_top), len, -1.0, -half, kernel::DraftCorner::default())?;
tools.push((crate::lineage::part_tool(csink, "csink"), None));
let len = (rc - r_end) / half.tan();
let up = -dir;
let rp = Plane::new(*position, up.any_perp(), up).ok_or_else(|| DocError::Invalid("hole axis".into()))?;
let pts = [Vec2::new(rc, 0.0), Vec2::new(r_end, -len), Vec2::new(0.0, -len), Vec2::new(0.0, top), Vec2::new(rc, top)];
let region = Region2 { outer: solidcraft_geom::Loop2::polygon(&pts), holes: vec![] };
tools.extend(
kernel::revolve(&rp, &[region], Vec2::ZERO, Vec2::Y, std::f64::consts::TAU)?
.into_iter()
.map(|tool| (crate::lineage::part_tool(tool, "csink"), None)),
);
tools.extend(bore(tip_angle.as_ref())?);
}
}
+13 -16
View File
@@ -579,10 +579,7 @@ pub(super) fn sheet_eval(
}
let rr = match radius {
Some(e) => val(vals, e, Kind::Length)?,
None => {
let rule = st.sheets.get(i).map(|s| s.rule.clone()).unwrap_or_default();
doc.rule_values(vals, &doc.sheet_rule(Some(&rule)))?.bend_radius
}
None => sheet_rule_values(doc, vals, st, i)?.bend_radius,
};
// The corner relief these flanges ask for in place of the rule's.
let relief = sheet::ReliefOverride {
@@ -693,10 +690,7 @@ pub(super) fn sheet_eval(
let l = val(vals, length, Kind::Length)?;
let g = match gap {
Some(e) => val(vals, e, Kind::Length)?,
None => {
let rule = st.sheets.get(i).map(|s| s.rule.clone()).unwrap_or_default();
doc.rule_values(vals, &doc.sheet_rule(Some(&rule)))?.hem_gap
}
None => sheet_rule_values(doc, vals, st, i)?.hem_gap,
};
let sh = st.sheets.get_mut(i).ok_or_else(|| DocError::Invalid("sheet".into()))?;
let picks = sheet_picks(sh, f, &crate::plain(edges), warning);
@@ -724,10 +718,7 @@ pub(super) fn sheet_eval(
let ang = val(vals, angle, Kind::Angle)?;
let rr = match radius {
Some(e) => val(vals, e, Kind::Length)?,
None => {
let rule = st.sheets.get(i).map(|s| s.rule.clone()).unwrap_or_default();
doc.rule_values(vals, &doc.sheet_rule(Some(&rule)))?.bend_radius
}
None => sheet_rule_values(doc, vals, st, i)?.bend_radius,
};
// A fixed point that touches no material at all (e.g. far above the sheet) still picks
// the side it lies on, so a stored fold keeps recomputing; it says so (#371).
@@ -767,7 +758,7 @@ pub(super) fn sheet_eval(
FeatureKind::SheetConvert { body, face, rule, bends } if !bends.is_empty() => {
let mb = st.body(body).cloned().ok_or_else(|| DocError::Unknown(format!("body `{body}`")))?;
let r = doc.sheet_rule(rule.as_deref());
let rv = doc.rule_values(vals, &r)?;
let values = |t: Option<f64>| doc.rule_values_at(vals, &r, t);
// The bend edges by name first; a name that is gone keeps its point, with a warning.
let mut picks = Vec::with_capacity(bends.len());
for (i, p) in bends.iter().enumerate() {
@@ -788,7 +779,7 @@ pub(super) fn sheet_eval(
}
let placement = doc.component_transform(doc.model_body_component(&mb));
let body_to_world = doc.model_body_offset(&mb).map(|offset| crate::mat_mul(&placement, offset)).unwrap_or(placement);
let (mut sh, notes) = sheet::convert_body(&mb, &r.name, &rv, face.0, &picks, &body_to_world)?;
let (mut sh, notes) = sheet::convert_body(&mb, &r.name, &values, face.0, &picks, &body_to_world)?;
for note in notes {
append_warning(warning, note);
}
@@ -839,8 +830,7 @@ pub(super) fn sheet_eval(
));
}
let r = doc.sheet_rule(rule.as_deref());
let mut rv = doc.rule_values(vals, &r)?;
rv.thickness = t;
let rv = doc.rule_values_at(vals, &r, Some(t))?;
let mut sh = sheet::base_flange(body, &r.name, &rv, plane, Region2 { outer: region.outer.clone(), holes: Vec::new() });
sh.holes = region.holes.iter().map(|h| Region2 { outer: h.ccw(), holes: Vec::new() }).collect();
let mut work = sheet::FlatWork::new();
@@ -2180,6 +2170,13 @@ fn sheet_picks(sh: &crate::sheet::SheetBody, f: &Feature, edges: &[Vec3], warnin
out
}
/// The values of sheet `i`'s rule for that sheet: `Thickness` in them is the sheet's own
/// thickness, which a converted body takes from its walls.
fn sheet_rule_values(doc: &Document, vals: &BTreeMap<String, Value>, st: &ModelState, i: usize) -> Result<sheet::RuleValues> {
let sh = st.sheets.get(i).ok_or_else(|| DocError::Invalid("sheet".into()))?;
doc.rule_values_at(vals, &doc.sheet_rule(Some(&sh.rule)), Some(sh.t))
}
/// Tag the flanges a feature just added (`F<feature>.<k>`).
fn tag_flanges(sh: &mut crate::sheet::SheetBody, from: usize, feature: u64) {
for (k, fl) in sh.flanges.iter_mut().enumerate().skip(from) {
+10 -1
View File
@@ -476,8 +476,17 @@ impl Document {
/// Evaluate a rule: `Thickness` in its expressions is the rule's thickness.
pub fn rule_values(&self, vals: &std::collections::BTreeMap<String, Value>, r: &SheetRule) -> Result<RuleValues> {
self.rule_values_at(vals, r, None)
}
/// Evaluate a rule for a sheet `thickness` thick (a converted body's own thickness), or the
/// rule's thickness: `Thickness` in its expressions is the sheet's.
pub fn rule_values_at(&self, vals: &std::collections::BTreeMap<String, Value>, r: &SheetRule, thickness: Option<f64>) -> Result<RuleValues> {
let look = |n: &str| vals.get(n).copied().ok_or_else(|| DocError::Expr(format!("unknown parameter `{n}`")));
let t = expr::eval_with(&r.thickness, &look)?.to_kind(Kind::Length)?;
let t = match thickness {
Some(t) => t,
None => expr::eval_with(&r.thickness, &look)?.to_kind(Kind::Length)?,
};
if !(t > 0.0 && t < 1e4) {
return Err(DocError::Invalid("the sheet thickness must be positive".into()));
}
+15 -10
View File
@@ -691,15 +691,16 @@ pub fn bend_edge_names(st: &crate::ModelState, body: &str, pts: &[Vec3]) -> Vec<
pts.iter().zip(crate::naming::edge_names_at(b, pts)).map(|(p, name)| if on(p) { name } else { String::new() }).collect()
}
/// Convert body `mb` to a sheet under the rule `rule` with values `rv`: `face` is a point on the
/// fixed face and `bends` are points on the sharp edges that become bends, in the middle of
/// chamfers or on bend cylinders that do (the body's coordinates, mm). See the module docs.
/// `body_to_world` places diagnostic points in world coordinates. Geometry and picks stay local.
/// Returns the sheet and a note for every corner or end of a bend not finished as the rule says.
/// Convert body `mb` to a sheet under the rule `rule`, whose values for a sheet of a thickness
/// (`None`: the rule's own) are `values`: `face` is a point on the fixed face and `bends` are
/// points on the sharp edges that become bends, in the middle of chamfers or on bend cylinders
/// that do (the body's coordinates, mm). See the module docs. `body_to_world` places diagnostic
/// points in world coordinates. Geometry and picks stay local. Returns the sheet and a note for
/// every corner or end of a bend not finished as the rule says.
pub fn convert_body(
mb: &ModelBody,
rule: &str,
rv: &RuleValues,
values: &dyn Fn(Option<f64>) -> Result<RuleValues>,
face: Vec3,
bends: &[Vec3],
body_to_world: &crate::Mat,
@@ -708,9 +709,7 @@ pub fn convert_body(
if bends.is_empty() || bends.len() > MAX_BENDS {
return err(format!("pick 1…{MAX_BENDS} bend edges"));
}
if !(rv.gap >= 0.0 && rv.bend_radius >= 0.0) {
return err("the rule's gap and bend radius must not be negative");
}
let rv = values(None)?;
let (b, mesh) = (&mb.body, mb.mesh());
let size = b.size();
if !(size.is_finite() && size > 0.0) {
@@ -763,6 +762,12 @@ pub fn convert_body(
.flatten()
.collect();
let t = shell.map_or(rv.thickness, |d| (d * 1e9).round() / 1e9);
// A shell's sheet is as thick as its walls: the rule's values that follow its thickness (a
// bend radius of `Thickness`, the gap, the reliefs) follow the walls', not the rule's own.
let rv = if shell.is_some() { values(Some(t))? } else { rv };
if !(rv.gap >= 0.0 && rv.bend_radius >= 0.0) {
return err("the rule's gap and bend radius must not be negative");
}
let r = rv.bend_radius;
let joined = |x: usize, y: usize| {
mesh.edge_faces.iter().any(|faces| faces.contains(&(x as u32)) && faces.contains(&(y as u32)))
@@ -841,7 +846,7 @@ pub fn convert_body(
}
panels.insert(g, wall);
}
let mut sh = base_flange(&mb.name, rule, &RuleValues { thickness: t, ..*rv }, frame, Region2::default());
let mut sh = base_flange(&mb.name, rule, &RuleValues { thickness: t, ..rv }, frame, Region2::default());
// How far behind a face of the sheet the body's face `g` starts and ends: a hole's wall
// reaches through the sheet, a pocket's ends on its floor, an island's starts at the face.
let mut points: BTreeMap<usize, Vec<Vec3>> = BTreeMap::new();