* 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>
97 lines
4.1 KiB
Rust
97 lines
4.1 KiB
Rust
//! Issue #2005: a closed sweep must join its end back to its start, without coincident caps.
|
|
//! The capped tool used to stall or fail when cutting the torus it lay inside.
|
|
|
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
|
|
use std::f64::consts::{FRAC_PI_2, PI, TAU};
|
|
|
|
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
|
|
|
|
use crate::{Body, BoolOp, PathSeg, SweepControl, boolean, measure, sweep_with};
|
|
|
|
fn square(half: f64) -> Region2 {
|
|
Region2 {
|
|
outer: Loop2::polygon(&[Vec2::new(-half, -half), Vec2::new(half, -half), Vec2::new(half, half), Vec2::new(-half, half)]),
|
|
holes: vec![],
|
|
}
|
|
}
|
|
|
|
fn profile_plane() -> Plane {
|
|
Plane { origin: Vec3::new(30.0, 0.0, 0.0), x: Vec3::X, y: Vec3::Z }
|
|
}
|
|
|
|
fn circle_path() -> [PathSeg; 2] {
|
|
// A sketch circle reaches the kernel as two half arcs.
|
|
[
|
|
PathSeg::Arc { a: Vec3::new(30.0, 0.0, 0.0), center: Vec3::ZERO, axis: Vec3::Z, angle: PI },
|
|
PathSeg::Arc { a: Vec3::new(-30.0, 0.0, 0.0), center: Vec3::ZERO, axis: Vec3::Z, angle: PI },
|
|
]
|
|
}
|
|
|
|
fn tube(body: &Body, volume: f64, genus: usize) {
|
|
let m = measure(body).unwrap();
|
|
assert!((m.volume - volume).abs() < volume * 0.01, "{m:?}, expected {volume}");
|
|
// A closed orientable tube of genus g: V - E + F - (L - F) = 2 - 2g (Euler-Poincare, L the
|
|
// loops: an annular face has two). Coincident caps gave 2 - 2g + 2.
|
|
let loops: usize = body.record().faces.iter().map(|f| f.loops.len()).sum();
|
|
assert_eq!(m.vertices + 2 * m.faces + 2 * genus, m.edges + loops + 2, "{m:?}, {loops} loops");
|
|
// Every shell closed: each edge bounds two faces.
|
|
assert!(body.record().edges.iter().all(|e| e.uses.len() >= 2));
|
|
let h = body.history().expect("sweep provenance");
|
|
assert!(h.faces.iter().all(|f| f.origins.iter().all(|o| matches!(o, crate::history::FaceOrigin::Profile { .. }))));
|
|
}
|
|
|
|
#[test]
|
|
fn closed_circle_sweeps_have_no_caps() {
|
|
for twist in [0.0, FRAC_PI_2, PI, TAU, -PI] {
|
|
let ctl = SweepControl { twist, ..SweepControl::default() };
|
|
let b = sweep_with(&profile_plane(), &square(4.0), &circle_path(), &ctl).unwrap();
|
|
tube(&b, 64.0 * TAU * 30.0, 1);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn one_full_arc_closes_like_a_sketch_circle() {
|
|
for angle in [TAU, -TAU] {
|
|
let path = [PathSeg::Arc { a: Vec3::new(30.0, 0.0, 0.0), center: Vec3::ZERO, axis: Vec3::Z, angle }];
|
|
let b = sweep_with(&profile_plane(), &square(4.0), &path, &SweepControl::default()).unwrap();
|
|
tube(&b, 64.0 * TAU * 30.0, 1);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn closed_polyline_sweep_shares_its_starting_section() {
|
|
let path = crate::path_polyline(&circle_path()).unwrap();
|
|
let b = crate::sweep_path(&profile_plane(), &square(4.0), &path).unwrap();
|
|
tube(&b, 64.0 * TAU * 30.0, 1);
|
|
}
|
|
|
|
#[test]
|
|
fn closed_sweep_refuses_an_end_section_that_does_not_match() {
|
|
for ctl in [SweepControl { twist: PI / 4.0, ..SweepControl::default() }, SweepControl { scale: 2.0, ..SweepControl::default() }] {
|
|
let err = sweep_with(&profile_plane(), &square(4.0), &circle_path(), &ctl).unwrap_err();
|
|
assert!(err.to_string().contains("closed path"), "{err}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn closed_holed_sweep_joins_every_loop() {
|
|
let region = Region2 { holes: vec![square(2.0).outer], ..square(4.0) };
|
|
let ctl = SweepControl { twist: PI, ..SweepControl::default() };
|
|
let b = sweep_with(&profile_plane(), ®ion, &circle_path(), &ctl).unwrap();
|
|
// Two disjoint toroidal shells, one bounding the cavity.
|
|
let m = measure(&b).unwrap();
|
|
assert!((m.volume - 48.0 * TAU * 30.0).abs() < m.volume * 0.02, "{m:?}");
|
|
assert_eq!(m.vertices + m.faces, m.edges, "{m:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn half_turn_sweep_cuts_a_torus() {
|
|
let base = crate::torus(Vec3::ZERO, 30.0, 8.0).unwrap();
|
|
let tool = sweep_with(&profile_plane(), &square(4.0), &circle_path(), &SweepControl { twist: PI, ..SweepControl::default() }).unwrap();
|
|
let result = boolean(&base, &tool, BoolOp::Cut).unwrap().expect("cut leaves the torus wall");
|
|
let expected = (PI * 64.0 - 64.0) * TAU * 30.0;
|
|
let m = measure(&result).unwrap();
|
|
assert!((m.volume - expected).abs() < expected * 0.015, "{m:?}, expected {expected}");
|
|
}
|