Skip to content

Commit 3ef19b2

Browse files
jyvikoclaude
andcommitted
fix: a round on a round is certified on its inner definition piece by piece (tangency-labs#2570)
The certificate's boxes on an inner round by its definition took the faces' and the leader's polynomial pieces at the station in the middle of the inner net's piece and continued them over the box: the definition only where the net has a station at every knot line a foot crosses and at the leader's knots. A net with knots removed, refitted or edited does not, and a box past a station continued the pieces across it. The certificate now takes the piecewise enclosure the certified normal's query already used (`nurbs_partials_over_box`), so there is one enclosure of a definition, `definition_partials_naive`, and `definition_partials_piecewise` is gone. Each box is cut at the leader's knots it crosses and each part taken on its own leader piece; the feet's box is cut at the faces' knot lines, each part on its own piece, and the hull taken. A part whose feet cross a knot line takes the direct enclosure (the centred form's mean value step needs the smoothness a knot line breaks). The net's piece only seeds the feet. `knot_cuts` returns a point on an inner knot with both pieces, so a hull at such a point holds both one-sided values (a leader's derivatives at its knot, a face's partials on its knot line); before, it took the piece after the knot only. The test also encloses a box across each station the coarse net lost (188, all proved and holding the definition). With the faces' knot range kept as the piecewise enclosure has it, the two points at the round's very ends are refused (the feet lie on the edge of the front face's range and Krawczyk's box reaches past it); every other of the 3948 is proved, none off the definition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
1 parent 9cd1fc6 commit 3ef19b2

6 files changed

Lines changed: 252 additions & 148 deletions

File tree

