Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/doc/src/eval_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,11 @@ pub(super) fn sheet_eval(
// the later one's is cut.
let order = doc.feature_index(f.id).unwrap_or(usize::MAX);
let mut made = Vec::with_capacity(picks.len());
let mut square = Vec::with_capacity(picks.len());
for (k, (edge, runs)) in picks.into_iter().enumerate() {
// One bend for each run: a split edge's butt where its runs meet.
let joints = sk.flanges_on(edge, &runs, rr, position, from).map_err(named(k))?;
let (joints, sides) = sk.flanges_on(edge, &runs, rr, position, from).map_err(named(k))?;
square.push(sides);
if let Some((relief, size)) = own {
for &joint in &joints {
sk.corner_reliefs.push((joint, relief, size, order));
Expand All @@ -1339,6 +1341,11 @@ pub(super) fn sheet_eval(
for (k, joints) in made.iter().enumerate() {
open.extend(sk.close_flange_corners(joints).map_err(named(k))?);
}
// A side laid on square no other bend met carries on the edge beside it again, now
// that every corner of the feature is closed (#19833).
for (k, sides) in square.iter().enumerate() {
sk.slant_open_sides(sides).map_err(named(k))?;
}
// The corners on the outside of a bend that stay open (#20720): each pair of bends is
// met once, so each corner once.
for at in open {
Expand Down
107 changes: 95 additions & 12 deletions crates/doc/src/sheet_surface_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,18 @@ impl SurfaceSheet {
from: HeightFrom,
flip: bool,
) -> Result<usize> {
let joint = self.flange_on(edge, height, angle, radius, position, from, flip)?;
let (joint, square) = self.flange_on(edge, height, angle, radius, position, from, flip)?;
self.close_corners(joint)?;
self.slant_open_sides(&square)?;
Ok(joint)
}

/// Closes the corners of the bends `made`, a feature's flanges all added first (see
/// [`SurfaceSheet::flange_on`]), each against the bends before it (see `close_corners`). The
/// corners left open because closing them would overlap the flat (see [`OUTSIDE_BEND_OPEN`]),
/// where they are in the sheet's space.
/// where they are in the sheet's space. Once every bend of the feature is closed, the caller
/// gives the sides laid on square for now their slant back
/// ([`SurfaceSheet::slant_open_sides`]).
pub fn close_flange_corners(&mut self, made: &[usize]) -> Result<Vec<Vec3>> {
let mut open = Vec::new();
for &j in made {
Expand All @@ -661,10 +664,22 @@ impl SurfaceSheet {
/// several edges adds all its flanges first and then closes their corners
/// ([`SurfaceSheet::close_flange_corners`]), so a flange that stands on another's side edge
/// (side flanges across a bend) is there when the corner the three bends make is closed.
/// With the flange's joint, its sides still to slant once the corners are closed (see
/// [`SurfaceSheet::slant_open_sides`]).
#[allow(clippy::too_many_arguments)]
pub fn flange_on(&mut self, edge: FreeEdge, height: f64, angle: f64, radius: f64, position: &str, from: HeightFrom, flip: bool) -> Result<usize> {
let made = self.flanges_on(edge, &[(WHOLE_EDGE.0, WHOLE_EDGE.1, height, angle, flip)], radius, position, from)?;
made.first().copied().ok_or_else(|| DocError::Invalid("the flange has no bend".into()))
pub fn flange_on(
&mut self,
edge: FreeEdge,
height: f64,
angle: f64,
radius: f64,
position: &str,
from: HeightFrom,
flip: bool,
) -> Result<(usize, Vec<SquareSides>)> {
let (made, square) = self.flanges_on(edge, &[(WHOLE_EDGE.0, WHOLE_EDGE.1, height, angle, flip)], radius, position, from)?;
let joint = made.first().copied().ok_or_else(|| DocError::Invalid("the flange has no bend".into()))?;
Ok((joint, square))
}

/// Flanges on stretches of the free edge `edge`, as [`SurfaceSheet::flange_on`] makes one on
Expand All @@ -683,15 +698,16 @@ impl SurfaceSheet {
/// setbacks differ. The two bends at a junction butt (see [`SurfaceSheet::junctions`]): no
/// corner is closed and no bend relief is cut there. Their corners elsewhere are not closed
/// yet (see [`SurfaceSheet::close_flange_corners`]). The new bends' joints, in the order of
/// `runs`.
/// `runs`, and the flanges among them laid on with square sides for now, which
/// [`SurfaceSheet::slant_open_sides`] settles once the corners are closed.
pub fn flanges_on(
&mut self,
edge: FreeEdge,
runs: &[(f64, f64, f64, f64, bool)],
radius: f64,
position: &str,
from: HeightFrom,
) -> Result<Vec<usize>> {
) -> Result<(Vec<usize>, Vec<SquareSides>)> {
if runs.iter().any(|&(_, _, _, angle, _)| !(angle > 1e-6 && angle <= std::f64::consts::PI - 1e-6)) {
return err("the flange angle must be between 0 and 180°");
}
Expand Down Expand Up @@ -770,6 +786,7 @@ impl SurfaceSheet {
});
}
let mut made = Vec::with_capacity(plans.len());
let mut square = Vec::new();
for run in plans {
let (origin, to) = run.anchor;
// A sharp inside the edge by no more than the thickness needs no cut: the bend's band
Expand Down Expand Up @@ -802,15 +819,22 @@ impl SurfaceSheet {
let depth = run.leg.max(0.0) + run.sharp;
let at = |y: f64| (-k0 * y, len - k1 * y);
let ((p0, p1), (q0, q1)) = (at(0.0), at(-depth));
if !(p1 - p0 > 1e-9 && q1 - q0 > 1e-9) {
return err("the edges beside it close the flange before it reaches its height");
}
// Sides that would cross before the flange reaches its height are laid on square for
// now: a bend that meets the flange at a corner replaces its side there, and only a
// side none meets is refused (see `slant_open_sides`).
let crossing = !(p1 - p0 > 1e-9 && q1 - q0 > 1e-9);
let (q0, q1) = if crossing { (p0, p1) } else { (q0, q1) };
let n = self.add_panel("flange", &edge, origin, d, len, depth, bend);
if let Some(panel) = self.sheet.panels.get_mut(n) {
let corners = [Vec2::new(p0, 0.0), Vec2::new(q0, -depth), Vec2::new(q1, -depth), Vec2::new(p1, 0.0)];
panel.region = Region2 { outer: Loop2::polygon(&corners).ccw(), holes: Vec::new() };
}
made.push(self.sheet.joints.len() - 1);
let joint = self.sheet.joints.len() - 1;
if crossing {
let side = |x: f64| [Vec2::new(x, 0.0), Vec2::new(x, -depth)];
square.push(SquareSides { joint, slants: (k0, k1), sides: [side(p0), side(p1)] });
}
made.push(joint);
}
// Where two runs meet, their bends butt: the later run's, nearer `a`, ends there, and the
// earlier one's starts there.
Expand All @@ -819,7 +843,53 @@ impl SurfaceSheet {
self.junctions.push([*later, *earlier]);
}
}
Ok(made)
Ok((made, square))
}

/// Gives the flanges `square` laid on with square sides (see [`SquareSides`]) their sides
/// back, once their feature's corners are closed. A side another bend met at its corner (a
/// mitre, or a flange cut back on the outside of a bend) keeps what closing the corner made of
/// it. A flange no other bend met at either side is refused: its sides cross, as `flanges_on`
/// found. Every other side carries on the edge beside it again, as `flanges_on` lays it, up
/// to the flange's far edge; where it would cross the side another bend made before it gets
/// there, the flange is refused.
pub fn slant_open_sides(&mut self, square: &[SquareSides]) -> Result<()> {
for s in square {
let Some(Joint { b: an, kind: JointKind::Bend(bend), .. }) = self.sheet.joints.get(s.joint).cloned() else { continue };
let met = [self.side_met(an.panel, s.sides[0]), self.side_met(an.panel, s.sides[1])];
if met == [false, false] {
return err("the edges beside it close the flange before it reaches its height");
}
for (end, slant, met) in [(0.0, s.slants.0, met[0]), (bend.length, s.slants.1, met[1])] {
if slant == 0.0 || met {
continue;
}
let Some(region) = self.sheet.panels.get(an.panel).map(|p| p.region.clone()) else { continue };
let Some((region, _)) = to_line(&region, &an, -1.0, end, end, an.dir * slant - an.dir.perp())? else {
return err("the edges beside it close the flange before it reaches its height");
};
if let Some(panel) = self.sheet.panels.get_mut(an.panel) {
panel.region = region;
}
}
}
Ok(())
}

/// Whether closing the corners met the side `side` (its two ends, as `flanges_on` laid it) of
/// panel `i`: the panel's outline no longer has it, or a rip starts at its foot (a mitre that
/// runs square up from the bend's end, where the flange's side already was).
fn side_met(&self, i: usize, [foot, top]: [Vec2; 2]) -> bool {
let Some(panel) = self.sheet.panels.get(i) else { return true };
let kept = panel.region.outer.segs.iter().any(|s| matches!(*s, Seg2::Line { a, b } if (a == foot && b == top) || (a == top && b == foot)));
let ripped = self.sheet.joints.iter().any(|j| match &j.kind {
JointKind::Rip(r) => {
let at = |panel: usize, edge: &[Vec2]| panel == i && edge.contains(&foot);
at(j.a.panel, &r.edges.0) || at(j.b.panel, &r.edges.1)
}
_ => false,
});
!kept || ripped
}

/// Closes the corners the bend `j`, a flange's just added, makes with the other bends standing
Expand Down Expand Up @@ -2844,6 +2914,19 @@ struct FlangeRun {
strip: (Vec2, Vec2),
}

/// A flange [`SurfaceSheet::flanges_on`] laid on with square sides, because the sides it carries on
/// from the edges beside it would cross before it reaches its height (#19833): its bend's joint,
/// those sides' slants at its start and at its end (see `edge_slants`), and its square sides as
/// laid on, each from its foot on the bend to the flange's far edge, in the flange's chart. A
/// side another bend meets at its corner is replaced there when the corners are closed, so
/// whether the sides cross is known only then (see [`SurfaceSheet::slant_open_sides`]).
#[derive(Clone, Copy, Debug)]
pub struct SquareSides {
joint: usize,
slants: (f64, f64),
sides: [[Vec2; 2]; 2],
}

/// A fold worked out before anything of the sheet changes (see [`SurfaceSheet::add_fold`]).
struct FoldPlan {
/// The way to the side that moves, the way along the fold's line (the side that stays on its
Expand Down
Loading
Loading