Files
makeCAD/crates/kernel/src/issue_1080_tests.rs
T
jyviko f74c6605c4 Fillet: Mitre or Swept corners where two rounds meet (#11498)
* SMLib wrapper: a swept or mitred turn for constant rounds (Turn)

Brep::blend_dropping takes a Turn: Mitre (the default, as before) or Swept,
which sets solidcore's FilletSession::set_swept_turns before the corners are
made. A swept turn solidcore refuses at CreateFilletCorners comes back as
Error::TurnRefused with its reason and place (NoRoom at a concave side edge,
else CornerUnsupported). Swept is for Blend::Round only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Kernel: fillet rounds turn in a mitre or swept (FilletTurn)

fillet_removing, fillet_max, fillet_max_each and fillet_each take a
FilletTurn and hand it to SMLib, through the reblend of earlier rounds at a
later corner too. A swept corner solidcore does not build is refused as
invalid input with its reason and place: no smaller radius builds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Design: a fillet saves its turn, mitre (default) or swept

FeatureKind::Fillet gets `turn` (FilletTurn: mitre, the default and not
saved, or swept), one pending format file. Evaluation hands it to the kernel,
pattern copies included, and refuses a swept turn with a style, fit, corner
or setbacks the kernel's swept corner does not take (SWEPT_TAKES).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* solid.fillet: the turn parameter, and the command's input and output schemas

`turn: mitre|swept` on solid.fillet, refused when unknown or with options a
swept corner does not take. solid.fillet now has its contract (FilletParams)
and reply type (FilletResult), registered with checked!, and leaves
schema/unconverted.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Fillet dialog: a Turns choice, Mitre or Swept

A Constant radius fillet's Turns row sends `turn: swept`; choosing a narrowed
radius or a curvature corner puts it back to Mitre, and Swept puts those back.
Its tooltip says what each does where two rounds turn round a corner edge.
New strings in a pending locale file (en, de, ja, ko, zh); glossary entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Fillet turn: the schema tests' fixes and the complete catalogs' strings

The no-contract example in the schema tests is solid.chamfer now that
solid.fillet has one; the reply test checks the mid-radii form against the
contract (solidcore refuses that law's corner yet, #430) instead of building
it; Arabic, Hebrew and Vietnamese, complete catalogs, get the new strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Fillet schema test: variable and spline forms checked against the contract

solidcore fails a variable round on a box edge at this pin (status 1001, as
variable_radius_on_a_box_edge), so the reply test checks those forms against
the contract instead of building them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

* Fillet turn: the swept rig cases pass; the MCP no-contract example is solid.chamfer

cov-fillet-turn-swept-boss-base-r1 and
cov-fillet-turn-swept-pocket-sharp-corner-refused-r1 pass now that
solid.fillet takes `turn`: off the rig's known-failing list. The MCP bridge
test's example of a command without a contract was solid.fillet, which has
one now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ

---------

Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:36:00 -05:00

118 lines
6.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! #1080: fillets and chamfers that would run past the faces beside their edge. A convex blend
//! running over a face's far edge into a pocket or a hole (a cliff) is built as if its faces went
//! on and what it removes is cut from the body, so it never bridges the opening (the owner's
//! blend-overflow decision, 237f0ae74); blends that would cross each other are refused as too
//! large, and the largest size that fits is found by searching ([`crate::fillet_max`],
//! [`crate::chamfer_max`]).
use solidcore_record::Vec3;
use crate::{Body, BoolOp, ChamferSide, KernelError, build::box_solid, ops::boolean};
fn cut(a: &Body, lo: [f64; 3], hi: [f64; 3]) -> Body {
let t = box_solid(Vec3::new(lo[0], lo[1], lo[2]), Vec3::new(hi[0], hi[1], hi[2])).unwrap();
boolean(a, &t, BoolOp::Cut).unwrap().unwrap()
}
/// A 40 × 20 × 20 block with a 10 × 10 pocket, 10 deep, 4 mm in from its top edge at x = 40.
fn pocketed() -> Body {
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(40.0, 20.0, 20.0)).unwrap();
cut(&b, [26.0, 5.0, 10.0], [36.0, 15.0, 20.0])
}
const EDGE: Vec3 = Vec3 { x: 40.0, y: 10.0, z: 20.0 };
fn too_large(r: crate::Result<Body>) -> String {
match r {
Err(KernelError::TooLarge(m)) => m,
Err(e) => panic!("refused, but not as too large: {e}"),
Ok(_) => panic!("a blend that runs into another was accepted"),
}
}
/// The pocketed block's volume: 16000 less the 1000 mm³ pocket.
const POCKETED: f64 = 15000.0;
/// The 6 mm chamfer runs 2 mm past the pocket's rim at x = 36: its triangle
/// (40 − x) + (20 − z) <= 6, area 18 along the 20 mm edge, less its part over the pocket
/// (x in [34, 36], z >= 54 − x: area 2, along the pocket's 10 mm), is cut away: 360 − 20.
#[test]
fn chamfer_into_a_pocket_is_cut_by_it() {
let p = pocketed();
let b = crate::chamfer(&p, &[EDGE], 6.0).unwrap();
assert!(b.validity().is_empty(), "{:?}", b.validity());
let v = crate::measure(&b).unwrap().volume;
assert!((v - (POCKETED - 340.0)).abs() < 1e-6, "{v}");
// Up to the pocket's rim it builds: the triangle along the 20 mm edge.
for s in [2.0, 4.0] {
let b = crate::chamfer(&p, &[EDGE], s).unwrap();
let v = b.volume_at(0.01).unwrap();
assert!((p.volume_at(0.01).unwrap() - v - 0.5 * s * s * 20.0).abs() < 1e-6, "{s}: {v}");
}
// Unequal sides, 6 along the top and 2 down the side: the triangle
// (40 − x) / 6 + (20 − z) / 2 <= 1, area 6 along 20, less its part over the pocket
// (x in [34, 36], a triangle 2 by 2/3), along 10: 120 − 20/3. The other way round it stays
// clear of the pocket: 120.
let b = crate::chamfer_sides(&p, &[EDGE], 6.0, ChamferSide::Distance(2.0), false).unwrap();
let v = crate::measure(&b).unwrap().volume;
assert!((v - (POCKETED - (120.0 - 20.0 / 3.0))).abs() < 1e-6, "{v}");
let b = crate::chamfer_sides(&p, &[EDGE], 2.0, ChamferSide::Distance(6.0), false).unwrap();
let v = crate::measure(&b).unwrap().volume;
assert!((v - (POCKETED - 120.0)).abs() < 1e-6, "{v}");
}
/// R5 runs 1 mm past the pocket's rim: the round's section (1 − π/4)·25 along 20, less its part
/// over the pocket, the square [35, 36] × [15, 20] outside the circle about (35, 15) of radius 5,
/// ∫₀¹ (5 − √(25 − t²)) dt = 5 − (√24 / 2 + (25/2)·asin(1/5)), along 10.
#[test]
fn fillet_into_a_pocket_is_cut_by_it_and_one_that_fits_builds() {
let p = pocketed();
let over = 5.0 - (24f64.sqrt() / 2.0 + 12.5 * (0.2f64).asin());
let want = POCKETED - ((1.0 - std::f64::consts::FRAC_PI_4) * 25.0 * 20.0 - over * 10.0);
let b = crate::fillet(&p, &[EDGE], 5.0).unwrap();
assert!(b.validity().is_empty(), "{:?}", b.validity());
let v = crate::measure(&b).unwrap().volume;
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
let b = crate::fillet(&p, &[EDGE], 3.0).unwrap();
assert!(b.validity().is_empty(), "{:?}", b.validity());
assert_eq!(b.face_count(), p.face_count() + 1);
}
/// A rib 4 mm wide: chamfers of its two top edges meet in the middle of its top face at 2 mm;
/// past that they would cross each other. Neither reaches the far side's face below 4 mm,
/// so only the two blends clash: refused as too large, and the largest that fits is 2 mm.
#[test]
fn chamfers_crossing_each_other_are_refused() {
let rib = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(40.0, 4.0, 20.0)).unwrap();
let edges = [Vec3::new(20.0, 0.0, 20.0), Vec3::new(20.0, 4.0, 20.0)];
too_large(crate::chamfer(&rib, &edges, 3.0));
too_large(crate::fillet(&rib, &edges, 3.0));
assert_eq!(crate::chamfer_max(&rib, &edges, 3.0).unwrap().map(|x| x.0), Some(2.0));
assert_eq!(crate::fillet_max(&rib, &edges, 3.0, crate::FilletTurn::Mitre).unwrap().map(|x| x.0), Some(2.0));
// Below half the width both build.
let b = crate::chamfer(&rib, &edges, 1.5).unwrap();
assert!((b.volume_at(0.01).unwrap() - (3200.0 - 2.0 * 0.5 * 1.5 * 1.5 * 40.0)).abs() < 1e-6);
// Two rounds of radius 1.5 along 40: each removes (1 − π/4)·1.5² of section.
let b = crate::fillet(&rib, &edges, 1.5).unwrap();
let want = 3200.0 - 2.0 * (1.0 - std::f64::consts::FRAC_PI_4) * 2.25 * 40.0;
let v = crate::measure(&b).unwrap().volume;
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
}
/// Edges meeting at a corner mitre: their chamfers overlap there and are not refused for it.
#[test]
fn chamfers_meeting_at_a_corner_still_build() {
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(20.0, 20.0, 20.0)).unwrap();
let edges = [Vec3::new(10.0, 0.0, 20.0), Vec3::new(20.0, 10.0, 20.0), Vec3::new(10.0, 20.0, 20.0), Vec3::new(0.0, 10.0, 20.0)];
// The chamfers leave the 20 x 20 x 15 block under a frustum from 20 x 20 to 10 x 10, 5 high:
// 6000 + (5/3)(400 + 100 + √(400·100)).
let v = crate::measure(&crate::chamfer(&b, &edges, 5.0).unwrap()).unwrap().volume;
let want = 6000.0 + 5.0 / 3.0 * (400.0 + 100.0 + 200.0);
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
// The rounds: (1 − π/4)·25 of section along each edge's 10 mm between the corners, and in each
// 5 mm corner cube the two cylinders' intersection is kept, ∫₀⁵ (25 − w²) dw = 250/3 of 125.
let v = crate::measure(&crate::fillet(&b, &edges, 5.0).unwrap()).unwrap().volume;
let want = 8000.0 - 4.0 * (1.0 - std::f64::consts::FRAC_PI_4) * 25.0 * 10.0 - 4.0 * (125.0 - 250.0 / 3.0);
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
}