‎crates/solidcore/src/blend/fillet_section/certificate.rs‎

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ pub fn face_partials_over(
685685
/// The parts of `[lo, hi]` between the knots strictly inside it, each with the span whose
686686
/// closed interval holds it: a knot crossed where the direction is continuous to less than
687687
/// `continuity` (degree minus multiplicity) is refused, and so is an interval past the
688-
/// knots' range (the face or curve is not defined there).
689-
fn knot_cuts(
688+
/// knots' range (the face or curve is not defined there). A point `lo = hi` on an inner
689+
/// knot lies in both spans' closed intervals: it is returned twice, once with each, so a
690+
/// hull over the parts holds both one-sided values there (#2570).
691+
pub(crate) fn knot_cuts(
690692
knots: &[f64],
691693
p: usize,
692694
n: usize,
@@ -702,6 +704,15 @@ fn knot_cuts(
702704
if !(lo >= first && hi <= last && lo <= hi) {
703705
return Err(refused("a box past the face's knots"));
704706
}
707+
let after = span(knots, p, n, lo);
708+
if lo == hi && after > p && knot(knots, after as isize) == lo {
709+
// the span that ends at the knot: the last one before it that is not empty
710+
let mut before = after - 1;
711+
while before > p && knot(knots, before as isize) >= knot(knots, before as isize + 1) {
712+
before -= 1;
713+
}
714+
return Ok(vec![(lo, hi, before), (lo, hi, after)]);
715+
}
705716
let mut at = vec![lo];
706717
let mut prev = f64::NAN;
707718
for &x in knots {
@@ -724,6 +735,12 @@ fn knot_cuts(
724735
.collect())
725736
}
726737

738+
/// Whether `[lo, hi]` lies on more than one piece of `knots` (it crosses an inner knot, or
739+
/// is a point on one), or past their range.
740+
pub(crate) fn crosses_a_knot(knots: &[f64], p: usize, n: usize, lo: f64, hi: f64) -> bool {
741+
knot_cuts(knots, p, n, lo, hi, 0).map_or(true, |c| c.len() > 1)
742+
}
743+
727744
/// The continuity a face must have at a knot line a feet's box crosses
728745
/// ([`nurbs_partials_over_box`]): Krawczyk's mean-value form needs the feet's system (the
729746
/// faces' points and first partials) continuous, with its Jacobian (their second partials)
@@ -764,29 +781,29 @@ pub fn nurbs_partials_over_box(
764781
let p = nurbs_partials_over_piece(cn, ku, kv, a0, a1, b0, b1, lk)?;
765782
out = Some(match out {
766783
None => p,
767-
Some(mut h) => {
768-
for a in 0..=lk {
769-
for b in 0..=(lk - a) {
770-
let (x, y) = (h.at(a, b), p.at(a, b));
771-
h.set(
772-
a,
773-
b,
774-
V3 {
775-
x: x.x.hull(y.x),
776-
y: x.y.hull(y.y),
777-
z: x.z.hull(y.z),
778-
},
779-
);
780-
}
781-
}
782-
h
783-
}
784+
Some(h) => partials_hull(h, &p, lk),
784785
});
785786
}
786787
}
787788
out.ok_or_else(|| SolidError::sm_err(OP))
788789
}
789790

791+
/// The hull of two enclosures of partials, `a + b <= lk`.
792+
pub(crate) fn partials_hull(mut h: Partials<Ivl>, p: &Partials<Ivl>, lk: usize) -> Partials<Ivl> {
793+
for a in 0..=lk {
794+
for b in 0..=(lk - a) {
795+
let (x, y) = (h.at(a, b), p.at(a, b));
796+
let v = V3 {
797+
x: x.x.hull(y.x),
798+
y: x.y.hull(y.y),
799+
z: x.z.hull(y.z),
800+
};
801+
h.set(a, b, v);
802+
}
803+
}
804+
h
805+
}
806+
790807
/// A span the feet are enclosed over (`sm_GnSpanAt`, c5b6bb7): S, the feet's guesses at
791808
/// its ends (their hull, widened, is the first box), each face's polynomial piece over it
792809
/// and the leader's (`None`: the one the middle of S lies in).
@@ -804,11 +821,12 @@ pub struct SpanAt {
804821
pub kv: [usize; 2],
805822
/// `lLeader`.
806823
pub leader: Option<usize>,
807-
/// Not upstream: a NURBS face's partials over a box, and the leader's series over S,
808-
/// are enclosed piece by piece ([`nurbs_partials_over_box`],
809-
/// [`leader_series_piecewise`]), so the feet and S may cross knot lines (`ku`, `kv` and
810-
/// `leader` unused for them); `false`: on the pieces `ku`, `kv` and `leader`, continued
811-
/// (upstream's, which relies on the station invariant).
824+
/// Not upstream: a NURBS face's partials over a box are enclosed piece by piece
825+
/// ([`nurbs_partials_over_box`]), so the feet may cross knot lines (`ku`, `kv` unused for
826+
/// them), and the leader's series over S on the piece `leader` names (the caller cut S
827+
/// at the leader's knots: a point S on a knot, the side it names) or, `None`, piece by
828+
/// piece ([`leader_series_piecewise`]); `false`: on the pieces `ku`, `kv` and `leader`,
829+
/// continued (upstream's, which relies on the station invariant).
812830
pub piecewise: bool,
813831
}
814832

@@ -896,7 +914,7 @@ pub fn gn_enclose_over(
896914
None => None,
897915
};
898916
let law_r = law_r.as_ref();
899-
let (leader, tangent) = if at.piecewise {
917+
let (leader, tangent) = if at.piecewise && at.leader.is_none() {
900918
gn_try!(leader_series_piecewise(leader_n, s, tr), None)
901919
} else {
902920
gn_try!(leader_series_over(leader_n, s, tr, at.leader), None)
@@ -2115,6 +2133,13 @@ mod tests {
21152133
continued_misses,
21162134
"the left piece continued is not the face past the knot"
21172135
);
2136+
// a point on the knot: both sides' partials (the third u-partial jumps there)
2137+
let at = nurbs_partials_over_box(&n, 1.0, 1.0, 0.25, 0.25, 3, FEET_BOX_CONTINUITY).unwrap();
2138+
let sides = [3, 4].map(|ku| nurbs_partials::<f64>(&n, ku, 1, 1.0, 0.25, 3).at(3, 0).z);
2139+
assert!(sides[0] != sides[1], "{sides:?}");
2140+
for c in sides {
2141+
assert!(contains(at.at(3, 0).z, c), "{c} not in {:?}", at.at(3, 0).z);
2142+
}
21182143
// a double knot (C^1) crossed by a feet's box is refused; at C^1 asked, enclosed
21192144
let d = cubic_with_knot(2);
21202145
assert!(matches!(

0 commit comments

Comments
 (0)