dc38349cbf
* Kernel: the B-rep record and the native body file come from solidcore-record SolidCraft's portable B-rep record (`solidcraft_geom::brep`: brep.rs, topology, history, envelope, part, curve2) and the native body file (`solidcraft_kernel::native`: the tagged binary codec and the container) move to solidcore's `solidcore-record` crate: geometry as data, with structural validation and no maths (solidcore's docs/layers.md, stage 1). Every caller uses `solidcore_record::brep` and `solidcore_record::native`; the old copies are deleted. What computes from coordinates stays with the kernel, in geom's `brep`: - `brep::check`: the record's geometric checks (orthonormal frames, non-degenerate planes, unit revolution axes, non-singular placements). `check::validate` and `check::validate_built` are the record's validation and these together, and every caller of `Brep::validate` uses them, so what is accepted is unchanged; - `brep::label`: a surface's natural ranges (a cone's apex), `curve_interval`, `edge_curve_interval` and `form_turns`; - `brep::pcurve::eval`: a pcurve's point; - `geometry::check`, `placement::moved` and `split_edges` become functions on the record. The kernel's native module keeps the conversion between a body and its saved record (metadata.rs) and checks the decoded record's geometry. `native/analytic.rs`, which no module declared, is deleted. solidcore-record is pinned to its rev on solidcore's `layer-record` branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT * Geometry: Vec2, Vec3, Plane and the profile types come from solidcore-record The plain data of vectors and points, sketch planes and planar profiles (`Seg2`, `Loop2`, `Region2`) moves to `solidcore-record`, with its constants and component-wise operators only (owner decision, solidcore layer split). Their geometry stays in geom as traits: `Vec2Geom`, `Vec3Geom`, `PlaneGeom`, `Seg2Geom`, `Loop2Geom`, `Region2Geom`, `Seg2ArcFit`, `Loop2ArcFit` and `Region2ArcFit`, in scope with `use solidcraft_geom::prelude::*`. Every caller names the types from `solidcore_record`; geom no longer defines or re-exports them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT * Kernel: pin solidcore-record to solidcore main f5e8e9a29 solidcore-record is merged on solidcore main (tangency-labs/solidcore#2519); its crate there is identical to the rev pinned before but for its clippy configuration. The lock is regenerated against the merged rev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT --------- Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
4.4 KiB
Rust
77 lines
4.4 KiB
Rust
use solidcore_record::Vec3;
|
|
use solidcraft_geom::prelude::*;
|
|
|
|
use crate::*;
|
|
|
|
/// The 60 x 40 x 20 box with r5 rounds on the three edges at (60, 40, 20).
|
|
fn corner_case(setback: Option<f64>) -> Result<Body> {
|
|
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(60.0, 40.0, 20.0)).unwrap();
|
|
let edges = [Vec3::new(30.0, 40.0, 20.0), Vec3::new(60.0, 20.0, 20.0), Vec3::new(60.0, 40.0, 10.0)];
|
|
match setback {
|
|
Some(s) => fillet_setback(&b, &edges, 5.0, &[(Vec3::new(60.0, 40.0, 20.0), s)]),
|
|
None => fillet(&b, &edges, 5.0),
|
|
}
|
|
}
|
|
|
|
/// Set back 8 along each edge: outside the corner cube [52, 60] x [32, 40] x [12, 20] the body
|
|
/// is the sphere corner's, and inside it the convex body holds the hull of its points on the
|
|
/// cube's faces (299.0201) and lies within the three rounds' prisms (512 - 225 (1 - pi/4) -
|
|
/// 125 (sqrt 2 - 1)); see capi/tests/ops_kernel.cpp, corner_setback. The patch is SMLib's two
|
|
/// quadrilaterals per side: 15 faces, 36 edges, 23 vertices; the box stays the box.
|
|
#[test]
|
|
fn a_corner_set_back_8_blends_through_a_larger_patch() {
|
|
let pi = std::f64::consts::PI;
|
|
let sphere = measure(&corner_case(None).unwrap()).unwrap().volume;
|
|
let out = corner_case(Some(8.0)).unwrap();
|
|
assert!(out.validity().is_empty(), "{:?}", out.validity());
|
|
let m = measure(&out).unwrap();
|
|
let in_c_sphere = 512.0 - 225.0 * (1.0 - pi / 4.0) - 125.0 * (1.0 - pi / 6.0);
|
|
let prisms = 512.0 - 225.0 * (1.0 - pi / 4.0) - 125.0 * (2f64.sqrt() - 1.0);
|
|
let outside = sphere - in_c_sphere;
|
|
assert!(m.volume > outside + 299.0201 && m.volume < outside + prisms, "{} not in [{}, {}]", m.volume, outside + 299.0201, outside + prisms);
|
|
assert_eq!((m.faces, m.edges, m.vertices), (15, 36, 23));
|
|
assert!((m.bbox.min - Vec3::new(0.0, 0.0, 0.0)).len() < 1e-6 && (m.bbox.max - Vec3::new(60.0, 40.0, 20.0)).len() < 1e-6, "{:?}", m.bbox);
|
|
}
|
|
|
|
/// A setback point at no vertex, at a corner where no edge is rounded, or as long as an edge
|
|
/// there, is refused.
|
|
#[test]
|
|
fn a_setback_off_the_rounded_corner_is_refused() {
|
|
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(60.0, 40.0, 20.0)).unwrap();
|
|
let edges = [Vec3::new(30.0, 40.0, 20.0), Vec3::new(60.0, 20.0, 20.0), Vec3::new(60.0, 40.0, 10.0)];
|
|
assert!(fillet_setback(&b, &edges, 5.0, &[(Vec3::new(30.0, 20.0, 10.0), 8.0)]).is_err());
|
|
assert!(fillet_setback(&b, &edges, 5.0, &[(Vec3::new(0.0, 0.0, 0.0), 8.0)]).is_err());
|
|
assert!(matches!(corner_case(Some(20.0)), Err(KernelError::TooLarge(_))));
|
|
}
|
|
|
|
/// A setback that does not reach past where the corner's rounds meet without one (on faces square
|
|
/// to each other, the radius) is refused before SMLib runs, naming that least setback. Past it, a
|
|
/// setback still too short for the corner fill (certified convex only from a setback on, as SMLib
|
|
/// f916a8d's setback corner does) is refused naming the smallest that builds,
|
|
/// at most twice the one asked for (the certificate scales the setbacks up to 2); that one builds.
|
|
#[test]
|
|
fn a_setback_not_past_the_radius_is_refused_naming_the_least() {
|
|
for s in [2.0, 5.0] {
|
|
match corner_case(Some(s)) {
|
|
Err(KernelError::Invalid(why)) => assert!(why.contains("setback must be more than the radius (5 mm)"), "{why}"),
|
|
other => panic!("setback {s}: {:?}", other.map(|b| b.face_count())),
|
|
}
|
|
}
|
|
let least = match corner_case(Some(5.5)) {
|
|
Err(KernelError::Invalid(why)) => {
|
|
let named = why.split_once(SETBACK_AT_LEAST).and_then(|(_, rest)| rest.split_once(" mm")).and_then(|(n, _)| n.parse::<f64>().ok());
|
|
named.unwrap_or_else(|| panic!("no least setback named: {why}"))
|
|
}
|
|
other => panic!("setback 5.5: {:?}", other.map(|b| b.face_count())),
|
|
};
|
|
eprintln!("setback 5.5 refused: the smallest that builds is {least}");
|
|
assert!(least > 5.5 && least <= 11.0, "{least}");
|
|
let out = corner_case(Some(least)).unwrap();
|
|
assert!(out.validity().is_empty(), "{:?}", out.validity());
|
|
// The least the refusal names, for a form to show before it runs; none at no vertex.
|
|
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(60.0, 40.0, 20.0)).unwrap();
|
|
let least = crate::fillet_least_setback(&b, Vec3::new(60.0, 40.0, 20.0), 5.0).unwrap();
|
|
assert!(least.is_some_and(|l| (l - 5.0).abs() < 1e-9), "{least:?}");
|
|
assert_eq!(crate::fillet_least_setback(&b, Vec3::new(30.0, 20.0, 10.0), 5.0).unwrap(), None);
|
|
}
|