Fix lofts through sections turning past 90 degrees (#2847) (#3452)

* claim: #2847

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* loft: keep sections turned past 90 degrees facing the same way (#2847)

The loft oriented each section by the sign of its normal against the first section's, so on planes turning about an axis every section beyond 90 degrees was reversed and the side faces folded. Follow the facing neighbour to neighbour instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
rlartot
2026-10-21 00:15:41 +00:00
committed by GitHub
parent 4098ff9dc8
commit 6a8604c55d
2 changed files with 42 additions and 2 deletions
+11 -2
View File
@@ -2000,11 +2000,20 @@ fn loft_numbered_wires(sections: &[(Plane, NumberedLoop)], reversed: bool) -> Re
// with the most segments.
let n0 = ordered.first().map(|(p, _)| p.normal()).unwrap_or(Vec3::Z);
let parallel = ordered.iter().all(|(p, _)| p.normal().dot(n0).abs() > 1.0 - 1e-9);
// Whether a section faces the first one's way is followed neighbour to neighbour, not by its
// normal against the first's: planes turning about an axis pass 90 degrees and would be
// flipped, folding the loft (#2847).
let mut facing = true;
let mut before = n0;
let oriented: Vec<(Plane, NumberedLoop)> = ordered
.iter()
.map(|(p, l)| {
let ccw = p.normal().dot(n0) >= 0.0;
(*p, l.oriented(!ccw))
let n = p.normal();
if n.dot(before) < 0.0 {
facing = !facing;
}
before = n;
(*p, l.oriented(!facing))
})
.collect();
let lead = oriented.iter().max_by_key(|(_, l)| l.lp.segs.len()).ok_or_else(|| KernelError::Invalid("no sections".into()))?;
+31
View File
@@ -2981,6 +2981,37 @@ fn an_attempt_budget_stops_the_boolean_and_is_shared_by_nesting() {
assert!(boolean(&a, &b, BoolOp::Intersect).unwrap().is_some());
}
/// #2847: identical elliptic spline sections (3 x 5 mm, 30 mm off the Z axis) on planes turning
/// about Z in 10 degree steps. The start vertex was matched by projecting the lead section's
/// vertex directions onto each plane, which squeezes them as the plane turns (and flips them past
/// 90 degrees), so the sections were paired round the wrong way and the loft folded (6 % of
/// Pappus' volume at 180 degrees). The volume follows Pappus: area x 30 mm x angle.
#[test]
fn loft_through_identical_sections_turning_about_an_axis_keeps_its_volume() {
let pts: Vec<Vec2> = (0..12).map(|a| Vec2::new(30.0 + 3.0 * (a as f64 * PI / 6.0).cos(), 5.0 * (a as f64 * PI / 6.0).sin())).collect();
// Periodic Catmull-Rom through the points, as cubic Beziers.
let segs: Vec<Seg2> = (0..12)
.map(|i| {
let p = |k: usize| pts[(i + k + 11) % 12];
let (p0, p1, p2, p3) = (p(0), p(1), p(2), p(3));
Seg2::Cubic { p0: p1, p1: p1 + (p2 - p0) * (1.0 / 6.0), p2: p2 - (p3 - p1) * (1.0 / 6.0), p3: p2 }
})
.collect();
let section = Loop2 { segs };
let area = section.signed_area().abs();
for span in [90, 120, 180] {
let secs: Vec<(Plane, Loop2)> = (0..=span / 10)
.map(|i| {
let t = (i as f64 * 10.0).to_radians();
(Plane { origin: Vec3::ZERO, x: Vec3::new(t.cos(), t.sin(), 0.0), y: Vec3::Z }, section.clone())
})
.collect();
let want = area * 30.0 * (span as f64).to_radians();
let m = measure(&loft(&secs).unwrap()).unwrap();
assert!(rel(m.volume, want) < 0.03, "{span} degrees: volume {} vs Pappus {want}", m.volume);
}
}
/// Moving an assembly places every body of it again: a copy placed for showing keeps its
/// revolved faces where its source turned them, so placing searches none of them again (that search was most
/// of the time an occurrence move took on a large assembly, #3044), and the copy is the same