Files
solidcraft/crates/kernel/src/record.rs
T
dc38349cbf Layer split stage 1: the B-rep record, native body file and Vec/Plane come from solidcore-record (#11496)
* 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>
2026-11-03 09:04:26 -05:00

115 lines
5.7 KiB
Rust

//! Recording the exact history of the bodies operations build on the schema 4 record: for each
//! result face, what it is made from (operand faces it is the whole of or a piece of, profile
//! segments, caps, operand edges a blend replaces); for each result edge, the operand edges it is
//! or is a piece of, and otherwise the meeting of the two faces it separates. Indices are the
//! records' canonical ones, the result's and each operand's. Nothing is sampled: the building
//! code says what it built from what. Profile segments are numbered by [`crate::numbered`].
use std::collections::BTreeSet;
use solidcore_record::brep::Brep;
use crate::body::Body;
use crate::history::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History, edge_faces};
/// A face made from all of profile segments `numbers` (in any order, repeats allowed).
pub(crate) fn profile<'a>(numbers: impl IntoIterator<Item = &'a usize>) -> FaceProv {
let numbers: BTreeSet<usize> = numbers.into_iter().copied().collect();
generated(numbers.into_iter().map(|segment| FaceOrigin::Profile { segment }).collect())
}
/// A face of operand `operand` and how this one relates to it.
pub(crate) fn from_face(operand: usize, face: usize, change: Change) -> FaceProv {
FaceProv { origins: vec![FaceOrigin::Face { operand, face }], change }
}
/// Every face of the one operand (with `count` faces) but `except`, kept as it is, in order:
/// the faces a builder carries over unchanged when it rebuilds a body around one face.
pub(crate) fn kept_except(count: usize, except: usize) -> impl Iterator<Item = FaceProv> {
(0..count).filter(move |i| *i != except).map(|i| from_face(0, i, Change::Kept))
}
/// A start (`end == false`) or end cap.
pub(crate) fn cap(end: bool) -> FaceProv {
generated(vec![FaceOrigin::Cap { end }])
}
/// A face new to the operation, made from `origins`.
pub(crate) fn generated(origins: Vec<FaceOrigin>) -> FaceProv {
FaceProv { origins, change: Change::Generated }
}
pub(crate) use solidcore_record::brep::history::mark_shared_split;
/// The origins of a result edge that is (a piece of, or the moved) edges `edges` of operand
/// `operand`.
pub(crate) fn pieces_of(operand: usize, edges: impl IntoIterator<Item = usize>) -> Vec<EdgeOrigin> {
let edges: BTreeSet<usize> = edges.into_iter().collect();
edges.into_iter().map(|edge| EdgeOrigin::Edge { operand, edge }).collect()
}
/// The history over `operands` operands of `result`, whose faces (in its face order) come from
/// `faces` (an operand face shared by several result faces is marked Split), and whose edges come
/// from `edges` (by result edge index) where the building code knows them: an operand edge it
/// kept or re-made ([`pieces_of`]). Every other edge separates two faces that met nowhere before,
/// so it comes from their meeting ([`meeting`]); an operation with no operands (a body built
/// from a sketch) makes every face and edge new, so its edges have no origins.
pub(crate) fn of_faces(result: &Brep, operands: usize, mut faces: Vec<FaceProv>, edges: &[Vec<EdgeOrigin>]) -> History {
mark_shared_split(&mut faces);
let edges = edge_faces(result)
.into_iter()
.enumerate()
.map(|(i, between)| {
let origins = match edges.get(i) {
Some(known) if !known.is_empty() => known.clone(),
_ if operands == 0 => Vec::new(),
_ => meeting(&between, &faces),
};
EdgeProv { faces: between, origins }
})
.collect();
History { operands, faces, edges }
}
/// `body`, made from operands with these face and edge `counts`, with the history [`of_faces`]
/// gives (none where the faces could not be followed, `None`, or the history does not describe
/// the body: an operation whose history could not be recorded still gives its result).
pub(crate) fn attach(body: Body, counts: &[(usize, usize)], faces: Option<Vec<FaceProv>>, edges: &[Vec<EdgeOrigin>]) -> Body {
let history = faces.map(|faces| of_faces(body.record(), counts.len(), faces, edges));
body.with_checked_history(history, counts)
}
/// The face and edge counts of `bodies`, for [`traced`].
pub(crate) fn counts(bodies: &[&Body]) -> Vec<(usize, usize)> {
bodies.iter().map(|b| (b.face_count(), b.edge_count())).collect()
}
/// `step`, made from `prev` (the step's one operand), with its history carried back to what
/// `prev` was made from: the operation's operands, with `counts` faces and edges. A multi-step
/// operation starts from its operand with [`crate::boolean_record::operand`] (or healed, see
/// [`crate::boolean_record::healed`]) and takes each step's result through this.
pub(crate) fn after(mut step: Body, prev: &Body, counts: &[(usize, usize)]) -> Body {
let own = step.history.take().map(std::sync::Arc::unwrap_or_clone);
let h = own.zip(prev.history()).and_then(|(h, inner)| crate::boolean_record::composed(h.substituted(0, inner)));
step.with_checked_history(h, counts)
}
/// The origins of a new edge between the result faces `between` (whose provenance is in
/// `faces`): the meeting of the two faces (each side all of its face's origins, one or
/// several), when each comes from something and no origin is under both; else none (a seam,
/// an edge between pieces of one face, a face new to the operation).
pub(crate) fn meeting(between: &[usize], faces: &[FaceProv]) -> Vec<EdgeOrigin> {
let side = |f: &usize| faces.get(*f).and_then(|p| crate::history::Side::new(p.origins.iter().copied()));
match between {
[f, g] => match (side(f), side(g)) {
(Some(a), Some(b)) if a.origins().iter().all(|o| !b.origins().contains(o)) => vec![EdgeOrigin::meet(a, b)],
_ => Vec::new(),
},
_ => Vec::new(),
}
}
#[cfg(test)]
#[path = "record_tests.rs"]
mod tests;