Files
makeCAD/crates/engine/src/tests/blend_fit.rs
T
brett19 8a730c6273 Fillets on solidcore: the largest size that fits is still the one the search builds; the kernel's names the edge
solidcore's fit is the largest size less a margin (34.99 where the L bracket's bend builds 35,
4.29 where #3435's ring builds 4.3), so the feature's search keeps naming the size, and solidcore's
is the answer only where the search finds none. The refusal keeps its words, "larger than the
faces beside its edges allow", with the edge after them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SdcgEu4Lr3moCCisdZShKz
2026-11-02 20:13:26 -05:00

80 lines
4.0 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: a fillet or chamfer running past the faces beside its edge into an opening is built
//! as if the faces went on and cut by the opening (the blend-overflow decision, 237f0ae74), so it
//! never bridges it; one that stops short builds as it always did.
use std::path::Path;
use serde_json::json;
use super::{run, volume};
use crate::Session;
fn open_fixture() -> Session {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/tests/fixtures/cubeish-chamfer-too-large.sc");
let mut s = Session::default();
run(&mut s, "doc.open", json!({"path": path.to_string_lossy()}));
s
}
fn chamfer_error(s: &Session) -> Option<String> {
s.model.results.iter().find(|r| r.name == "Chamfer1").and_then(|r| r.error.clone())
}
/// The report's design: a 20 mm cube with a 10 mm square opening into each of three faces,
/// then a 9 mm chamfer on the top edge over one side opening. The openings are 5 mm from the
/// edge, so the chamfer runs over their rims: it is cut by them. Of its section, the triangle
/// y + (20 − z) <= 9 (area 40.5, along 20: 810), the two openings crossing it hold 80 each
/// (the rig's fillets/1080-chamfer-runs-into-openings-cut-by-them): 4000 − (810 − 160) = 3350.
#[test]
fn chamfer_through_the_openings_is_cut_by_them() {
let mut s = open_fixture();
assert_eq!(chamfer_error(&s), None);
assert!((volume(&mut s) - 3350.0).abs() < 1e-6, "{}", volume(&mut s));
}
/// Sizes that stop short of the openings build, and take away exactly the chamfer's triangle
/// along the 20 mm edge.
#[test]
fn chamfer_that_fits_still_builds() {
let mut s = open_fixture();
for d in [4.0, 5.0] {
run(&mut s, "timeline.edit", json!({"feature": "Chamfer1", "set": {"distance": format!("{d} mm")}}));
assert_eq!(chamfer_error(&s), None, "{d} mm fits");
let want = 4000.0 - 0.5 * d * d * 20.0;
assert!((volume(&mut s) - want).abs() < 1e-6, "{d} mm: {} (want {want})", volume(&mut s));
}
}
/// #199's bar, 14 x 6 x 10, its four upright edges rounded: past a full round of its 6 mm ends
/// the two rounds on each end would cross. Refused, naming 3 mm; on solidcore the kernel's refusal
/// carries a size and the edge it was found for (`SolidError::FilletRefused`), and the message
/// names the edge.
#[test]
fn a_round_past_a_full_round_is_refused_naming_the_largest_that_fits_and_its_edge() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 14, "width": 6, "height": 10, "corner": [14, 0, 0]}));
let uprights = json!([[14, 0, 5], [28, 0, 5], [14, 6, 5], [28, 6, 5]]);
let on_solidcore = solidcraft_kernel::kernel_route::backend() == solidcraft_kernel::kernel_route::Backend::Solidcore;
for r in [3.001, 3.5] {
let e = s.execute("solid.fillet", &json!({"edges": uprights, "radius": r})).unwrap_err().to_string();
assert!(e.contains("the largest radius that fits is 3 mm"), "{r}: {e}");
assert!(!on_solidcore || e.contains("allow, at the edge at ("), "{r}: {e}");
assert_eq!(e.matches("that fits is").count(), 1, "{r}: {e}");
}
assert!((volume(&mut s) - 840.0).abs() < 1e-6, "the part stays as it was");
}
/// A rib 4 mm wide: blends of its two top edges meet in its top's middle at 2 mm and past that
/// would cross each other. Refused as too large, naming the largest size that fits.
#[test]
fn blends_crossing_each_other_are_refused_naming_the_largest_that_fits() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 40, "width": 4, "height": 20}));
let edges = json!([[20, 0, 20], [20, 4, 20]]);
let e = s.execute("solid.chamfer", &json!({"edges": edges, "distance": 3})).unwrap_err().to_string();
assert!(e.contains("the largest distance that fits is 2 mm"), "{e}");
let e = s.execute("solid.fillet", &json!({"edges": edges, "radius": 3})).unwrap_err().to_string();
assert!(e.contains("the largest radius that fits is 2 mm"), "{e}");
assert!((volume(&mut s) - 3200.0).abs() < 1e-6, "the part stays as it was");
}