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>
This commit is contained in:
jyviko
2026-11-03 09:04:26 -05:00
committed by GitHub
parent bd2dc3fade
commit dc38349cbf
806 changed files with 4281 additions and 6434 deletions
+8 -6
View File
@@ -10,11 +10,13 @@
//! and holes clockwise there; [`Assembly::finish`] stores them relative to the surface's natural
//! normal, as the record does.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::pcurve::{EdgeUse, pcurves_within};
use solidcraft_geom::brep::{
Brep, Curve, Curve2, Edge, Face, Frame, Loop, Natural, OrientedEdge, OrientedFace, Region, Shell, Surface, VERSION, Vertex, form,
use solidcore_record::Vec3;
use solidcore_record::brep::{
Brep, Curve, Curve2, Edge, Face, Frame, Loop, Natural, OrientedEdge, OrientedFace, Region, Shell, Surface, VERSION, Vertex,
};
use solidcraft_geom::brep::form;
use solidcraft_geom::brep::pcurve::{EdgeUse, pcurves_within};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::history::{EdgeOrigin, FaceProv};
@@ -244,7 +246,7 @@ impl Assembly {
let loose =
Brep { version: VERSION, tolerance: self.tolerance, regions, shells, faces, edges: edges.collect(), vertices: self.vertices.clone() };
let part = loose.canonical().map_err(invalid)?;
part.brep.check_geometry().map_err(invalid)?;
solidcraft_geom::brep::geometry::check(&part.brep).map_err(invalid)?;
let mut face_map: Vec<Option<usize>> = vec![None; self.faces.len()];
for (c, &k) in part.faces.iter().enumerate() {
if let Some(slot) = kept.get(k as usize).and_then(|i| face_map.get_mut(*i)) {
@@ -422,7 +424,7 @@ fn domain_of(surface: &Surface, pcurves: &[Vec<Curve2>], kept: Option<[[f64; 2];
}
}
}
let natural = surface.natural();
let natural = solidcraft_geom::brep::label::surface_natural(surface);
let mut out = [[0.0; 2]; 2];
for d in 0..2 {
let (mut a, mut b) = (*lo.get(d)?, *hi.get(d)?);
+4 -3
View File
@@ -7,11 +7,12 @@
//! The helpers here read a body's schema 4 record: planar faces' outward normals, the direction
//! into a face across an edge, an edge's tangent at its ends.
use solidcraft_geom::prelude::*;
use std::collections::BTreeSet;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcore_record::brep::{Brep, Curve, Loop, OrientedEdge, Shell, Surface};
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::brep::{Brep, Curve, Loop, OrientedEdge, Shell, Surface};
use crate::body::Body;
use crate::{KernelError, Result};
@@ -1138,7 +1139,7 @@ pub(crate) fn with_continuation(e: KernelError, next: Option<Vec3>) -> KernelErr
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
/// A round (`round`) or an equal-distance chamfer of the edges nearest `pts`.
fn blend(body: &Body, pts: &[Vec3], size: f64, round: bool) -> Result<Body> {
+4 -3
View File
@@ -15,7 +15,7 @@
use std::collections::BTreeSet;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::body::Body;
use crate::history::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History};
@@ -271,6 +271,7 @@ mod tests {
use crate::blend::Faces;
use crate::{box_solid, fillet, measure};
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::prelude::*;
/// The 20 mm box and the three edges at its corner (20, 0, 20): `a` along y, `b` along x,
/// `c` up.
@@ -551,7 +552,7 @@ mod tests {
#[test]
fn sloped_basin_rim_fillets() {
use solidcraft_geom::{Loop2, Plane, Vec2};
use solidcore_record::{Loop2, Plane, Vec2};
let rectangle = |x0, y0, x1, y1| Loop2::polygon(&[Vec2::new(x0, y0), Vec2::new(x1, y0), Vec2::new(x1, y1), Vec2::new(x0, y1)]);
let slab = box_solid(Vec3::ZERO, Vec3::new(100.0, 60.0, 30.0)).unwrap();
let pocket =
@@ -588,7 +589,7 @@ mod tests {
/// each piece: 375.673069 taken from V0 = 140333.333333 (the prismatoid), 139957.660264.
#[test]
fn a_rim_loop_chamfer_running_off_its_rim_builds() {
use solidcraft_geom::{Loop2, Plane, Vec2};
use solidcore_record::{Loop2, Plane, Vec2};
let rectangle = |x0, y0, x1, y1| Loop2::polygon(&[Vec2::new(x0, y0), Vec2::new(x1, y0), Vec2::new(x1, y1), Vec2::new(x0, y1)]);
let slab = box_solid(Vec3::ZERO, Vec3::new(100.0, 60.0, 30.0)).unwrap();
let pocket =
+4 -3
View File
@@ -13,7 +13,7 @@
//! The history is SMLib's tags, renumbered into the body's orders; a blend face, which SMLib
//! leaves untagged, comes from the edge it replaces ([`solidcraft_smlib::history::blends`]).
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::blend_variable::RadiusSpline;
use crate::body::Body;
@@ -111,9 +111,10 @@ enum Kind {
}
mod imp {
use solidcraft_geom::prelude::*;
use std::collections::BTreeSet;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_smlib::{Blend, Brep, ChamferSecond, CheckLevel, Error as SmError};
use super::Kind;
@@ -562,7 +563,7 @@ mod imp {
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use super::*;
use crate::history::{Change, FaceOrigin};
+5 -4
View File
@@ -5,8 +5,9 @@
//! two planar faces the band a radius law takes from the faces is checked against the faces
//! first, which also gives a [`taper`] its room along the edge.
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::prelude::*;
use crate::blend::{Faces, too_large, unsupported};
use crate::body::Body;
@@ -504,8 +505,8 @@ mod tests {
f.loops
.iter()
.map(|l| match l {
solidcraft_geom::brep::Loop::Edges { edges } => edges.len(),
solidcraft_geom::brep::Loop::Vertex { .. } => 0,
solidcore_record::brep::Loop::Edges { edges } => edges.len(),
solidcore_record::brep::Loop::Vertex { .. } => 0,
})
.sum()
})
@@ -651,7 +652,7 @@ mod tests {
/// A prism of the polygon `pts` (in xy) from z = `z0` to `z1`.
fn prism_between(pts: &[(f64, f64)], z0: f64, z1: f64) -> Body {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let outer = Loop2::polygon(&pts.iter().map(|(x, y)| Vec2::new(*x, *y)).collect::<Vec<_>>());
crate::extrude(&Plane::XY, &[Region2 { outer, holes: vec![] }], z0, z1).unwrap().pop().unwrap()
}
+2 -1
View File
@@ -1,4 +1,5 @@
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::*;
+27 -25
View File
@@ -1,6 +1,8 @@
use serde::Serialize;
use solidcraft_geom::brep::{self, Brep, Curve, Loop, Shell, Surface};
use solidcraft_geom::{Aabb3, Mesh, Vec3};
use solidcore_record::Vec3;
use solidcore_record::brep::{self, Brep, Curve, Loop, Shell, Surface};
use solidcraft_geom::prelude::*;
use solidcraft_geom::{Aabb3, Mesh};
use crate::history::BodyHistory;
use crate::{KernelError, Result, guard};
@@ -147,7 +149,7 @@ fn placed_mesh(m: &Mesh, t: &[[f64; 4]; 4]) -> Option<Mesh> {
t[0][2] * v.x + t[1][2] * v.y + t[2][2] * v.z + w * t[3][2],
)
};
brep::placement::Rigid::of_matrix(t)?;
solidcraft_geom::brep::placement::Rigid::of_matrix(t)?;
Some(Mesh {
positions: m.positions.iter().map(|p| r(*p, 1.0)).collect(),
normals: m.normals.iter().map(|n| r(*n, 0.0)).collect(),
@@ -159,20 +161,20 @@ fn placed_mesh(m: &Mesh, t: &[[f64; 4]; 4]) -> Option<Mesh> {
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum FaceSource {
ExtrudeSide {
segment: solidcraft_geom::Seg2,
plane: Option<solidcraft_geom::Plane>,
segment: solidcore_record::Seg2,
plane: Option<solidcore_record::Plane>,
coalesced: bool,
},
CertifiedExtrudeSide {
producer: u64,
sketch: u64,
curve: String,
plane: Option<solidcraft_geom::Plane>,
plane: Option<solidcore_record::Plane>,
},
ExtrudeCap {
high: bool,
region: solidcraft_geom::Region2,
plane: solidcraft_geom::Plane,
region: solidcore_record::Region2,
plane: solidcore_record::Plane,
},
CertifiedExtrudeCap {
producer: u64,
@@ -180,25 +182,25 @@ pub enum FaceSource {
high: bool,
outer: Vec<String>,
holes: Vec<Vec<String>>,
plane: solidcraft_geom::Plane,
plane: solidcore_record::Plane,
},
Box {
producer: Option<u64>,
axis: u8,
high: bool,
plane: solidcraft_geom::Plane,
plane: solidcore_record::Plane,
},
/// A cylinder primitive's cap: `high` at the far end (its `top`), else at the base.
CylinderCap {
producer: u64,
high: bool,
plane: solidcraft_geom::Plane,
plane: solidcore_record::Plane,
},
ShellPlanar {
producer: Option<u64>,
source: Box<FaceSource>,
inner: bool,
plane: solidcraft_geom::Plane,
plane: solidcore_record::Plane,
},
Imported {
item: u64,
@@ -212,7 +214,7 @@ pub type CapSignature = (Vec<String>, Vec<Vec<String>>);
type FaceSources = std::sync::Arc<Vec<Option<FaceSource>>>;
impl FaceSource {
fn plane_mut(&mut self) -> Option<&mut solidcraft_geom::Plane> {
fn plane_mut(&mut self) -> Option<&mut solidcore_record::Plane> {
match self {
Self::ExtrudeSide { plane, .. } | Self::CertifiedExtrudeSide { plane, .. } => plane.as_mut(),
Self::ExtrudeCap { plane, .. }
@@ -361,7 +363,7 @@ fn coarse_tolerance(span: f64) -> f64 {
fn span_of(record: &Brep) -> f64 {
let mut bounds: Aabb3 = record.vertices.iter().map(|v| v3(v.point)).collect();
for e in &record.edges {
if let Ok(c) = brep::eval::CurveEval::new(e.parameters()) {
if let Ok(c) = solidcraft_geom::brep::eval::CurveEval::new(e.parameters()) {
let [t0, t1] = e.interval;
for i in 1..4 {
if let Some(p) = c.point(t0 + (t1 - t0) * f64::from(i) / 4.0)
@@ -389,7 +391,7 @@ fn same_shared<T: PartialEq>(a: &Option<std::sync::Arc<T>>, b: &Option<std::sync
/// canonical order) and at least one face. A solid's faces bound material; a surface body's lie
/// in open shells.
fn solid_record(record: Brep) -> Result<Brep> {
record.validate_built().map_err(|e| KernelError::Invalid(e.to_string()))?;
solidcraft_geom::brep::check::validate_built(&record).map_err(|e| KernelError::Invalid(e.to_string()))?;
if record.faces.is_empty() {
return Err(KernelError::Failed("empty result".into()));
}
@@ -467,8 +469,8 @@ impl Refusal {
}
impl SurfaceKind {
pub(crate) fn of(surface: &solidcraft_geom::brep::Surface) -> SurfaceKind {
use solidcraft_geom::brep::Surface as S;
pub(crate) fn of(surface: &solidcore_record::brep::Surface) -> SurfaceKind {
use solidcore_record::brep::Surface as S;
match surface {
S::Plane { .. } | S::PlaneThrough { .. } => SurfaceKind::Plane,
S::Cylinder { .. } => SurfaceKind::Cylinder,
@@ -714,7 +716,7 @@ impl Body {
}
/// An exact construction/import plane; never inferred from tessellation.
pub fn face_plane(&self, index: usize) -> Option<solidcraft_geom::Plane> {
pub fn face_plane(&self, index: usize) -> Option<solidcore_record::Plane> {
if index >= 50_000 {
return None;
}
@@ -732,7 +734,7 @@ impl Body {
/// Exact current planar surface for an explicitly fixed snapshot, without source lineage: the
/// face's plane as the face faces (out of the material in a closed shell).
pub fn planar_face(&self, index: usize) -> Option<solidcraft_geom::Plane> {
pub fn planar_face(&self, index: usize) -> Option<solidcore_record::Plane> {
let face = self.record.faces.get(index)?;
let (o, u, v) = match &face.surface {
Surface::Plane { origin, u_axis, v_axis } => (v3(*origin), v3(*u_axis), v3(*v_axis)),
@@ -743,7 +745,7 @@ impl Body {
_ => return None,
};
let v = if self.face_forward(index) { v } else { -v };
solidcraft_geom::Plane::new(o, u, v)
solidcore_record::Plane::new(o, u, v)
}
/// Certify the two caps of a body built by [`crate::cylinder`]. Its wall stays uncertified.
@@ -853,7 +855,7 @@ impl Body {
let mut sources = sources.as_ref().clone();
for source in sources.iter_mut().flatten() {
if let Some(plane) = source.plane_mut() {
*plane = solidcraft_geom::Plane::new(
*plane = solidcore_record::Plane::new(
vector(plane.origin) + translation,
vector(plane.x),
vector(plane.y) * if reflected { -1. } else { 1. },
@@ -1139,7 +1141,7 @@ impl Body {
// A placed copy is planned as its original, moved (as `Body::mesh` shows the original's
// mesh): the part is planned once for every copy.
if let Some((shared, m)) = self.display_of.as_deref()
&& brep::placement::Rigid::of_matrix(m).is_some()
&& solidcraft_geom::brep::placement::Rigid::of_matrix(m).is_some()
{
return Ok(remembered(&shared.plans, t, || shared.original.mesh_plan_untimed(t))?.transformed(m));
}
@@ -1298,7 +1300,7 @@ impl Body {
/// B-spline it is, for a sketch to project them. `None` for an edge that doesn't lie in a
/// plane parallel to `plane`, isn't read exactly or isn't there, and for every edge of a mesh
/// body.
pub fn planar_edges(&self, plane: &solidcraft_geom::Plane, indices: &[usize]) -> Vec<Option<Vec<crate::PlanarPiece>>> {
pub fn planar_edges(&self, plane: &solidcore_record::Plane, indices: &[usize]) -> Vec<Option<Vec<crate::PlanarPiece>>> {
if self.is_mesh() {
return vec![None; indices.len()];
}
@@ -1531,7 +1533,7 @@ impl Body {
/// rest at the evaluator's points (capped).
fn edge_points(e: &brep::Edge, chord: f64) -> Result<Vec<Vec3>> {
const MAX_POINTS: usize = 4096;
let curve = brep::eval::CurveEval::new(e.parameters()).map_err(|err| KernelError::Invalid(err.to_string()))?;
let curve = solidcraft_geom::brep::eval::CurveEval::new(e.parameters()).map_err(|err| KernelError::Invalid(err.to_string()))?;
let [t0, t1] = e.interval;
let at = |t: f64| curve.point(t).ok_or_else(|| KernelError::Invalid(format!("edge curve has no point at {t}")));
if let Curve::Line { .. } = e.curve {
@@ -1559,7 +1561,7 @@ fn edge_points(e: &brep::Edge, chord: f64) -> Result<Vec<Vec3>> {
fn curve_hull(c: &Curve, interval: [f64; 2], b: &mut Aabb3) {
match c {
Curve::Line { .. } | Curve::Circle { .. } | Curve::Ellipse { .. } => {
if let Ok(e) = brep::eval::CurveEval::new(c) {
if let Ok(e) = solidcraft_geom::brep::eval::CurveEval::new(c) {
let [t0, t1] = interval;
for i in 0..=16 {
if let Some(p) = e.point(t0 + (t1 - t0) * f64::from(i) / 16.0) {
+4 -4
View File
@@ -161,7 +161,7 @@ fn spheres_apart_join_as_two_lumps() {
}
fn certified_lump_witness() -> Body {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
// The current trimmed lower prism: a rectangular tool with a circular stop
// removed. Its cap footprint differs materially from the original sketch.
let region = Region2 {
@@ -176,8 +176,8 @@ fn certified_lump_witness() -> Body {
let inputs = [&named, &unknown, &lower];
let sources: Vec<Option<FaceSource>> =
inputs.iter().flat_map(|b| b.face_sources().map_or_else(|| vec![None; b.face_count()], |s| s.to_vec())).collect();
let records: Vec<&solidcraft_geom::brep::Brep> = inputs.iter().map(|b| b.record()).collect();
let part = solidcraft_geom::brep::part::compound(&records).unwrap();
let records: Vec<&solidcore_record::brep::Brep> = inputs.iter().map(|b| b.record()).collect();
let part = solidcore_record::brep::part::compound(&records).unwrap();
let body = Body::from_record(part.brep).unwrap();
let table = part.faces.iter().map(|f| sources.get(*f as usize).cloned().flatten()).collect();
body.with_face_sources(Some(std::sync::Arc::new(table)))
@@ -249,7 +249,7 @@ fn grouping_lumps_does_not_infer_absent_or_misaligned_sources() {
/// It must still come out outward, or a Cut with it removes the wrong side (#559).
#[test]
fn a_long_thin_cylinder_comes_out_outward() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
let plane = Plane::from_normal(Vec3::new(0., 24., 30.), Vec3::Z).unwrap();
for (lo, seam) in [(-181.0, 0.613), (-100.0, 0.613), (-10.0, 0.613), (-181.0, 0.0)] {
let disc = Region2 { outer: Loop2::circle_from(Vec2::ZERO, 0.5, seam), holes: vec![] };
+5 -3
View File
@@ -2,9 +2,11 @@
//! of the operands (in tests only: the history itself is recorded, never sampled), and the exact
//! origins asserted where the outcome is known.
use solidcraft_geom::prelude::*;
use std::collections::BTreeSet;
use solidcraft_geom::{Mesh, Vec3};
use solidcore_record::Vec3;
use solidcraft_geom::Mesh;
use crate::body::Body;
use crate::history::BodyHistory;
@@ -347,7 +349,7 @@ fn faceted_tool() {
/// one face each past the cutter's floor, untouched (Kept).
#[test]
fn stepped_cut_keeps_the_stock_walls_whole() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
for curved in [true, false] {
let (outer, inner) = if curved {
(Loop2::circle(Vec2::ZERO, 10.0), Loop2::circle(Vec2::ZERO, 5.0))
@@ -464,7 +466,7 @@ mod smlib {
/// how the two meet.
#[test]
fn cubes_touching_along_an_edge_or_at_a_vertex_unite_into_two_solids() {
use solidcraft_geom::brep::part::{Contact, RegionContact};
use solidcore_record::brep::part::{Contact, RegionContact};
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
for (name, b, contact) in [
("edge", boxed(10.0, 10.0, 0.0, 20.0, 20.0, 10.0), Contact::Edge),
+2 -1
View File
@@ -17,7 +17,8 @@
//! exactly; the network there refuses G1/G2 on two sides that meet at a corner for the same
//! reason. Everything this module refuses is an error, never a quietly worse surface.
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::bridge::{Continuity, Frame, bridge};
+11 -10
View File
@@ -11,11 +11,12 @@
//! The two-curve bridge with G0–G3 against a sketch's plane is [`crate::boundary`]; this is the
//! general case: three or four sides, interior curves, 3D curves and edges.
use solidcraft_geom::brep::Brep;
use solidcore_record::brep::Brep;
use solidcore_record::{Plane, Seg2, Vec3};
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::bspline::{CurveN, NurbsSurface, SplineError};
use solidcraft_geom::network::{self, CrossFace, FaceFrame, NetCurve, NetworkCurve, PointCurve, Tolerances};
use solidcraft_geom::{Plane, Seg2, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::continuity_order::{Construction, Continuity};
@@ -336,7 +337,7 @@ impl EdgeFaces {
// How the face's loop (counter-clockwise about its surface's natural normal) runs the edge.
let face = r.faces.get(u.face as usize).ok_or_else(|| KernelError::Failed("boundary surface: an edge's face".into()))?;
let in_loop = match face.loops.get(u.r#loop as usize) {
Some(solidcraft_geom::brep::Loop::Edges { edges }) => edges.get(u.position as usize).map(|x| x.forward),
Some(solidcore_record::brep::Loop::Edges { edges }) => edges.get(u.position as usize).map(|x| x.forward),
_ => None,
};
let in_loop = in_loop.ok_or_else(|| KernelError::Failed("boundary surface: an edge's face".into()))?;
@@ -431,7 +432,7 @@ fn face_of(s: &NurbsSurface, corners: &[Vec3]) -> Result<Body> {
}
let tolerance = (size * 1e-6).max(1e-5);
let mut parts = Parts { tolerance, ..Parts::default() };
parts.vertices = c.iter().map(|p| solidcraft_geom::brep::Vertex { point: [p.x, p.y, p.z], tolerance }).collect();
parts.vertices = c.iter().map(|p| solidcore_record::brep::Vertex { point: [p.x, p.y, p.z], tolerance }).collect();
let mut uses = Vec::new();
for (k, (ctrl, knots, [a, z], forward, fixed)) in sides.into_iter().enumerate() {
if collapsed.get(k).copied().unwrap_or(false) {
@@ -446,7 +447,7 @@ fn face_of(s: &NurbsSurface, corners: &[Vec3]) -> Result<Body> {
let mut ends = vec![vertex_of[a]];
for (_, p) in &cuts {
ends.push(parts.vertices.len());
parts.vertices.push(solidcraft_geom::brep::Vertex { point: [p.x, p.y, p.z], tolerance });
parts.vertices.push(solidcore_record::brep::Vertex { point: [p.x, p.y, p.z], tolerance });
}
ends.push(vertex_of[z]);
let uv = |t: f64| [fixed[0].unwrap_or(t), fixed[1].unwrap_or(t)];
@@ -455,19 +456,19 @@ fn face_of(s: &NurbsSurface, corners: &[Vec3]) -> Result<Body> {
let interval = [w[0], w[1]];
let edge = index(parts.edges.len())?;
let vertices = [index(e[0])?, index(e[1])?];
parts.edges.push(solidcraft_geom::brep::Edge { nurbs: None, curve: curve.clone(), interval, vertices, tolerance, uses: Vec::new() });
pieces.push(solidcraft_geom::brep::OrientedEdge { edge, forward, pcurve: uv_line(uv(w[0]), uv(w[1]), interval) });
parts.edges.push(solidcore_record::brep::Edge { nurbs: None, curve: curve.clone(), interval, vertices, tolerance, uses: Vec::new() });
pieces.push(solidcore_record::brep::OrientedEdge { edge, forward, pcurve: uv_line(uv(w[0]), uv(w[1]), interval) });
}
if !forward {
pieces.reverse();
}
uses.extend(pieces);
}
let face = solidcraft_geom::brep::Face {
let face = solidcore_record::brep::Face {
nurbs: None,
surface: spline_surface(s),
domain: s.domain(),
loops: vec![solidcraft_geom::brep::Loop::Edges { edges: uses }],
loops: vec![solidcore_record::brep::Loop::Edges { edges: uses }],
};
parts.faces.push((face, true));
let body = surface_body(&parts.canonical()?.brep)?;
@@ -513,7 +514,7 @@ fn index(i: usize) -> Result<u32> {
mod tests {
use super::*;
use crate::patch_region;
use solidcraft_geom::{Loop2, Region2, Vec2};
use solidcore_record::{Loop2, Region2, Vec2};
fn sketch(label: &str, plane: Plane, segs: Vec<Seg2>) -> BoundaryCurve<'static> {
BoundaryCurve { label: label.into(), source: CurveSource::Sketch { plane, segs }, continuity: Continuity::G0 }
+4 -3
View File
@@ -16,10 +16,11 @@
//! speed) by finite differences: the second derivative of a surface curve with a unit tangent is
//! its curvature vector, and the third is the arclength derivative of that curvature vector.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::Brep;
use solidcore_record::Vec3;
use solidcore_record::brep::Brep;
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::bspline::{CurveN, HPoint, NurbsSurface};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::continuity_order::Construction;
@@ -402,7 +403,7 @@ impl Support {
.shells
.iter()
.find_map(|s| match s {
solidcraft_geom::brep::Shell::Faces { faces, .. } => faces.iter().find(|o| o.face as usize == face).map(|o| o.forward),
solidcore_record::brep::Shell::Faces { faces, .. } => faces.iter().find(|o| o.face as usize == face).map(|o| o.forward),
_ => None,
})
.unwrap_or(true);
+1 -1
View File
@@ -80,7 +80,7 @@ fn valley_between_cylinders(count: usize, r: f64) -> (Vec<Frame>, Vec<Frame>) {
/// The edges of `body`'s face `face` chained into one loop (its outer loop, as it runs).
fn loop_of(body: &Body, face: usize) -> Chain {
let r = body.record();
let solidcraft_geom::brep::Loop::Edges { edges } = &r.faces[face].loops[0] else { panic!("a vertex loop") };
let solidcore_record::brep::Loop::Edges { edges } = &r.faces[face].loops[0] else { panic!("a vertex loop") };
edges.iter().map(|u| (u.edge as usize, u.forward)).collect()
}
+9 -7
View File
@@ -2,7 +2,8 @@
//! through SMLib ([`crate::smlib_sweeps`]); a profile face as its schema 4 record
//! ([`planar_face_record`]).
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::draft_corners::DraftCorner;
@@ -50,7 +51,7 @@ fn seg_ok(s: &Seg2) -> bool {
}
Seg2::Cubic { p0, p1, p2, p3 } => p0.is_finite() && p1.is_finite() && p2.is_finite() && p3.is_finite(),
Seg2::Conic { a, apex, b, w } => a.is_finite() && apex.is_finite() && b.is_finite() && w.is_finite() && w > 1e-9,
Seg2::Bezier { n, p } => (4..=solidcraft_geom::MAX_BEZIER_DEGREE as u8).contains(&n) && p.iter().all(|q| q.is_finite()),
Seg2::Bezier { n, p } => (4..=solidcore_record::MAX_BEZIER_DEGREE as u8).contains(&n) && p.iter().all(|q| q.is_finite()),
}
}
@@ -494,7 +495,7 @@ fn offset_curve(s: &Seg2, a: Vec2, b: Vec2, d: f64) -> Option<Seg2> {
q
}
Seg2::Bezier { n, p } => {
let k = (n as usize).clamp(1, solidcraft_geom::MAX_BEZIER_DEGREE);
let k = (n as usize).clamp(1, solidcore_record::MAX_BEZIER_DEGREE);
let mut q = offset_polygon(p.get(..=k)?, n0, n1, d)?;
let mut all = p;
for (dst, src) in all.iter_mut().zip(&q) {
@@ -730,7 +731,7 @@ fn with_end(s: &Seg2, x: Vec2) -> Seg2 {
Seg2::Conic { a, apex, w, .. } => Seg2::Conic { a, apex, b: x, w },
Seg2::Bezier { n, p } => {
let mut q = p;
if let Some(last) = q.get_mut((n as usize).clamp(1, solidcraft_geom::MAX_BEZIER_DEGREE)) {
if let Some(last) = q.get_mut((n as usize).clamp(1, solidcore_record::MAX_BEZIER_DEGREE)) {
*last = x;
}
Seg2::Bezier { n, p: q }
@@ -872,8 +873,9 @@ fn smlib_tapered(plane: &Plane, region: &Region2, from: f64, to: f64, foot: f64,
/// counter-clockwise and the holes clockwise, each sketch segment one edge of its exact record
/// curve ([`crate::point_path::sketch_record_curve`]) with its exact pcurve on the plane. The record
/// equivalent of a profile face: SMLib takes it with `Brep::from_record`.
pub fn planar_face_record(plane: &Plane, r: &Region2) -> Result<solidcraft_geom::brep::Brep> {
use solidcraft_geom::brep::{self as rec, pcurve};
pub fn planar_face_record(plane: &Plane, r: &Region2) -> Result<solidcore_record::brep::Brep> {
use solidcore_record::brep::{self as rec};
use solidcraft_geom::brep::pcurve;
if !frame_ok(plane) {
return Err(KernelError::Invalid("the face's plane is not finite and orthonormal".into()));
}
@@ -948,7 +950,7 @@ pub fn planar_face_record(plane: &Plane, r: &Region2) -> Result<solidcraft_geom:
edges,
vertices,
};
brep.validate().map_err(|e| KernelError::Failed(format!("profile face: {e}")))?;
solidcraft_geom::brep::check::validate(&brep).map_err(|e| KernelError::Failed(format!("profile face: {e}")))?;
Ok(brep)
}
@@ -5,7 +5,7 @@
use std::f64::consts::PI;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::build::{box_solid, extrude, extrude_tapered};
use crate::{Body, BoolOp, ChamferSide, boolean, chamfer, chamfer_sides};
+10 -8
View File
@@ -20,9 +20,11 @@
//! the join, and backs the engine's `inspect.continuity`.
use serde::Serialize;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcore_record::brep::{self as b};
use solidcraft_geom::brep::normal_section::{SectionJet, normal_section};
use solidcraft_geom::brep::{self as b, eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::brep::{eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::continuity_order::Continuity;
@@ -493,7 +495,7 @@ impl FaceSurface {
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use solidcraft_geom::{Plane, Seg2};
use solidcore_record::{Plane, Seg2};
fn tolerances() -> ContinuityTolerances {
ContinuityTolerances::default()
@@ -548,7 +550,7 @@ mod tests {
#[test]
fn a_line_tangent_into_an_arc_reports_one_over_its_radius() {
use solidcraft_geom::{Loop2, Region2, Seg2, Vec2};
use solidcore_record::{Loop2, Region2, Seg2, Vec2};
let v = |x: f64, y: f64| Vec2::new(x, y);
let outer = Loop2 {
segs: vec![
@@ -575,7 +577,7 @@ mod tests {
/// into `transition` (starting at the origin, leaving along +x), and back straight to
/// (-20, 20): its one tangent wall seam is the line meeting the transition.
fn line_into(transition: Seg2) -> Body {
use solidcraft_geom::{Loop2, Region2, Vec2};
use solidcore_record::{Loop2, Region2, Vec2};
let end = match transition {
Seg2::Cubic { p3, .. } => p3,
Seg2::Bezier { n, p } => p[usize::from(n)],
@@ -607,7 +609,7 @@ mod tests {
/// L = H = 10, 2 / 900 per mm².
#[test]
fn a_plane_into_a_g2_transition_is_curvature_continuous_but_not_g3() {
use solidcraft_geom::Vec2;
use solidcore_record::Vec2;
let v = Vec2::new;
let body = line_into(Seg2::Cubic { p0: v(0.0, 0.0), p1: v(10.0, 0.0), p2: v(20.0, 0.0), p3: v(30.0, 10.0) });
let seam = tangent_seam(&body);
@@ -625,8 +627,8 @@ mod tests {
/// with L = 5, H = 10, 3 / 2000 per mm³.
#[test]
fn a_plane_into_a_g3_transition_holds_the_change_of_curvature_but_not_g4() {
use solidcraft_geom::Vec2;
let mut p = [Vec2::new(0.0, 0.0); solidcraft_geom::MAX_BEZIER_CTRL];
use solidcore_record::Vec2;
let mut p = [Vec2::new(0.0, 0.0); solidcore_record::MAX_BEZIER_CTRL];
for (k, q) in [(5.0, 0.0), (10.0, 0.0), (15.0, 0.0), (20.0, 10.0)].into_iter().enumerate() {
p[k + 1] = Vec2::new(q.0, q.1);
}
+1 -1
View File
@@ -2,7 +2,7 @@
//! define.
#![allow(clippy::unwrap_used, clippy::panic)]
use crate::*;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
/// An l x w x h block with two bottom edges chamfered by 1 mm: no prism along any axis, so
/// its booleans are not done on sections.
+5 -3
View File
@@ -1,5 +1,6 @@
use solidcraft_geom::Vec3;
use solidcraft_geom::brep as b;
use solidcore_record::Vec3;
use solidcore_record::brep as b;
use solidcraft_geom::prelude::*;
use crate::*;
@@ -135,7 +136,8 @@ fn past_the_box(rec: &b::Brep, face: usize) -> (f64, f64, [f64; 2]) {
let mut ring = Vec::new();
for oe in edges {
let [t0, t1] = oe.pcurve.interval().unwrap();
let mut seg: Vec<[f64; 2]> = (0..=400).map(|k| oe.pcurve.eval(t0 + (t1 - t0) * f64::from(k) / 400.0).unwrap()).collect();
let mut seg: Vec<[f64; 2]> =
(0..=400).map(|k| solidcraft_geom::brep::pcurve::eval(&oe.pcurve, t0 + (t1 - t0) * f64::from(k) / 400.0).unwrap()).collect();
if !oe.forward {
seg.reverse();
}
+2 -1
View File
@@ -9,8 +9,9 @@
//! curvature in the line's direction times the surface normal, `κₙ n` with
//! `κₙ = n · S_tt / |S_t|²` (the second fundamental form over the first, in that direction).
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::iso::IsoLine;
+2 -1
View File
@@ -1,4 +1,5 @@
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::Body;
+5 -3
View File
@@ -10,10 +10,12 @@
//! straight edge between the moved corners. Anything else (curved neighbours, a gap the
//! neighbours cannot close) is refused, naming the face.
use solidcraft_geom::prelude::*;
use std::collections::{BTreeSet, HashMap};
use solidcraft_geom::brep::Curve;
use solidcraft_geom::{Aabb3, Vec3};
use solidcore_record::Vec3;
use solidcore_record::brep::Curve;
use solidcraft_geom::Aabb3;
use crate::assemble::{AFace, AUse, Assembly};
use crate::body::Body;
@@ -325,7 +327,7 @@ pub fn delete_faces(body: &Body, faces: &[usize]) -> Result<Body> {
#[cfg(test)]
mod tests {
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use super::delete_faces;
use crate::{BoolOp, boolean, box_solid, chamfer, cylinder, fillet};
+3 -1
View File
@@ -1,10 +1,12 @@
//! The display mesh of a large body with small radii: bends and holes look round, the mesh
//! stays closed, and the cost stays bounded.
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use std::f64::consts::{FRAC_PI_2, PI, TAU};
use solidcraft_geom::{Loop2, Mesh, Plane, Region2, Seg2, UnitVec3, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::{Mesh, UnitVec3};
use super::{Body, DISPLAY_ANGLE};
use crate::{FaceSurface, extrude, face_surface};
+3 -1
View File
@@ -10,12 +10,14 @@
//! the record curve's own points. A point that settles off its face (past the
//! face's boundary) is dropped: the face's edges, offered too, then carry the minimum.
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use std::sync::OnceLock;
use solidcore_record::Vec3;
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::mesh_distance::{MeshClosest, TriangleSet};
use solidcraft_geom::{Aabb3, Mesh, Vec3};
use solidcraft_geom::{Aabb3, Mesh};
use crate::body::Body;
use crate::surface_kind::{FaceSurface, surface_of};
+2 -1
View File
@@ -10,7 +10,8 @@
//! corner turns into the offset the offset curves overlap and every rule trims them where they
//! cross.
use serde::{Deserialize, Serialize};
use solidcraft_geom::{Region2, Seg2, Vec2};
use solidcore_record::{Region2, Seg2, Vec2};
use solidcraft_geom::prelude::*;
use crate::Result;
+6 -4
View File
@@ -8,9 +8,11 @@ use crate::history::Change;
use crate::numbered::NumberedRegion;
use crate::offset::{Surf, face_edges, surf_of};
use crate::{KernelError, Result, guard};
use solidcore_record::brep::{Brep, Curve, Frame, Loop, Surface};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::brep::{Brep, Curve, Frame, Loop, Surface, form};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::brep::form;
use solidcraft_geom::prelude::*;
fn fail(s: &str) -> KernelError {
KernelError::Invalid(format!("cylinder emboss: {s}"))
@@ -44,7 +46,7 @@ fn wall_angles(b: &Brep, face: usize, o: Vec3, axis: Vec3, radial: Vec3, tangent
// (`interval` is on its NURBS form where it has one) about the angle of its middle (a
// whole turn, from the seam, for a wall in one piece).
let c = CurveEval::new(&e.curve).ok()?;
let [t0, t1] = e.curve_interval()?;
let [t0, t1] = solidcraft_geom::brep::label::edge_curve_interval(e)?;
let am = angle(c.point(0.5 * (t0 + t1))?, o, axis, radial, tangent);
let half = 0.5 * (t1 - t0);
return Some((am - half, am + half));
@@ -607,7 +609,7 @@ fn profile_interval_overlaps(plane: &Plane, regions: &[Region2], o: Vec3, axis:
add(p)?;
}
}
Seg2::Bezier { n, p } if (1..=solidcraft_geom::MAX_BEZIER_DEGREE as u8).contains(&n) => {
Seg2::Bezier { n, p } if (1..=solidcore_record::MAX_BEZIER_DEGREE as u8).contains(&n) => {
for p in p.iter().take(usize::from(n) + 1) {
add(*p)?;
}
+2 -1
View File
@@ -1,5 +1,6 @@
use crate::{FaceSource, extrude, transform_matrix};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
fn assert_exact_planes(body: &crate::Body) {
let mesh = body.mesh(&crate::MeshTolerance::chord(0.001)).unwrap();
+4 -2
View File
@@ -43,9 +43,10 @@
//! control point that does not change the geometry at all — is reported as an error and the
//! geometry is left alone.
use solidcraft_geom::brep as b;
use solidcore_record::Vec3;
use solidcore_record::brep as b;
use solidcraft_geom::Grid;
use solidcraft_geom::bspline::{HPoint, MAX_SPLINE_DEGREE, NurbsSurface, Side, SplineError, check_knots, local_basis};
use solidcraft_geom::{Grid, Vec3};
use crate::body::Body;
use crate::history::Change;
@@ -962,6 +963,7 @@ fn held_face(surface: &b::Surface, opts: &FairOptions) -> Result<Option<FairRepo
mod tests {
use super::*;
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::prelude::*;
/// A clamped uniform knot vector over `[0, spans]` of degree `degree`: `spans + degree`
/// control points.
+8 -4
View File
@@ -14,13 +14,15 @@
//! order asked: the neighbour as a height over its tangent plane to that order
//! (`solidcraft_geom::linkage`).
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcore_record::brep::{self as b, Curve2};
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::brep::eval::SurfaceEval;
use solidcraft_geom::brep::{self as b, Curve2, eval::CurveEval};
use solidcraft_geom::bspline::{HPoint, SplineError};
use solidcraft_geom::fill_general::{Across, MAX_FILL_POINTS, Station};
use solidcraft_geom::fill_iso::{IsoEdge, IsoFill, IsoSpec};
use solidcraft_geom::fill_matched::{MatchedFill, MatchedSpec};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::bridge::Continuity;
@@ -1030,8 +1032,10 @@ pub(crate) fn face_tolerance(body: &Body) -> f64 {
#[cfg(test)]
mod tests {
use solidcraft_geom::brep::{self as b, eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::brep::{self as b};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcraft_geom::brep::{eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::boolean_record::tests::{Reach, checked};
+9 -3
View File
@@ -3,8 +3,10 @@
//! against the analytic surface the loop was cut from, or against a quadrature of the fitted
//! surface itself, never against the mesher alone.
use solidcraft_geom::brep::{self as b, eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::brep::{self as b};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcraft_geom::brep::{eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::prelude::*;
use super::{PATCH_ANGLE_TOL_DEG, PatchReport, PatchSpec, face_tolerance, patch_edges_report};
use crate::body::Body;
@@ -35,7 +37,11 @@ impl Faces {
let [t0, t1] = r.edges[u.edge as usize].interval;
(0..64).map(move |k| {
let x = k as f64 / 64.0;
u.pcurve.eval(if u.forward { t0 + (t1 - t0) * x } else { t1 - (t1 - t0) * x }).unwrap()
solidcraft_geom::brep::pcurve::eval(
&u.pcurve,
if u.forward { t0 + (t1 - t0) * x } else { t1 - (t1 - t0) * x },
)
.unwrap()
})
})
.collect(),
+2 -1
View File
@@ -1,4 +1,5 @@
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use crate::*;
+4 -3
View File
@@ -5,8 +5,9 @@
//! cubic and higher Béziers B-splines on their own control points; conics rational quadratic
//! Béziers (exact ellipses, parabolas and hyperbolas).
use solidcraft_geom::brep::{Curve, Curve2, Surface};
use solidcraft_geom::{Plane, Seg2, Vec2, Vec3};
use solidcore_record::brep::{Curve, Curve2, Surface};
use solidcore_record::{Plane, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::{KernelError, Result};
@@ -62,7 +63,7 @@ fn net(s: &Seg2) -> Result<(Vec<Vec2>, Vec<f64>, Vec<f64>)> {
}
Seg2::Bezier { n, ref p } => {
let n = usize::from(n);
let pts = p.get(..=n).filter(|_| (1..=solidcraft_geom::MAX_BEZIER_DEGREE).contains(&n));
let pts = p.get(..=n).filter(|_| (1..=solidcore_record::MAX_BEZIER_DEGREE).contains(&n));
let pts = pts.ok_or_else(|| KernelError::Invalid("Bézier degree".into()))?;
(pts.to_vec(), vec![1.0; n + 1], bezier_knots(n))
}
+1 -1
View File
@@ -3,7 +3,7 @@
//! placed on a coarse grid, so coincident faces and tangencies come up often.
use serde::Serialize;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::{Body, BoolOp, boolean, box_solid, cylinder, measure, sphere, torus};
+3 -2
View File
@@ -3,9 +3,10 @@
//! (`Brep::merge_faces`, its `SmBrep::RemoveTopologicalEdgesAndVertices`; its booleans do the
//! same at their end), keeping apart the faces split on purpose along the body's split lines.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::Brep;
use solidcore_record::Vec3;
use solidcore_record::brep::Brep;
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::{KernelError, Result};
+3 -1
View File
@@ -1,6 +1,8 @@
//! Helical sweeps (coils, springs) and lofts to a point (pyramids, cones).
use solidcraft_geom::{Loop2, Mesh, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::Mesh;
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::{KernelError, Result};
+5 -5
View File
@@ -15,20 +15,20 @@
//! history here gives its faces attachments with no attachment code of its own. An operation
//! that can't should leave its result without one (`Body::without_history`), never guess.
pub use solidcraft_geom::brep::history::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History, Side};
pub use solidcore_record::brep::history::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History, Side};
use crate::body::{Body, FaceSource};
use crate::{KernelError, Result};
use solidcraft_geom::brep::{Brep, part::Part};
use solidcore_record::brep::{Brep, part::Part};
impl From<solidcraft_geom::brep::history::Failed> for KernelError {
fn from(e: solidcraft_geom::brep::history::Failed) -> KernelError {
impl From<solidcore_record::brep::history::Failed> for KernelError {
fn from(e: solidcore_record::brep::history::Failed) -> KernelError {
KernelError::Failed(e.to_string())
}
}
/// What a [`History`] needs a kernel body for: the history types belong to
/// `solidcraft_geom::brep::history`, so a backend can report them without this crate.
/// `solidcore_record::brep::history`, so a backend can report them without this crate.
pub trait BodyHistory {
/// The history of an operation that keeps every face and edge of its one operand in place
/// (a rigid move, a rebuild that keeps the topology's order).
+4 -3
View File
@@ -1,4 +1,5 @@
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use super::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History, Side};
use crate::history::BodyHistory;
@@ -250,7 +251,7 @@ fn face_sources_follow_kept_split_and_agreeing_merged_faces() {
/// side face over both pieces, not two coplanar faces with an edge between them (#1788).
#[test]
fn collinear_profile_lines_extrude_into_one_side_face() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let pts = [(0.0, 0.0), (10.0, 0.0), (20.0, 0.0), (20.0, 10.0), (0.0, 10.0)].map(|(x, y)| Vec2::new(x, y));
let region = Region2 { outer: Loop2::polygon(&pts), holes: vec![] };
// Plain `extrude` keeps a face per segment (sheet metal's flat pattern relies on it).
@@ -283,7 +284,7 @@ fn collinear_profile_lines_extrude_into_one_side_face() {
/// (#1788): one sloped face generated by both pieces, and the same solid as a side in one piece.
#[test]
fn collinear_profile_lines_taper_into_one_side_face() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let polygon =
|pts: &[(f64, f64)]| Region2 { outer: Loop2::polygon(&pts.iter().map(|&(x, y)| Vec2::new(x, y)).collect::<Vec<_>>()), holes: vec![] };
let split = polygon(&[(0.0, 0.0), (10.0, 0.0), (20.0, 0.0), (20.0, 10.0), (0.0, 10.0)]);
+3 -2
View File
@@ -1,6 +1,7 @@
use super::*;
use crate::{Body, BoolOp, ExportBody, StepHeader, boolean, box_solid, cylinder, fillet, iges_export_bodies, measure, sphere, torus};
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
fn rel(a: f64, b: f64) -> f64 {
(a - b).abs() / b.abs().max(1e-9)
@@ -413,7 +414,7 @@ fn trim_pieces_that_miss_their_corner_are_closed_onto_it() {
fn a_drill_point_round_trips_through_iges() {
// A blind hole with a cone tip: the tip's face closes at its apex (its seam runs out to the
// apex and straight back).
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let plate = box_solid(Vec3::new(-20.0, -15.0, 0.0), Vec3::new(20.0, 15.0, 10.0)).unwrap();
let profile =
Region2 { outer: Loop2::polygon(&[Vec2::new(0.0, 2.0), Vec2::new(4.0, 5.0), Vec2::new(4.0, 11.0), Vec2::new(0.0, 11.0)]), holes: vec![] };
+1 -1
View File
@@ -9,7 +9,7 @@
use std::collections::HashMap;
use std::fmt::Write as _;
use solidcraft_geom::brep::{Brep, Loop, Shell};
use solidcore_record::brep::{Brep, Loop, Shell};
use solidcraft_step::geom::{Curve, Placement, Surface};
use solidcraft_step::write::topology;
+2 -2
View File
@@ -5,8 +5,8 @@
//! tolerance, or the line, circle or ellipse it is) on its interval. Which edges are new comes from
//! the imprint's own history: an edge no edge of either operand became.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::Curve;
use solidcore_record::Vec3;
use solidcore_record::brep::Curve;
use crate::body::{Body, MeshTolerance};
use crate::{KernelError, Result};
@@ -1,7 +1,7 @@
//! A face whose edge is an intersection curve that does not evaluate (#1252): meshing it neither
//! panics nor gives non-finite points.
use solidcraft_geom::brep::{self as b, Curve, Curve2, Surface};
use solidcore_record::brep::{self as b, Curve, Curve2, Surface};
/// A plane at height `z` with its parameters along x and y.
fn plane(z: f64) -> Surface {
+7 -6
View File
@@ -10,9 +10,10 @@
//! box's side, where the outer loop's polygon closes. Every iso line of a closed surface is
//! therefore one line across the box, cut where it crosses the loops.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep;
use solidcore_record::Vec3;
use solidcore_record::brep;
use solidcraft_geom::brep::eval::SurfaceEval;
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::point_path::{MAX_CURVE_POINTS, curve_path};
@@ -129,13 +130,13 @@ impl<'a> FaceTrims<'a> {
let (mut x, mut y) = (ta, tb);
for _ in 0..80 {
let m = 0.5 * (x + y);
match c.eval(m).map(across) {
match solidcraft_geom::brep::pcurve::eval(c, m).map(across) {
Some(k) if (k < 0.0) == (ka < 0.0) => x = m,
Some(_) => y = m,
None => break,
}
}
if let Some(t) = c.eval(0.5 * (x + y)).map(along).filter(|t| *t > lo && *t < hi) {
if let Some(t) = solidcraft_geom::brep::pcurve::eval(c, 0.5 * (x + y)).map(along).filter(|t| *t > lo && *t < hi) {
cuts.push(t);
}
}
@@ -260,7 +261,7 @@ fn pcurve_samples(c: &brep::Curve2) -> Vec<(f64, [f64; 2])> {
(0..=n)
.filter_map(|i| {
let t = a + (b - a) * i as f64 / n as f64;
c.eval(t).map(|q| (t, q))
solidcraft_geom::brep::pcurve::eval(c, t).map(|q| (t, q))
})
.collect()
}
@@ -280,7 +281,7 @@ fn crosses_right(q: [f64; 2], l: &[[f64; 2]]) -> bool {
/// The iso curve of `surface` at `fixed` (the other parameter) as a record curve on `[a, b]` of
/// its own parameter: the surface's own line or circle, or its B-spline row.
fn iso_record(surface: &brep::Surface, along_u: bool, fixed: f64, (a, b): (f64, f64)) -> Result<(brep::Curve, [f64; 2])> {
use solidcraft_geom::brep::{Curve, Frame, Surface};
use solidcore_record::brep::{Curve, Frame, Surface};
let v = |q: [f64; 3]| Vec3::new(q[0], q[1], q[2]);
let d = |q: Vec3| [q.x, q.y, q.z];
let line = |p: Vec3, q: Vec3| (Curve::Line { start: d(p), end: d(q) }, [0.0, 1.0]);
+3 -2
View File
@@ -1,8 +1,9 @@
//! #1038: a small hole on a large curved face cuts cleanly, its rim on the face an intersection
//! edge.
use solidcraft_geom::brep::Curve;
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::brep::Curve;
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::{Body, BoolOp, build::extrude, cylinder, ops::boolean};
+1 -1
View File
@@ -5,7 +5,7 @@
//! large, and the largest size that fits is found by searching ([`crate::fillet_max`],
//! [`crate::chamfer_max`]).
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::{Body, BoolOp, ChamferSide, KernelError, build::box_solid, ops::boolean};
+8 -7
View File
@@ -1,7 +1,8 @@
//! #1510: a body split by a plane that a face of the body lies in: the parts meet in the plane
//! and together are the body.
use solidcraft_geom::{Plane, Vec3};
use solidcore_record::{Plane, Vec3};
use solidcraft_geom::prelude::*;
use crate::{Body, BoolOp, build::box_solid, build::cylinder, ops::boolean, ops::split_by_plane};
@@ -52,13 +53,13 @@ fn a_split_in_the_plane_of_a_face_keeps_all_of_the_body() {
fn a_face_only_nearly_in_the_plane_is_not_moved() {
let x = Vec3::new(700.0, 0.0, 0.03).normalized().unwrap();
let bottom = Plane::new(Vec3::ZERO, x, Vec3::Y).unwrap();
let outer = solidcraft_geom::Loop2::polygon(&[
solidcraft_geom::Vec2::new(0.0, 0.0),
solidcraft_geom::Vec2::new(Vec3::new(700.0, 0.0, 0.03).len(), 0.0),
solidcraft_geom::Vec2::new(Vec3::new(700.0, 0.0, 0.03).len(), 100.0),
solidcraft_geom::Vec2::new(0.0, 100.0),
let outer = solidcore_record::Loop2::polygon(&[
solidcore_record::Vec2::new(0.0, 0.0),
solidcore_record::Vec2::new(Vec3::new(700.0, 0.0, 0.03).len(), 0.0),
solidcore_record::Vec2::new(Vec3::new(700.0, 0.0, 0.03).len(), 100.0),
solidcore_record::Vec2::new(0.0, 100.0),
]);
let b = crate::extrude(&bottom, &[solidcraft_geom::Region2 { outer, holes: vec![] }], 0.0, 10.0).unwrap().pop().unwrap();
let b = crate::extrude(&bottom, &[solidcore_record::Region2 { outer, holes: vec![] }], 0.0, 10.0).unwrap().pop().unwrap();
let plane = Plane::from_normal(Vec3::ZERO, Vec3::Z).unwrap();
let v0 = b.volume_at(1e-2).unwrap();
let up = crate::ops::half_space(&b, &plane, true).unwrap().0.unwrap();
+1 -1
View File
@@ -5,7 +5,7 @@
use std::f64::consts::{FRAC_PI_2, PI, TAU};
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::{Body, BoolOp, PathSeg, SweepControl, boolean, measure, sweep_with};
+3 -1
View File
@@ -1,7 +1,9 @@
//! Issue #616: small boxes joined flush to the walls and floor of a part never change it away
//! from the box, and a retry that would is refused.
use solidcraft_geom::{Aabb3, Mesh, Vec3};
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use solidcraft_geom::{Aabb3, Mesh};
use crate::*;
+4 -3
View File
@@ -1,6 +1,7 @@
//! Partial planar contact must sew a solid without displacing or inventing material.
use crate::*;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use std::f64::consts::PI;
#[test]
@@ -12,7 +13,7 @@ fn split_contact_arc_crossing_one_edge_twice_preserves_the_body() {
.record()
.faces
.iter()
.position(|f| !matches!(f.surface, solidcraft_geom::brep::Surface::Plane { .. } | solidcraft_geom::brep::Surface::PlaneThrough { .. }))
.position(|f| !matches!(f.surface, solidcore_record::brep::Surface::Plane { .. } | solidcore_record::brep::Surface::PlaneThrough { .. }))
.unwrap();
let r = split_faces(&a, &[face], &SplitTool::Face { body: &b, face: side }).unwrap();
assert_eq!(r.face_count(), a.face_count() + 1);
@@ -27,7 +28,7 @@ fn split_contact_arc_crossing_one_edge_twice_preserves_the_body() {
fn partial_contact_retains_an_authored_split_away_from_the_contact() {
let a = box_solid(Vec3::ZERO, Vec3::new(25.0, 47.5, 37.5)).unwrap();
let face = a.faces(0.01).unwrap().iter().position(|f| f.plane_normal.is_some_and(|n| n.dot(Vec3::X) > 0.99)).unwrap();
let a = split_faces(&a, &[face], &SplitTool::Plane(solidcraft_geom::Plane { origin: Vec3::new(0.0, 0.0, 15.0), ..solidcraft_geom::Plane::XY }))
let a = split_faces(&a, &[face], &SplitTool::Plane(solidcore_record::Plane { origin: Vec3::new(0.0, 0.0, 15.0), ..solidcore_record::Plane::XY }))
.unwrap();
let b = cylinder(Vec3::new(0.0, 7.5, 0.0), -Vec3::X, 5.0, 2.5).unwrap();
let r = boolean(&a, &b, BoolOp::Union).unwrap().unwrap();
+1 -1
View File
@@ -2,7 +2,7 @@
//! grid extruded up and down (#679), a pad half past the edge of the face it stands on (#674),
//! several contact regions, contact beside a shared edge, and random rectangles.
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::*;
+1 -1
View File
@@ -2,7 +2,7 @@
//! of the crossing meet, which a mesh intersection cannot trace and a boolean cannot take in the
//! middle of a face.
use crate::*;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use std::f64::consts::PI;
const SIDE: f64 = 45.0;
+1 -1
View File
@@ -1,6 +1,6 @@
//! Fillets and chamfers where a curved wall runs out into a flat face in a knife edge (#851).
use crate::*;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use std::f64::consts::PI;
const R_WALL: f64 = 21.0;
+1 -1
View File
@@ -1,6 +1,6 @@
//! #871: a fillet that opened holes in the model must be refused, not accepted.
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::{Body, BoolOp, build::box_solid, ops::boolean};
+1 -1
View File
@@ -7,7 +7,7 @@
use std::f64::consts::PI;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::*;
+1 -1
View File
@@ -279,7 +279,7 @@ impl Cause for str {}
impl Cause for String {}
impl Cause for solidcraft_smlib::CheckReport {}
impl Cause for solidcraft_smlib::export::ExportError {}
impl Cause for solidcraft_geom::brep::history::Failed {}
impl Cause for solidcore_record::brep::history::Failed {}
impl Cause for solidcraft_geom::brep::pcurve::Error {}
impl<T: Cause + ?Sized> Cause for &T {
fn panic(&self) -> Option<&str> {
+5 -3
View File
@@ -3,8 +3,10 @@
//! directly on the body's schema 4 record (the band's walls continue the walls below, which a
//! boolean union can't join: their faces would coincide).
use solidcraft_geom::brep::{Brep, Curve, Frame, Surface};
use solidcraft_geom::{Loop2, Plane, Region2, Ring, Seg2, Vec3};
use solidcore_record::brep::{Brep, Curve, Frame, Surface};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec3};
use solidcraft_geom::Ring;
use solidcraft_geom::prelude::*;
use crate::assemble::{AFace, AUse, Assembly};
use crate::body::Body;
@@ -150,7 +152,7 @@ fn pieces(asm: &Assembly, lp: &[AUse], n: Vec3) -> Result<Vec<Piece>> {
let (s, t) = asm.ends(u).ok_or_else(|| fail("edge"))?;
let (a, b) = (asm.point(s).ok_or_else(|| fail("vertex"))?, asm.point(t).ok_or_else(|| fail("vertex"))?);
// The arc's angles, on the circle itself (its NURBS form, if any, is parameterised otherwise).
let [t0, t1] = solidcraft_geom::brep::curve_interval(&e.curve, e.nurbs.as_ref(), e.interval).ok_or_else(|| fail("edge"))?;
let [t0, t1] = solidcraft_geom::brep::label::curve_interval(&e.curve, e.nurbs.as_ref(), e.interval).ok_or_else(|| fail("edge"))?;
match &e.curve {
Curve::Line { .. } => Ok(Piece { a, b, arc: None }),
Curve::Circle { frame, .. } => {
+2 -1
View File
@@ -40,9 +40,10 @@
//! to 3 fuller, down to −0.9 flatter), exactly as a bridge's crown does. It shapes the middle of
//! each end span and leaves every joint's conditions alone.
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::brep::eval::SurfaceEval;
use solidcraft_geom::bspline::{CurveN, HPoint, MAX_SPLINE_DEGREE, NurbsSurface};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::bridge::{Continuity, Frame};
+4 -3
View File
@@ -12,8 +12,9 @@
//! Sections are exact NURBS curves ([`Section`], from the sketch segments' record curves); a
//! station is the plain loft's control points moved by an affine map, so each is exact too.
use solidcore_record::{Plane, Seg2, Vec3};
use solidcraft_geom::bspline::CurveN;
use solidcraft_geom::{Plane, Seg2, Vec3};
use solidcraft_geom::prelude::*;
use crate::sweep_path::RailFit;
use crate::{KernelError, Result};
@@ -42,8 +43,8 @@ impl Section {
}
/// A record line or (rational) B-spline as a homogeneous NURBS curve.
fn nurbs(c: &solidcraft_geom::brep::Curve) -> Result<CurveN<4>> {
use solidcraft_geom::brep::Curve;
fn nurbs(c: &solidcore_record::brep::Curve) -> Result<CurveN<4>> {
use solidcore_record::brep::Curve;
let degree = |knots: &[f64], n: usize| knots.len().checked_sub(n + 1).ok_or_else(|| KernelError::Invalid("spline degree".into()));
Ok(match c {
Curve::Line { start, end } => {
+2 -1
View File
@@ -5,9 +5,10 @@
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use solidcraft_geom::prelude::*;
use std::f64::consts::PI;
use solidcraft_geom::{Loop2, Plane, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Seg2, Vec2, Vec3};
use crate::{KernelError, RailFit, loft, loft_sheet_with_rails, loft_with_rails, measure};
+3 -2
View File
@@ -1,8 +1,9 @@
//! Analytic regressions for lofted passages (#2435).
use solidcraft_geom::prelude::*;
use std::f64::consts::PI;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::{Body, loft_regions, measure, step_export, step_import};
@@ -90,7 +91,7 @@ fn loft_regions_bound_segments_after_matching() {
// would exceed it in every section. Refuse before allocating the topology.
let circle = |x, n| Loop2 {
segs: (0..n)
.map(|i| solidcraft_geom::Seg2::Arc {
.map(|i| solidcore_record::Seg2::Arc {
center: Vec2::new(x, 0.0),
radius: 1.0,
start: i as f64 * std::f64::consts::TAU / n as f64,
+4 -2
View File
@@ -16,8 +16,10 @@
//! of the target meet, with shapes that part company, is a seam the target itself does not hold
//! beyond that order, and no surface can be told to carry a condition the target has not got.
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::{self as b, eval::CurveEval, eval::SurfaceEval};
use solidcore_record::Vec3;
use solidcore_record::brep::{self as b};
use solidcraft_geom::brep::{eval::CurveEval, eval::SurfaceEval};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::bridge::{self, Continuity, Frame};
+1 -1
View File
@@ -6,7 +6,7 @@ use super::*;
use crate::bridge::{Continuity, Frame};
use crate::build::SEAM_ANGLE;
use crate::{cylinder, stitch};
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
/// The radius of the cylinder a sheet is matched to, the radius the sheet starts at, its height,
/// and how far round the cylinder the sheet runs.
+4 -2
View File
@@ -1,5 +1,6 @@
use serde::Serialize;
use solidcraft_geom::{Aabb3, Vec3};
use solidcore_record::Vec3;
use solidcraft_geom::Aabb3;
use crate::Result;
use crate::body::Body;
@@ -112,6 +113,7 @@ pub fn measure_mass(b: &Body) -> Result<MassMeasure> {
mod tests {
use super::*;
use crate::{BoolOp, boolean, cylinder, torus};
use solidcraft_geom::prelude::*;
/// The mass properties alone are [`measure`]'s, to the bit; and on a curved intersection
/// they are the textbook ones.
@@ -139,7 +141,7 @@ mod tests {
// A body's measured volume does not depend on where it sits: the same revolved ring of cones
// and cylinders, moved far from the origin, measures what it measures at the origin.
use crate::{revolve, transform};
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
use std::f64::consts::{PI, TAU};
/// Ring cross-section in (radius, height): cones top and bottom, cylinders inside and out.
+5 -4
View File
@@ -1,9 +1,10 @@
//! Conservative reconstruction of constant-section mechanical mesh parts.
//! Geometry is inferred from closed, manifold input, never from a display mesh.
use solidcraft_geom::prelude::*;
use std::collections::BTreeMap;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::{Body, KernelError, Result};
@@ -260,7 +261,7 @@ fn extrusion(mesh: &crate::meshbody::TriMesh, axis: Vec3, tolerance: f64) -> Res
}
let p = plane.to_local(*p);
if !boundary_segments.iter().any(|&(a, b)| {
solidcraft_geom::Seg2::Line { a, b }.point_at(solidcraft_geom::Seg2::Line { a, b }.closest_param(p)).dist(p) <= epsilon * 3.
solidcore_record::Seg2::Line { a, b }.point_at(solidcore_record::Seg2::Line { a, b }.closest_param(p)).dist(p) <= epsilon * 3.
}) {
return Ok(None);
}
@@ -411,7 +412,7 @@ fn fit_loop(points: &[Vec2], tolerance: f64, epsilon: f64) -> Loop2 {
}
let remove = (0..n).find(|&i| {
let (Some(a), Some(b), Some(c)) = (points.get((i + n - 1) % n), points.get(i), points.get((i + 1) % n)) else { return false };
let edge = solidcraft_geom::Seg2::Line { a: *a, b: *c };
let edge = solidcore_record::Seg2::Line { a: *a, b: *c };
edge.point_at(edge.closest_param(*b)).dist(*b) <= linear_tolerance
});
let Some(index) = remove else { break };
@@ -483,7 +484,7 @@ mod tests {
/// The loop is the exact circle: one full turn of an arc round `center` at `radius`.
fn assert_exact_circle(fitted: &Loop2, center: Vec2, radius: f64) {
let [solidcraft_geom::Seg2::Arc { center: c, radius: r, sweep, .. }] = fitted.segs.as_slice() else { panic!("not one arc: {fitted:?}") };
let [solidcore_record::Seg2::Arc { center: c, radius: r, sweep, .. }] = fitted.segs.as_slice() else { panic!("not one arc: {fitted:?}") };
assert!(c.dist(center) < 1e-9 && (r - radius).abs() < 1e-9, "centre {c:?}, radius {r}");
assert!((sweep.abs() - std::f64::consts::TAU).abs() < 1e-9, "sweep {sweep}");
}
+3 -1
View File
@@ -1,9 +1,11 @@
//! Mesh bodies: triangles without a B-rep (imported 3MF/STL). They render, measure, move and
//! export; B-rep features refuse them.
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use solidcraft_geom::{Mesh, Vec3};
use solidcore_record::Vec3;
use solidcraft_geom::Mesh;
use crate::body::Body;
use crate::{KernelError, Result};
+2 -1
View File
@@ -2,7 +2,8 @@
//! face and edge origin checked against the geometry of the operands (in tests only: the history
//! itself is recorded, never sampled), and the exact origins asserted where the outcome is known.
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::boolean_record::tests::{self, Reach, changes, to_edge, to_face};
+49 -143
View File
@@ -1,45 +1,19 @@
//! SolidCraft native, versioned binary geometry. No STEP conversion or display meshes.
//! Exact: a decoded body is the encoded one, number for number, for the same producer.
use crate::{Body, KernelError, Result, guard};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Number, Value};
use solidcore_record::native::{self as file, Runtime, Saved};
mod binary;
mod metadata;
mod preview;
pub use preview::native_preview_mesh;
// 01/02 were development-only prototypes; independent metadata records start at 03; 04 stores
// procedural intersections and placed revolutions exactly, and the measured runtime values; 05
// nests geometry schema 4 (regions, unbounded geometry, pcurves, canonical order).
const MAGIC: &[u8; 8] = b"SCBREP05";
// A body's own limits. A design's cache holds many bodies within the container's budgets, and
// decoding is linear in the bytes, so one large part (an imported casting) fits.
const MAX_BYTES: usize = 256 << 20;
const MAX_ITEMS: usize = 1_000_000;
const MAX_VALUES: usize = 20_000_000;
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct SavedBody {
solid: solidcraft_geom::brep::Brep,
metadata: solidcraft_geom::brep::envelope::Metadata,
runtime: Runtime,
}
/// What a body measured about itself that later operations read: kept so a decoded body works
/// to the same tolerances as the one encoded, without measuring again.
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct Runtime {
/// [`Body::size`] as stored (0: not measured).
size: f64,
/// Saved by earlier versions (an orientation mesh's missing-face count); read and ignored.
coarse_missing: Option<(f64, u64)>,
}
fn invalid(detail: impl std::fmt::Display) -> KernelError {
KernelError::Invalid(format!("native B-rep: {detail}"))
}
/// A refusal of the native file (its own message, "native B-rep: ...").
fn refused(e: file::Error) -> KernelError {
KernelError::Invalid(e.to_string())
}
/// Explicit topology, spatial geometry, construction certificates and history, exactly: the
/// body's own record and what it carries. Failure is a cache miss at the IO boundary, never a
@@ -61,22 +35,20 @@ pub fn encode_native_body(body: &Body) -> Result<Vec<u8>> {
if body.mesh.is_some() {
return Err(invalid("mesh bodies are source blobs, not B-rep"));
}
if body.face_count() > MAX_ITEMS || body.edge_count() > MAX_ITEMS {
if body.face_count() > file::MAX_ITEMS || body.edge_count() > file::MAX_ITEMS {
return Err(invalid("native geometry budget"));
}
let runtime = Runtime { size: body.size, coarse_missing: None };
let saved = SavedBody { solid: body.record().clone(), metadata: metadata::encode(body)?, runtime };
// Structural validation does not invoke another geometric reconstruction.
validate_topology(&saved)?;
let mut out = MAGIC.to_vec();
binary::write_serialized(&saved, &mut out)?;
Ok(out)
let saved = Saved { solid: body.record().clone(), metadata: metadata::encode(body)?, runtime };
// The record's own checks: no geometric reconstruction.
check(&saved)?;
file::encode(&saved).map_err(refused)
})
}
/// The schema 4 record of a solid body, in canonical order with its pcurves: the body itself.
/// Mesh bodies have none.
pub fn brep_record(body: &Body) -> Result<solidcraft_geom::brep::Brep> {
pub fn brep_record(body: &Body) -> Result<solidcore_record::brep::Brep> {
let _span = solidcraft_profile::span("kernel", "brep_record");
if body.mesh.is_some() {
return Err(invalid("mesh bodies are source blobs, not B-rep"));
@@ -94,23 +66,10 @@ pub fn smlib_body(body: &Body) -> Result<solidcraft_smlib::Brep> {
/// Only a caller that has checked who produced the data may treat it as evaluated geometry.
pub fn decode_native_body(bytes: &[u8]) -> Result<Body> {
let _span = solidcraft_profile::span("kernel", "decode_native_body");
if bytes.len() > MAX_BYTES || bytes.get(..8) != Some(MAGIC.as_slice()) {
return Err(invalid("version or size"));
}
guard("decode native B-rep", || {
let mut input = bytes.get(8..).ok_or_else(|| invalid("header"))?;
let mut remaining = MAX_VALUES;
let value = binary::read(&mut input, 0, &mut remaining)?;
if !input.is_empty() {
return Err(invalid("trailing data"));
}
validate_value(&value, 0)?;
let saved: SavedBody = serde_json::from_value(value).map_err(invalid)?;
validate_topology(&saved)?;
let Runtime { size, .. } = saved.runtime;
if !(size.is_finite() && size >= 0.0) {
return Err(invalid("runtime values"));
}
let saved = file::decode(bytes).map_err(refused)?;
check(&saved)?;
let size = saved.runtime.size;
let mut body = Body::from_record(saved.solid)?;
if size > 0.0 {
body.size = size;
@@ -146,7 +105,7 @@ pub(crate) fn smlib_body_ordered(body: &Body) -> Result<(solidcraft_smlib::Brep,
/// `record` in SMLib, imported as given (SMLib's own form; a record it refuses is an error that
/// names why), with where each of SMLib's faces and edges is in the record's order.
pub(crate) fn smlib_record_ordered(
record: &solidcraft_geom::brep::Brep,
record: &solidcore_record::brep::Brep,
) -> Result<(solidcraft_smlib::Brep, Option<solidcraft_smlib::history::Order>)> {
let _span = solidcraft_profile::span("kernel", "smlib_record_ordered");
let brep = solidcraft_smlib::Brep::from_record(record, true).map_err(|e| KernelError::smlib("SMLib", e))?;
@@ -163,7 +122,7 @@ pub(crate) fn smlib_record_ordered(
/// SMLib's faces and edges in the record's order, and canonical order can list them otherwise,
/// a tube's seam edges among them): the export put back in SMLib's order then numbers them as
/// `record` does, and SMLib's face and edge `i` are the record's `i`.
fn numbering(record: &solidcraft_geom::brep::Brep, brep: &solidcraft_smlib::Brep) -> Option<solidcraft_smlib::history::Order> {
fn numbering(record: &solidcore_record::brep::Brep, brep: &solidcraft_smlib::Brep) -> Option<solidcraft_smlib::history::Order> {
match brep.to_native_ordered() {
Ok((back, order)) => {
if same_numbering(record, &back) {
@@ -183,8 +142,8 @@ fn numbering(record: &solidcraft_geom::brep::Brep, brep: &solidcraft_smlib::Brep
/// SMLib's face and edge `i` are in `back`), each loop naming its edges by SMLib's numbers.
/// `None` where `order` is not a renumbering of `back`'s faces and edges (an edge split into
/// pieces where solids touch along it is more than one record edge).
fn in_smlib_order(back: &solidcraft_geom::brep::Brep, order: &solidcraft_smlib::history::Order) -> Option<solidcraft_geom::brep::Brep> {
use solidcraft_geom::brep::Loop;
fn in_smlib_order(back: &solidcore_record::brep::Brep, order: &solidcraft_smlib::history::Order) -> Option<solidcore_record::brep::Brep> {
use solidcore_record::brep::Loop;
let permutation = |to: &[usize], n: usize| -> Option<Vec<usize>> {
if to.is_empty() {
return Some((0..n).collect());
@@ -225,8 +184,8 @@ fn in_smlib_order(back: &solidcraft_geom::brep::Brep, order: &solidcraft_smlib::
/// Whether two records of one body number its faces, edges and vertices alike: the same loops of
/// the same edges, the same edge ends, and each vertex where the other's is.
fn same_numbering(a: &solidcraft_geom::brep::Brep, b: &solidcraft_geom::brep::Brep) -> bool {
use solidcraft_geom::brep::Loop;
fn same_numbering(a: &solidcore_record::brep::Brep, b: &solidcore_record::brep::Brep) -> bool {
use solidcore_record::brep::Loop;
if a.faces.len() != b.faces.len() || a.edges.len() != b.edges.len() || a.vertices.len() != b.vertices.len() {
return false;
}
@@ -250,7 +209,7 @@ fn same_numbering(a: &solidcraft_geom::brep::Brep, b: &solidcraft_geom::brep::Br
/// opposite order with each edge the other way round. SMLib walks a face whose surface it turned
/// (a hole's wall) the other way, starting where it likes; its faces and edges are numbered
/// alike all the same.
fn same_cycle(x: &[solidcraft_geom::brep::OrientedEdge], y: &[solidcraft_geom::brep::OrientedEdge]) -> bool {
fn same_cycle(x: &[solidcore_record::brep::OrientedEdge], y: &[solidcore_record::brep::OrientedEdge]) -> bool {
let n = x.len();
if n != y.len() {
return false;
@@ -264,72 +223,16 @@ fn same_cycle(x: &[solidcraft_geom::brep::OrientedEdge], y: &[solidcraft_geom::b
})
}
fn validate_topology(saved: &SavedBody) -> Result<()> {
saved.solid.validate().map_err(invalid)?;
let (faces, edges) = (saved.solid.faces.len(), saved.solid.edges.len());
let saved = &saved.metadata;
if saved.version != solidcraft_geom::brep::envelope::VERSION {
return Err(invalid("metadata version"));
}
if saved.face_sources.as_ref().is_some_and(|s| s.len() != faces) {
return Err(invalid("face source count"));
}
if let Some(history) = &saved.history
&& (history.faces.len() != faces
|| history.edges.len() != edges
|| history.operands as usize > MAX_ITEMS
|| history.edges.iter().flat_map(|e| &e.faces).any(|&f| f as usize >= faces))
{
return Err(invalid("history topology"));
}
if saved.color.is_some_and(|c| c.iter().any(|v| !v.is_finite() || !(0.0..=1.0).contains(v))) {
return Err(invalid("colour"));
}
if let Some(paint) = &saved.paint
&& (!paint.opacity.is_finite()
|| !(0.0..=1.0).contains(&paint.opacity)
|| paint.faces.iter().any(|p| {
p.face as usize >= faces
|| !p.opacity.is_finite()
|| !(0.0..=1.0).contains(&p.opacity)
|| p.color.iter().any(|v| !v.is_finite() || !(0.0..=1.0).contains(v))
}))
{
return Err(invalid("face paint"));
}
Ok(())
/// The kernel's checks of a saved body's record that the file's own structural checks leave to
/// it ([`solidcraft_geom::brep::check::geometry`]: frames, planes, placements).
fn check(saved: &Saved) -> Result<()> {
solidcraft_geom::brep::check::geometry(&saved.solid).map_err(invalid)
}
// The binary reader bounds allocation before deserialization. Geometry semantics
// are checked by the independent schema validator, not by backend serde internals.
fn validate_value(v: &Value, depth: usize) -> Result<()> {
if depth > 48 {
return Err(invalid("nesting"));
}
match v {
Value::String(s) if s.len() > 1 << 20 => return Err(invalid("string budget")),
Value::Number(n) if n.is_f64() && n.as_f64().is_none_or(|x| !x.is_finite() || x.abs() > 1e12) => return Err(invalid("non-finite metadata")),
Value::Array(a) => {
if a.len() > MAX_ITEMS {
return Err(invalid("array budget"));
}
for x in a {
validate_value(x, depth + 1)?;
}
}
Value::Object(o) => {
for x in o.values() {
validate_value(x, depth + 1)?;
}
}
_ => {}
}
Ok(())
}
/// How many values `v` is (a collection and each of its items): [`MAX_VALUES`] at most.
/// How many values `v` is (a collection and each of its items): [`file::MAX_VALUES`] at most.
#[cfg(test)]
fn value_nodes(v: &Value) -> usize {
fn value_nodes(v: &serde_json::Value) -> usize {
use serde_json::Value;
match v {
Value::Array(a) => a.iter().fold(1usize, |n, v| n.saturating_add(value_nodes(v))),
Value::Object(o) => o.values().fold(1usize, |n, v| n.saturating_add(value_nodes(v))),
@@ -342,7 +245,9 @@ mod smlib_import_tests;
#[cfg(test)]
mod tests {
use super::*;
use solidcraft_geom::Vec3;
use serde_json::Value;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use std::sync::Arc;
fn equal(a: &Body, b: &Body) {
assert_eq!(a.face_count(), b.face_count());
@@ -366,7 +271,7 @@ mod tests {
for body in [cube, rounded, cut] {
let body = body.with_color(Some([0.1, 0.5, 0.9]));
let bytes = encode_native_body(&body).unwrap();
assert!(bytes.starts_with(MAGIC));
assert!(bytes.starts_with(file::MAGIC));
let decoded = decode_native_body(&bytes).unwrap();
equal(&body, &decoded);
let a = crate::boolean(&body, &bore, crate::BoolOp::Cut).unwrap().unwrap();
@@ -396,15 +301,16 @@ mod tests {
/// a JSON value, checked, then written.
fn encoded_through_a_value(body: &Body) -> Result<Vec<u8>> {
let runtime = Runtime { size: body.size, coarse_missing: None };
let saved = SavedBody { solid: body.record().clone(), metadata: metadata::encode(body)?, runtime };
validate_topology(&saved)?;
let saved = Saved { solid: body.record().clone(), metadata: metadata::encode(body)?, runtime };
check(&saved)?;
file::check(&saved).map_err(refused)?;
let value = serde_json::to_value(saved).map_err(invalid)?;
validate_value(&value, 0)?;
if value_nodes(&value) > MAX_VALUES {
file::check_value(&value).map_err(refused)?;
if value_nodes(&value) > file::MAX_VALUES {
return Err(invalid("value budget"));
}
let mut out = MAGIC.to_vec();
binary::write(&value, &mut out, 0)?;
let mut out = file::MAGIC.to_vec();
file::write_value(&value, &mut out).map_err(refused)?;
Ok(out)
}
@@ -413,7 +319,7 @@ mod tests {
/// along lines, round (spline forms), open, and placed far off.
#[test]
fn the_encoding_is_the_bytes_of_the_record_as_a_json_value() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let cube = crate::box_solid(Vec3::ZERO, Vec3::new(40., 30., 10.)).unwrap();
let rounded = crate::fillet(&cube, &[Vec3::new(20., 0., 10.)], 2.).unwrap();
let bore = crate::cylinder(Vec3::new(10., 10., -1.), Vec3::Z, 3., 12.).unwrap();
@@ -459,7 +365,7 @@ mod tests {
let bytes = encode_native_body(body).unwrap();
assert_eq!(&bytes[..8], b"SCBREP05");
let mut raw = &bytes[8..];
let value = binary::read(&mut raw, 0, &mut 2_000_000).unwrap();
let value = file::read_value(&mut raw, &mut 2_000_000).unwrap();
assert!(raw.is_empty());
value
})
@@ -509,7 +415,7 @@ mod tests {
assert!(std::panic::catch_unwind(|| decode_native_body(&bad)).is_ok());
}
let mut raw = &bytes[8..];
let value = binary::read(&mut raw, 0, &mut 2_000_000).unwrap();
let value = file::read_value(&mut raw, &mut 2_000_000).unwrap();
for key in ["vertices", "index"] {
let mut v = value.clone();
if key == "vertices" {
@@ -517,11 +423,11 @@ mod tests {
} else {
v["solid"]["faces"][0]["loops"][0]["edges"][0]["edge"] = serde_json::json!(u64::MAX);
}
let mut bad = MAGIC.to_vec();
binary::write(&v, &mut bad, 0).unwrap();
let mut bad = file::MAGIC.to_vec();
file::write_value(&v, &mut bad).unwrap();
assert!(decode_native_body(&bad).is_err());
}
let mut huge = MAGIC.to_vec();
let mut huge = file::MAGIC.to_vec();
huge.push(7);
huge.extend(u32::MAX.to_le_bytes());
assert!(decode_native_body(&huge).is_err());
@@ -534,13 +440,13 @@ mod tests {
let body = crate::box_solid(Vec3::ZERO, Vec3::new(10., 20., 30.)).unwrap();
let mut record = body.record().clone();
let [t0, t1] = record.edges[0].interval;
let n = solidcraft_geom::brep::MAX_ITEMS;
let n = solidcore_record::brep::MAX_ITEMS;
let points = (0..n).map(|i| [i as f64 * 1e-6, 0., 0.]).collect();
record.edges[0].curve = solidcraft_geom::brep::Curve::Polyline { points };
record.edges[0].curve = solidcore_record::brep::Curve::Polyline { points };
assert!(t0 >= 0.0 && t1 <= (n - 1) as f64);
Body::from_record(record.clone()).unwrap();
let saved = SavedBody { solid: record, metadata: metadata::encode(&body).unwrap(), runtime: Runtime { size: 0.0, coarse_missing: None } };
let refused = validate_topology(&saved).err().map(|e| e.to_string()).unwrap_or_default();
let saved = Saved { solid: record, metadata: metadata::encode(&body).unwrap(), runtime: Runtime { size: 0.0, coarse_missing: None } };
let refused = file::check(&saved).err().map(|e| e.to_string()).unwrap_or_default();
assert!(refused.contains("item budget"), "{refused}");
}
-64
View File
@@ -1,64 +0,0 @@
//! Analytic wire records are mathematical loci, independent of backend parameterizations.
use super::*;
/// Exact rational conic locus. The adapter reparameterizes angle by rational spans.
pub(super) fn arc(frame: &b::Frame, radii: [f64; 2], angle: [f64; 2]) -> Result<mt::Curve> {
let span = angle[1] - angle[0];
let count = (span / std::f64::consts::FRAC_PI_2).ceil().clamp(1., 4.) as usize;
let step = span / count as f64;
let weight = (step / 2.).cos();
let at = |t: f64, scale: f64| p(frame.origin) + v(frame.x_axis) * (radii[0] * t.cos() / scale) + v(frame.y_axis) * (radii[1] * t.sin() / scale);
let mut controls = vec![at(angle[0], 1.).to_homogeneous()];
let mut knots = vec![0.; 3];
for i in 0..count {
let start = angle[0] + i as f64 * step;
controls.push(at(start + step / 2., weight).to_homogeneous() * weight);
controls.push(at(start + step, 1.).to_homogeneous());
knots.extend(std::iter::repeat_n((i + 1) as f64 / count as f64, if i + 1 == count { 3 } else { 2 }));
}
Ok(mt::Curve::NurbsCurve(mt::NurbsCurve::new(mt::BSplineCurve::try_new(knots.into(), controls).map_err(invalid)?)))
}
pub(super) fn revolved(profile: mt::Curve, origin: mt::Point3, axis: mt::Vector3, normal_flip: bool) -> mt::Surface {
let mut s = mt::Processor::new(mt::RevolutedCurve::by_revolution(profile, origin, axis));
// Internal parameter swapping is allowed; no such flag is persisted in a surface record.
if normal_flip {
s.invert();
}
mt::Surface::RevolutedCurve(s)
}
/// An unbounded analytic surface as a truck revolution, its profile over `height` (the face's
/// v range) for a cylinder or cone, and the whole meridian for a sphere or torus. Truck's
/// revolution has its own (u, v); the record's loops, not its parameters, bound the face. The
/// profile runs against the record's v so the revolution's (profile, angle) has the record's
/// natural normal unswapped, as truck's own revolutions are: the tessellator meets a cone's
/// apex or a sphere's pole at the profile's end, where it places it right (swapped, a drilled
/// hole's tip came out 41 % too large).
pub(super) fn load_analytic(surface: b::Surface, height: [f64; 2]) -> Result<mt::Surface> {
use std::f64::consts::{FRAC_PI_2, TAU};
let axis = |f: &b::Frame| v(f.x_axis).cross(v(f.y_axis));
Ok(match surface {
b::Surface::Cylinder { frame, radius } => {
let z = axis(&frame);
let at = |h| p(frame.origin) + v(frame.x_axis) * radius + z * h;
revolved(mt::Curve::Line(mt::Line(at(height[1]), at(height[0]))), p(frame.origin), z, false)
}
b::Surface::Cone { frame, radius_at_origin, half_angle } => {
let z = axis(&frame);
let at = |h| p(frame.origin) + v(frame.x_axis) * (radius_at_origin + h * half_angle.tan()) + z * h;
revolved(mt::Curve::Line(mt::Line(at(height[1]), at(height[0]))), p(frame.origin), z, false)
}
b::Surface::Sphere { frame, radius } => {
let z = axis(&frame);
let meridian = b::Frame { origin: frame.origin, x_axis: frame.x_axis, y_axis: vector(z) };
revolved(arc(&meridian, [radius; 2], [-FRAC_PI_2, FRAC_PI_2])?.inverse(), p(frame.origin), z, false)
}
b::Surface::Torus { frame, major_radius, minor_radius, .. } => {
let z = axis(&frame);
let profile = b::Frame { origin: point(p(frame.origin) + v(frame.x_axis) * major_radius), x_axis: frame.x_axis, y_axis: vector(z) };
revolved(arc(&profile, [minor_radius; 2], [0., TAU])?.inverse(), p(frame.origin), z, false)
}
_ => return Err(invalid("expected analytic surface")),
})
}
-635
View File
@@ -1,635 +0,0 @@
//! Bounded tagged binary values: integer and f64 bits stay exact, no base64/text numbers.
use super::*;
fn bytes<'a>(input: &mut &'a [u8], n: usize) -> Result<&'a [u8]> {
let head = input.get(..n).ok_or_else(|| invalid("truncated value"))?;
*input = input.get(n..).ok_or_else(|| invalid("truncated value"))?;
Ok(head)
}
fn length(input: &mut &[u8]) -> Result<usize> {
let raw: [u8; 4] = bytes(input, 4)?.try_into().map_err(invalid)?;
usize::try_from(u32::from_le_bytes(raw)).map_err(invalid)
}
fn string(input: &mut &[u8]) -> Result<String> {
let n = length(input)?;
if n > 1 << 20 {
return Err(invalid("string budget"));
}
Ok(std::str::from_utf8(bytes(input, n)?).map_err(invalid)?.to_owned())
}
pub(super) fn read(input: &mut &[u8], depth: usize, budget: &mut usize) -> Result<Value> {
if depth > 48 || *budget == 0 {
return Err(invalid("value budget/depth"));
}
*budget -= 1;
let tag = *bytes(input, 1)?.first().ok_or_else(|| invalid("tag"))?;
Ok(match tag {
0 => Value::Null,
1 => Value::Bool(false),
2 => Value::Bool(true),
3..=5 => {
let raw: [u8; 8] = bytes(input, 8)?.try_into().map_err(invalid)?;
Value::Number(match tag {
3 => Number::from(i64::from_le_bytes(raw)),
4 => Number::from(u64::from_le_bytes(raw)),
_ => Number::from_f64(f64::from_le_bytes(raw)).ok_or_else(|| invalid("non-finite number"))?,
})
}
6 => Value::String(string(input)?),
7 | 8 => {
let n = length(input)?;
if n > MAX_ITEMS || n > input.len() || n > *budget {
return Err(invalid("collection budget"));
}
if tag == 7 {
let mut a = Vec::new();
for _ in 0..n {
a.push(read(input, depth + 1, budget)?);
}
Value::Array(a)
} else {
let mut map = Map::new();
for _ in 0..n {
let key = string(input)?;
if map.contains_key(&key) {
return Err(invalid("duplicate key"));
}
map.insert(key, read(input, depth + 1, budget)?);
}
Value::Object(map)
}
}
_ => return Err(invalid("unknown binary tag")),
})
}
#[cfg(test)]
fn count(n: usize, out: &mut Vec<u8>) -> Result<()> {
out.extend_from_slice(&u32::try_from(n).map_err(invalid)?.to_le_bytes());
Ok(())
}
#[cfg(test)]
fn text(s: &str, out: &mut Vec<u8>) -> Result<()> {
count(s.len(), out)?;
out.extend_from_slice(s.as_bytes());
Ok(())
}
/// `value` appended to `out`. The encoder writes a body as it serializes
/// ([`write_serialized`]); this writes a value already built, as tests build hostile ones.
#[cfg(test)]
pub(super) fn write(value: &Value, out: &mut Vec<u8>, depth: usize) -> Result<()> {
if depth > 48 || out.len() > MAX_BYTES {
return Err(invalid("encoding budget"));
}
match value {
Value::Null => out.push(0),
Value::Bool(b) => out.push(if *b { 2 } else { 1 }),
Value::Number(n) => {
if n.is_f64() {
out.push(5);
out.extend_from_slice(&n.as_f64().ok_or_else(|| invalid("number"))?.to_le_bytes());
} else if let Some(n) = n.as_u64() {
out.push(4);
out.extend_from_slice(&n.to_le_bytes());
} else {
out.push(3);
out.extend_from_slice(&n.as_i64().ok_or_else(|| invalid("integer"))?.to_le_bytes());
}
}
Value::String(s) => {
out.push(6);
text(s, out)?;
}
Value::Array(a) => {
out.push(7);
count(a.len(), out)?;
for v in a {
write(v, out, depth + 1)?;
}
}
Value::Object(map) => {
out.push(8);
count(map.len(), out)?;
for (k, v) in map {
text(k, out)?;
write(v, out, depth + 1)?;
}
}
}
if out.len() > MAX_BYTES {
return Err(invalid("encoding size"));
}
Ok(())
}
/// Why a value could not be written (a serde error carries only its message).
#[derive(Debug)]
pub(super) struct WriteError(String);
impl std::fmt::Display for WriteError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for WriteError {}
impl serde::ser::Error for WriteError {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
WriteError(msg.to_string())
}
}
fn refuse(what: &str) -> WriteError {
WriteError(what.into())
}
type Written<T = ()> = std::result::Result<T, WriteError>;
/// `value` appended to `out` as the tagged binary value it is as JSON: the bytes [`write`] gives
/// for `serde_json::to_value(value)`, refused where that, the checks on its result
/// (`validate_value`, the [`MAX_VALUES`] budget) or [`write`] refuse. Written as it is
/// serialized, with no JSON value in between: a body's record is millions of values, and building
/// them all first was most of the cost of encoding it.
///
/// As JSON: a struct or a map is an object of its entries in key order (a JSON object's), its
/// keys strings (a map's keys may be strings, characters, booleans or integers, written as JSON
/// writes such keys); an enum variant without data its name, one with data an object of its name
/// and the data; an option its value or null; bytes an array of numbers. A number is an integer
/// (unsigned from 0 up, signed below) or a finite float; a float that is not finite is null.
///
/// Refused: nesting past 48, a string over 1 MiB, an array of more than [`MAX_ITEMS`], a float
/// over 1e12 in size, more than [`MAX_VALUES`] values, more than [`MAX_BYTES`] in `out`.
pub(super) fn write_serialized<T: serde::Serialize + ?Sized>(value: &T, out: &mut Vec<u8>) -> Result<()> {
let mut w = Writer { out, values: 0 };
value.serialize(Ser { w: &mut w, depth: 0 }).map_err(invalid)
}
struct Writer<'a> {
out: &'a mut Vec<u8>,
values: usize,
}
impl Writer<'_> {
/// Count a value at `depth` and write its tag.
fn start(&mut self, depth: usize, tag: u8) -> Written {
if depth > 48 {
return Err(refuse("nesting"));
}
self.values = self.values.saturating_add(1);
if self.values > MAX_VALUES {
return Err(refuse("value budget"));
}
self.out.push(tag);
self.fits()
}
fn fits(&self) -> Written {
if self.out.len() > MAX_BYTES { Err(refuse("encoding size")) } else { Ok(()) }
}
fn number(&mut self, depth: usize, tag: u8, bits: [u8; 8]) -> Written {
self.start(depth, tag)?;
self.out.extend_from_slice(&bits);
self.fits()
}
fn unsigned(&mut self, depth: usize, v: u64) -> Written {
self.number(depth, 4, v.to_le_bytes())
}
fn signed(&mut self, depth: usize, v: i64) -> Written {
match u64::try_from(v) {
Ok(u) => self.unsigned(depth, u),
Err(_) => self.number(depth, 3, v.to_le_bytes()),
}
}
fn float(&mut self, depth: usize, v: f64) -> Written {
if !v.is_finite() {
return self.start(depth, 0);
}
if v.abs() > 1e12 {
return Err(refuse("non-finite metadata"));
}
self.number(depth, 5, v.to_le_bytes())
}
fn length(&mut self, n: usize) -> Written {
self.out.extend_from_slice(&u32::try_from(n).map_err(|_| refuse("length"))?.to_le_bytes());
self.fits()
}
fn text(&mut self, s: &str) -> Written {
self.length(s.len())?;
self.out.extend_from_slice(s.as_bytes());
self.fits()
}
fn string(&mut self, depth: usize, s: &str) -> Written {
if s.len() > 1 << 20 {
return Err(refuse("string budget"));
}
self.start(depth, 6)?;
self.text(s)
}
/// Open a collection at `depth`: its tag and room for its count, which goes at the place
/// returned.
fn open(&mut self, depth: usize, tag: u8) -> Written<usize> {
self.start(depth, tag)?;
let at = self.out.len();
self.out.extend_from_slice(&[0; 4]);
self.fits()?;
Ok(at)
}
fn count_at(&mut self, at: usize, n: usize) -> Written {
let n = u32::try_from(n).map_err(|_| refuse("length"))?.to_le_bytes();
self.out.get_mut(at..at + 4).ok_or_else(|| refuse("count"))?.copy_from_slice(&n);
Ok(())
}
}
/// A value to write at a depth.
pub(super) struct Ser<'w, 'a> {
w: &'w mut Writer<'a>,
depth: usize,
}
impl<'w, 'a> Ser<'w, 'a> {
/// An object of one entry, named `variant`, whose value comes next (at the depth returned).
fn variant(self, variant: &str) -> Written<Ser<'w, 'a>> {
let at = self.w.open(self.depth, 8)?;
self.w.count_at(at, 1)?;
self.w.text(variant)?;
Ok(Ser { w: self.w, depth: self.depth + 1 })
}
fn array(self) -> Written<Array<'w, 'a>> {
let at = self.w.open(self.depth, 7)?;
Ok(Array { w: self.w, depth: self.depth, at, items: 0 })
}
fn object(self) -> Written<Object<'w, 'a>> {
let at = self.w.open(self.depth, 8)?;
Ok(Object { w: self.w, depth: self.depth, at, entries: Vec::new(), key: None })
}
}
/// An array being written: where its count goes, and how many items it has.
pub(super) struct Array<'w, 'a> {
w: &'w mut Writer<'a>,
depth: usize,
at: usize,
items: usize,
}
impl Array<'_, '_> {
fn item<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.items += 1;
if self.items > MAX_ITEMS {
return Err(refuse("array budget"));
}
value.serialize(Ser { w: self.w, depth: self.depth + 1 })
}
fn close(self) -> Written {
self.w.count_at(self.at, self.items)
}
}
/// An object being written: where its count goes, and each entry's key and where it ends. The
/// entries are written as they come and put in key order when it closes.
pub(super) struct Object<'w, 'a> {
w: &'w mut Writer<'a>,
depth: usize,
at: usize,
entries: Vec<(String, usize)>,
/// The key of the entry whose value comes next.
key: Option<String>,
}
impl Object<'_, '_> {
fn key(&mut self, key: String) -> Written {
self.w.text(&key)?;
self.key = Some(key);
Ok(())
}
fn value<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
let key = self.key.take().ok_or_else(|| refuse("an object's value without its key"))?;
value.serialize(Ser { w: self.w, depth: self.depth + 1 })?;
self.entries.push((key, self.w.out.len()));
Ok(())
}
fn entry<T: serde::Serialize + ?Sized>(&mut self, key: &str, value: &T) -> Written {
self.key(key.to_owned())?;
self.value(value)
}
fn close(self) -> Written {
let Object { w, at, entries, .. } = self;
let first = at + 4;
if !entries.windows(2).all(|p| p[0].0 < p[1].0) {
// In key order, as a JSON object (a map by key) holds them. A key twice would keep
// only its last value there; no record repeats one.
let mut spans: Vec<(&str, usize, usize)> = Vec::with_capacity(entries.len());
let mut start = first;
for (key, end) in &entries {
spans.push((key.as_str(), start, *end));
start = *end;
}
spans.sort_by(|a, b| a.0.cmp(b.0));
if spans.windows(2).any(|p| p[0].0 == p[1].0) {
return Err(refuse("duplicate key"));
}
let written = w.out.split_off(first);
for (_, start, end) in spans {
w.out.extend_from_slice(written.get(start - first..end - first).ok_or_else(|| refuse("object"))?);
}
}
w.count_at(at, entries.len())
}
}
/// A map key as JSON writes it: a string.
struct Key;
impl serde::Serializer for Key {
type Ok = String;
type Error = WriteError;
type SerializeSeq = serde::ser::Impossible<String, WriteError>;
type SerializeTuple = serde::ser::Impossible<String, WriteError>;
type SerializeTupleStruct = serde::ser::Impossible<String, WriteError>;
type SerializeTupleVariant = serde::ser::Impossible<String, WriteError>;
type SerializeMap = serde::ser::Impossible<String, WriteError>;
type SerializeStruct = serde::ser::Impossible<String, WriteError>;
type SerializeStructVariant = serde::ser::Impossible<String, WriteError>;
fn serialize_bool(self, v: bool) -> Written<String> {
Ok(v.to_string())
}
fn serialize_i8(self, v: i8) -> Written<String> {
Ok(v.to_string())
}
fn serialize_i16(self, v: i16) -> Written<String> {
Ok(v.to_string())
}
fn serialize_i32(self, v: i32) -> Written<String> {
Ok(v.to_string())
}
fn serialize_i64(self, v: i64) -> Written<String> {
Ok(v.to_string())
}
fn serialize_i128(self, v: i128) -> Written<String> {
Ok(v.to_string())
}
fn serialize_u8(self, v: u8) -> Written<String> {
Ok(v.to_string())
}
fn serialize_u16(self, v: u16) -> Written<String> {
Ok(v.to_string())
}
fn serialize_u32(self, v: u32) -> Written<String> {
Ok(v.to_string())
}
fn serialize_u64(self, v: u64) -> Written<String> {
Ok(v.to_string())
}
fn serialize_u128(self, v: u128) -> Written<String> {
Ok(v.to_string())
}
fn serialize_f32(self, _: f32) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_f64(self, _: f64) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_char(self, v: char) -> Written<String> {
Ok(v.to_string())
}
fn serialize_str(self, v: &str) -> Written<String> {
Ok(v.to_owned())
}
fn serialize_bytes(self, _: &[u8]) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_none(self) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_some<T: serde::Serialize + ?Sized>(self, _: &T) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_unit(self) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_unit_struct(self, _: &'static str) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_unit_variant(self, _: &'static str, _: u32, variant: &'static str) -> Written<String> {
Ok(variant.to_owned())
}
fn serialize_newtype_struct<T: serde::Serialize + ?Sized>(self, _: &'static str, value: &T) -> Written<String> {
value.serialize(self)
}
fn serialize_newtype_variant<T: serde::Serialize + ?Sized>(self, _: &'static str, _: u32, _: &'static str, _: &T) -> Written<String> {
Err(refuse("a map key must be a string"))
}
fn serialize_seq(self, _: Option<usize>) -> Written<Self::SerializeSeq> {
Err(refuse("a map key must be a string"))
}
fn serialize_tuple(self, _: usize) -> Written<Self::SerializeTuple> {
Err(refuse("a map key must be a string"))
}
fn serialize_tuple_struct(self, _: &'static str, _: usize) -> Written<Self::SerializeTupleStruct> {
Err(refuse("a map key must be a string"))
}
fn serialize_tuple_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Written<Self::SerializeTupleVariant> {
Err(refuse("a map key must be a string"))
}
fn serialize_map(self, _: Option<usize>) -> Written<Self::SerializeMap> {
Err(refuse("a map key must be a string"))
}
fn serialize_struct(self, _: &'static str, _: usize) -> Written<Self::SerializeStruct> {
Err(refuse("a map key must be a string"))
}
fn serialize_struct_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Written<Self::SerializeStructVariant> {
Err(refuse("a map key must be a string"))
}
}
impl<'w, 'a> serde::Serializer for Ser<'w, 'a> {
type Ok = ();
type Error = WriteError;
type SerializeSeq = Array<'w, 'a>;
type SerializeTuple = Array<'w, 'a>;
type SerializeTupleStruct = Array<'w, 'a>;
type SerializeTupleVariant = Array<'w, 'a>;
type SerializeMap = Object<'w, 'a>;
type SerializeStruct = Object<'w, 'a>;
type SerializeStructVariant = Object<'w, 'a>;
fn serialize_bool(self, v: bool) -> Written {
self.w.start(self.depth, if v { 2 } else { 1 })
}
fn serialize_i8(self, v: i8) -> Written {
self.w.signed(self.depth, v.into())
}
fn serialize_i16(self, v: i16) -> Written {
self.w.signed(self.depth, v.into())
}
fn serialize_i32(self, v: i32) -> Written {
self.w.signed(self.depth, v.into())
}
fn serialize_i64(self, v: i64) -> Written {
self.w.signed(self.depth, v)
}
fn serialize_i128(self, v: i128) -> Written {
match (u64::try_from(v), i64::try_from(v)) {
(Ok(u), _) => self.w.unsigned(self.depth, u),
(_, Ok(i)) => self.w.signed(self.depth, i),
_ => Err(refuse("number out of range")),
}
}
fn serialize_u8(self, v: u8) -> Written {
self.w.unsigned(self.depth, v.into())
}
fn serialize_u16(self, v: u16) -> Written {
self.w.unsigned(self.depth, v.into())
}
fn serialize_u32(self, v: u32) -> Written {
self.w.unsigned(self.depth, v.into())
}
fn serialize_u64(self, v: u64) -> Written {
self.w.unsigned(self.depth, v)
}
fn serialize_u128(self, v: u128) -> Written {
self.w.unsigned(self.depth, u64::try_from(v).map_err(|_| refuse("number out of range"))?)
}
fn serialize_f32(self, v: f32) -> Written {
self.w.float(self.depth, v.into())
}
fn serialize_f64(self, v: f64) -> Written {
self.w.float(self.depth, v)
}
fn serialize_char(self, v: char) -> Written {
self.w.string(self.depth, v.encode_utf8(&mut [0; 4]))
}
fn serialize_str(self, v: &str) -> Written {
self.w.string(self.depth, v)
}
fn serialize_bytes(self, v: &[u8]) -> Written {
let mut a = self.array()?;
for b in v {
a.item(b)?;
}
a.close()
}
fn serialize_none(self) -> Written {
self.w.start(self.depth, 0)
}
fn serialize_some<T: serde::Serialize + ?Sized>(self, value: &T) -> Written {
value.serialize(self)
}
fn serialize_unit(self) -> Written {
self.w.start(self.depth, 0)
}
fn serialize_unit_struct(self, _: &'static str) -> Written {
self.w.start(self.depth, 0)
}
fn serialize_unit_variant(self, _: &'static str, _: u32, variant: &'static str) -> Written {
self.w.string(self.depth, variant)
}
fn serialize_newtype_struct<T: serde::Serialize + ?Sized>(self, _: &'static str, value: &T) -> Written {
value.serialize(self)
}
fn serialize_newtype_variant<T: serde::Serialize + ?Sized>(self, _: &'static str, _: u32, variant: &'static str, value: &T) -> Written {
value.serialize(self.variant(variant)?)
}
fn serialize_seq(self, _: Option<usize>) -> Written<Array<'w, 'a>> {
self.array()
}
fn serialize_tuple(self, _: usize) -> Written<Array<'w, 'a>> {
self.array()
}
fn serialize_tuple_struct(self, _: &'static str, _: usize) -> Written<Array<'w, 'a>> {
self.array()
}
fn serialize_tuple_variant(self, _: &'static str, _: u32, variant: &'static str, _: usize) -> Written<Array<'w, 'a>> {
self.variant(variant)?.array()
}
fn serialize_map(self, _: Option<usize>) -> Written<Object<'w, 'a>> {
self.object()
}
fn serialize_struct(self, _: &'static str, _: usize) -> Written<Object<'w, 'a>> {
self.object()
}
fn serialize_struct_variant(self, _: &'static str, _: u32, variant: &'static str, _: usize) -> Written<Object<'w, 'a>> {
self.variant(variant)?.object()
}
}
impl serde::ser::SerializeSeq for Array<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_element<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.item(value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeTuple for Array<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_element<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.item(value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeTupleStruct for Array<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_field<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.item(value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeTupleVariant for Array<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_field<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.item(value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeMap for Object<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_key<T: serde::Serialize + ?Sized>(&mut self, key: &T) -> Written {
let key = key.serialize(Key)?;
self.key(key)
}
fn serialize_value<T: serde::Serialize + ?Sized>(&mut self, value: &T) -> Written {
self.value(value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeStruct for Object<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_field<T: serde::Serialize + ?Sized>(&mut self, key: &'static str, value: &T) -> Written {
self.entry(key, value)
}
fn end(self) -> Written {
self.close()
}
}
impl serde::ser::SerializeStructVariant for Object<'_, '_> {
type Ok = ();
type Error = WriteError;
fn serialize_field<T: serde::Serialize + ?Sized>(&mut self, key: &'static str, value: &T) -> Written {
self.entry(key, value)
}
fn end(self) -> Written {
self.close()
}
}
+7 -5
View File
@@ -1,7 +1,8 @@
//! Explicit conversions between runtime metadata and the versioned wire records.
use super::{Result, invalid};
use crate::{Body, FaceSource, history as h};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3, brep::envelope as w};
use solidcore_record::brep::envelope as w;
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
fn index(n: usize) -> Result<u32> {
u32::try_from(n).map_err(invalid)
@@ -32,7 +33,8 @@ fn segment(s: &Seg2) -> Result<w::Segment> {
Seg2::Conic { a, apex, b, w } => w::Segment::Conic { points: [a, apex, b].map(point2), middle_weight: w },
Seg2::Bezier { n, p } => {
let count = usize::from(n) + 1;
if !(5..=solidcraft_geom::MAX_BEZIER_CTRL).contains(&count) || p.get(count..).is_none_or(|unused| unused.iter().any(|p| *p != Vec2::ZERO))
if !(5..=solidcore_record::MAX_BEZIER_CTRL).contains(&count)
|| p.get(count..).is_none_or(|unused| unused.iter().any(|p| *p != Vec2::ZERO))
{
return Err(invalid("unsupported certificate Bezier layout"));
}
@@ -47,10 +49,10 @@ fn load_segment(s: w::Segment) -> Result<Seg2> {
w::Segment::Cubic { points: [a, b, c, d] } => Seg2::Cubic { p0: p2(a), p1: p2(b), p2: p2(c), p3: p2(d) },
w::Segment::Conic { points: [a, apex, b], middle_weight } => Seg2::Conic { a: p2(a), apex: p2(apex), b: p2(b), w: middle_weight },
w::Segment::Bezier { points } => {
if !(5..=solidcraft_geom::MAX_BEZIER_CTRL).contains(&points.len()) {
if !(5..=solidcore_record::MAX_BEZIER_CTRL).contains(&points.len()) {
return Err(invalid("certificate Bezier degree"));
}
let mut p = [Vec2::ZERO; solidcraft_geom::MAX_BEZIER_CTRL];
let mut p = [Vec2::ZERO; solidcore_record::MAX_BEZIER_CTRL];
let n = (points.len() - 1) as u8;
for (slot, value) in p.iter_mut().zip(points) {
*slot = p2(value);
@@ -325,7 +327,7 @@ mod tests {
for value in sources {
assert_eq!(value, source(&load_source(value.clone(), 0).unwrap(), 0).unwrap());
}
assert!(load_segment(w::Segment::Bezier { points: vec![[0., 0.]; solidcraft_geom::MAX_BEZIER_CTRL + 1] }).is_err());
assert!(load_segment(w::Segment::Bezier { points: vec![[0., 0.]; solidcore_record::MAX_BEZIER_CTRL + 1] }).is_err());
}
#[test]
+1 -1
View File
@@ -25,7 +25,7 @@ pub fn native_preview_mesh(body: &Body, detail: usize, remaining: &mut usize) ->
#[cfg(test)]
mod tests {
use super::*;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
#[test]
fn native_preview_is_finite_and_budgeted_before_meshing() {
for body in [
@@ -2,7 +2,7 @@
//! volume.
use std::f64::consts::PI;
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use crate::{Body, box_solid, cylinder, sphere, torus};
@@ -69,7 +69,7 @@ fn extruded_circles_go_as_cylinders() {
use solidcraft_smlib::flat;
let body = cylinder(v(0., 50., -60.), v(0., 0., 1.), 40.0, 120.0).unwrap();
let record = super::brep_record(&body).unwrap();
let walls = record.faces.iter().filter(|f| matches!(f.surface, solidcraft_geom::brep::Surface::Cylinder { .. })).count();
let walls = record.faces.iter().filter(|f| matches!(f.surface, solidcore_record::brep::Surface::Cylinder { .. })).count();
assert_eq!((walls, record.faces.len()), (1, 3));
let arrays = solidcraft_smlib::import::arrays(&record, true).unwrap();
let kinds = &arrays.ints[&flat::FACE_SURFACE_TYPE];
@@ -99,7 +99,7 @@ fn a_cavity_comes_back_from_smlib() {
/// square to the axis (annular sectors), its walls cylinders.
#[test]
fn a_revolved_annulus_goes_with_its_flat_faces() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let square =
Region2 { outer: Loop2::polygon(&[Vec2::new(4., 12.), Vec2::new(12., 12.), Vec2::new(12., 20.), Vec2::new(4., 20.)]), holes: vec![] };
let plane = Plane { y: v(0., 0., 1.), ..Plane::XZ };
@@ -114,7 +114,7 @@ fn a_revolved_annulus_goes_with_its_flat_faces() {
/// A drill point (a cone ending in its apex) through SMLib and back measures as it went in.
#[test]
fn a_cone_apex_comes_back_measuring_as_it_went() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
let r = 3.4;
let h = r / (59f64.to_radians()).tan();
let profile =
+2 -1
View File
@@ -4,9 +4,10 @@
//! numbers are defined here: the segments of the caller's regions in order, each region its outer
//! loop and then its holes ([`profile_loops`]).
use solidcraft_geom::prelude::*;
use std::collections::BTreeSet;
use solidcraft_geom::{Loop2, Region2, Seg2};
use solidcore_record::{Loop2, Region2, Seg2};
/// The loops of `regions` in profile order: each region's outer loop, then its holes.
pub(crate) fn profile_loops(regions: &[Region2]) -> impl Iterator<Item = &Loop2> {
+4 -3
View File
@@ -3,8 +3,9 @@
//! Moving faces along their normals (offset faces, shell, draft) is SMLib's
//! (`crate::offset_backend`).
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::{Brep, Frame, Loop, Surface};
use solidcore_record::Vec3;
use solidcore_record::brep::{Brep, Frame, Loop, Surface};
use solidcraft_geom::prelude::*;
use crate::body::Body;
@@ -38,7 +39,7 @@ fn axes(f: &Frame) -> Option<(Vec3, Vec3)> {
pub(crate) fn surf_of(b: &Brep, face: usize) -> Option<Surf> {
let f = b.faces.get(face)?;
// `forward` is about the face's NURBS form, which may run against its surface.
let out = crate::assemble::natural_out(b, face)? != f.form_turns()?;
let out = crate::assemble::natural_out(b, face)? != solidcraft_geom::brep::label::form_turns(f)?;
let sign = if out { 1.0 } else { -1.0 };
Some(match &f.surface {
Surface::Plane { origin, u_axis, v_axis } => {
+3 -2
View File
@@ -12,9 +12,10 @@
//! ([`FaceOrigin::Offset`]), and its edges as where its faces meet. A face SMLib makes new along
//! a sheet's open edge (a thickened sheet's wall) is recorded as made in place of that edge.
use solidcraft_geom::prelude::*;
use std::collections::{BTreeMap, BTreeSet};
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_smlib::{Brep, CheckLevel, Error as SmError};
use crate::body::Body;
@@ -145,7 +146,7 @@ pub(crate) fn thicken(b: &Body, thickness: f64, symmetric: bool) -> Result<Body>
/// tilted by `angle` about their lines on `neutral`, leaning in going along `pull`; the faces
/// around them extended or trimmed to meet them. A tilted face is the face itself (Modified).
/// A face SMLib can't draft (not flat, or not parallel to the pull) is "not supported yet".
pub(crate) fn draft(b: &Body, at: &[Vec3], neutral: &solidcraft_geom::Plane, pull: Vec3, angle: f64) -> Result<Body> {
pub(crate) fn draft(b: &Body, at: &[Vec3], neutral: &solidcore_record::Plane, pull: Vec3, angle: f64) -> Result<Body> {
if !angle.is_finite() || angle.abs() >= std::f64::consts::FRAC_PI_2 - 1e-3 {
return Err(KernelError::Invalid("draft angle must be between −90° and 90°".into()));
}
+15 -13
View File
@@ -2,8 +2,10 @@
//! from each other join without any intersection work, their records side by side.
use serde::{Deserialize, Serialize};
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::{part, placement::Rigid};
use solidcore_record::Vec3;
use solidcore_record::brep::part;
use solidcraft_geom::brep::placement::Rigid;
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::history::{BodyHistory, History};
@@ -136,7 +138,7 @@ pub(crate) fn join_pieces(pieces: Vec<Body>) -> Result<Option<Body>> {
/// The records of `bodies` side by side, as one body, and where its items come from.
fn joined(bodies: &[Body]) -> Result<(Body, part::Part)> {
let records: Vec<&solidcraft_geom::brep::Brep> = bodies.iter().map(Body::record).collect();
let records: Vec<&solidcore_record::brep::Brep> = bodies.iter().map(Body::record).collect();
let part = part::compound(&records).map_err(|e| KernelError::Failed(format!("pieces: {e}")))?;
// Each face's source, numbered as `compound` numbers the inputs: one after another.
let sources: Vec<Option<crate::FaceSource>> =
@@ -166,7 +168,7 @@ pub fn transform_matrix(body: &Body, m: [[f64; 4]; 4]) -> Result<Body> {
let sources = body.transformed_sources(m)?;
let (placed, sources, paint) = match Rigid::of_matrix(&m) {
Some(motion) => {
let moved = Body::from_record(body.record().moved(&motion))?;
let moved = Body::from_record(solidcraft_geom::brep::placement::moved(body.record(), &motion))?;
let history = History::identity(&moved);
(moved.with_history(history, &[body])?, sources, body.paint().cloned())
}
@@ -248,7 +250,7 @@ pub fn transform(body: &Body, translate: Vec3, origin: Vec3, axis: Vec3, angle:
/// Split a body with a plane: the parts on the positive and the negative side of the plane
/// (only the non-empty ones).
pub fn split_by_plane(body: &Body, plane: &solidcraft_geom::Plane) -> Result<Vec<Body>> {
pub fn split_by_plane(body: &Body, plane: &solidcore_record::Plane) -> Result<Vec<Body>> {
let _span = solidcraft_profile::span("kernel", "split_by_plane");
let mut out = Vec::new();
for positive in [true, false] {
@@ -261,7 +263,7 @@ pub fn split_by_plane(body: &Body, plane: &solidcraft_geom::Plane) -> Result<Vec
/// cut with: the part is the body's intersection with [`half_box`] (the tool), whose history it
/// carries, over the body and the box. The box's face in the plane, the part's cut face, is its
/// start cap on the positive side and its end cap on the negative side.
pub fn half_space(body: &Body, plane: &solidcraft_geom::Plane, positive: bool) -> Result<(Option<Body>, Body)> {
pub fn half_space(body: &Body, plane: &solidcore_record::Plane, positive: bool) -> Result<(Option<Body>, Body)> {
let _span = solidcraft_profile::span("kernel", "half_space");
// The box's own construction roles describe no face of the design: the cut face has none.
let tool = half_box(body, plane, positive)?.with_face_sources(None);
@@ -269,17 +271,17 @@ pub fn half_space(body: &Body, plane: &solidcraft_geom::Plane, positive: bool) -
}
/// A box covering everything of `body` on one side of a plane, its start cap in the plane.
pub(crate) fn half_box(body: &Body, plane: &solidcraft_geom::Plane, positive: bool) -> Result<Body> {
pub(crate) fn half_box(body: &Body, plane: &solidcore_record::Plane, positive: bool) -> Result<Body> {
body.require_brep("split")?;
let bb = body.exact_bounds()?;
let reach = (bb.diagonal() + plane.origin.dist(bb.center())) * 2.0 + body.size();
let c = plane.to_local(bb.center());
let sq = solidcraft_geom::Region2 {
outer: solidcraft_geom::Loop2::polygon(&[
solidcraft_geom::Vec2::new(c.x - reach, c.y - reach),
solidcraft_geom::Vec2::new(c.x + reach, c.y - reach),
solidcraft_geom::Vec2::new(c.x + reach, c.y + reach),
solidcraft_geom::Vec2::new(c.x - reach, c.y + reach),
let sq = solidcore_record::Region2 {
outer: solidcore_record::Loop2::polygon(&[
solidcore_record::Vec2::new(c.x - reach, c.y - reach),
solidcore_record::Vec2::new(c.x + reach, c.y - reach),
solidcore_record::Vec2::new(c.x + reach, c.y + reach),
solidcore_record::Vec2::new(c.x - reach, c.y + reach),
]),
holes: vec![],
};
+2 -1
View File
@@ -1,9 +1,10 @@
//! A lip swept along the rim of a round body joins it, flush with its side or set in from it:
//! the lip's foot lies on the body's top, and its sides are round where the rim is.
use solidcraft_geom::prelude::*;
use std::f64::consts::{FRAC_PI_2, PI};
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::*;
+1 -1
View File
@@ -3,7 +3,7 @@
//! along a line give separate shells, and near-tangent numbers from the sketch solver (a
//! circle 1e-13 mm past the side) behave like exact ones.
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::*;
+2 -2
View File
@@ -48,8 +48,8 @@ fn periodic_step_seam_survives_identity_rotation_and_translation() {
// A face whose loop uses an edge twice (the seam).
let seamed = body.record().faces.iter().any(|f| {
f.loops.iter().any(|l| match l {
solidcraft_geom::brep::Loop::Edges { edges } => edges.iter().any(|u| edges.iter().filter(|w| w.edge == u.edge).count() > 1),
solidcraft_geom::brep::Loop::Vertex { .. } => false,
solidcore_record::brep::Loop::Edges { edges } => edges.iter().any(|u| edges.iter().filter(|w| w.edge == u.edge).count() > 1),
solidcore_record::brep::Loop::Vertex { .. } => false,
})
});
assert!(seamed);
+4 -3
View File
@@ -2,9 +2,10 @@
//! A wall swept along a spiral has a flat top and bottom that are B-spline faces: a join of two
//! such walls, whose tops and bottoms coincide.
use solidcraft_geom::prelude::*;
use std::f64::consts::TAU;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use crate::*;
@@ -114,12 +115,12 @@ fn interleaved_spiral_walls_join() {
#[test]
fn a_cut_of_an_extruded_spline_keeps_its_spline_wall() {
let p = Vec2::new;
let line = |a: Vec2, b: Vec2| solidcraft_geom::Seg2::Line { a, b };
let line = |a: Vec2, b: Vec2| solidcore_record::Seg2::Line { a, b };
let outline = Loop2 {
segs: vec![
line(p(0.0, 0.0), p(40.0, 0.0)),
line(p(40.0, 0.0), p(40.0, 20.0)),
solidcraft_geom::Seg2::Cubic { p0: p(40.0, 20.0), p1: p(30.0, 35.0), p2: p(10.0, 5.0), p3: p(0.0, 20.0) },
solidcore_record::Seg2::Cubic { p0: p(40.0, 20.0), p1: p(30.0, 35.0), p2: p(10.0, 5.0), p3: p(0.0, 20.0) },
line(p(0.0, 20.0), p(0.0, 0.0)),
],
};
+3 -2
View File
@@ -4,8 +4,9 @@
//! every other edge kept by a point at its middle).
use super::Body;
use crate::{KernelError, Result, guard};
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::{self, eval::CurveEval};
use solidcore_record::Vec3;
use solidcore_record::brep::{self};
use solidcraft_geom::brep::eval::CurveEval;
use std::sync::Arc;
/// Points along a record edge (ends and three inside).
+4 -3
View File
@@ -2,8 +2,9 @@
//! No tessellated face names, centroids, or nearest-plane choices are used.
use super::{Body, FaceSource};
use crate::{KernelError, Result, guard};
use solidcraft_geom::brep::{self, Surface};
use solidcraft_geom::{Plane, Vec3};
use solidcore_record::brep::{self, Surface};
use solidcore_record::{Plane, Vec3};
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
@@ -735,7 +736,7 @@ mod tests {
#[test]
fn pocket_cut_removes_internal_wall_faces_in_actual_topology() {
use solidcraft_geom::{Loop2, Region2, Vec2};
use solidcore_record::{Loop2, Region2, Vec2};
let region = Region2 {
outer: Loop2::polygon(&[Vec2::new(-30., -27.), Vec2::new(30., -27.), Vec2::new(30., 27.), Vec2::new(-30., 27.)]),
holes: vec![],
+1 -1
View File
@@ -1,6 +1,6 @@
//! The area vector of a loop of points (Newell's method): its normal and the area it encloses.
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
/// The area vector of a closed polygon (Newell's method): normal to the loop, as long as the area
/// it encloses, pointing the way the loop runs round by the right-hand rule.
+9 -8
View File
@@ -6,10 +6,11 @@
//! [`PathSeg::Bezier`] ([`SpaceBezier`]); [`PointPath::points`] is its polyline, for what takes
//! points (rails, curve networks).
use solidcraft_geom::brep;
use solidcore_record::brep;
use solidcore_record::{MAX_BEZIER_CTRL, MAX_BEZIER_DEGREE, Plane, Region2, Vec3};
use solidcraft_geom::bspline::{HPoint, bezier_point, segment};
use solidcraft_geom::catmull_rom;
use solidcraft_geom::{MAX_BEZIER_CTRL, MAX_BEZIER_DEGREE, Plane, Region2, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::{KernelError, PathSeg, Result, SweepControl};
@@ -189,7 +190,7 @@ pub fn project_onto_face(
body: &Body,
face_at: Vec3,
plane: &Plane,
segs: &[solidcraft_geom::Seg2],
segs: &[solidcore_record::Seg2],
direction: Vec3,
) -> Result<Vec<(brep::Curve, [f64; 2])>> {
if !(face_at.is_finite() && direction.is_finite() && direction.len() > 1e-12) || segs.is_empty() || segs.len() > 4096 {
@@ -306,14 +307,14 @@ pub fn curve_path(c: &brep::Curve, [t0, t1]: [f64; 2]) -> Result<Vec<PathSeg>> {
/// segment's way: a line, a circle (an arc's; clockwise ones on the frame turned over), a cubic
/// or Bézier as a spline of its degree, a conic as a rational quadratic. `None` for a segment
/// with non-finite numbers.
pub fn sketch_record_curve(plane: &Plane, s: &solidcraft_geom::Seg2) -> Option<(brep::Curve, [f64; 2])> {
use solidcraft_geom::Seg2;
let w = |p: solidcraft_geom::Vec2| {
pub fn sketch_record_curve(plane: &Plane, s: &solidcore_record::Seg2) -> Option<(brep::Curve, [f64; 2])> {
use solidcore_record::Seg2;
let w = |p: solidcore_record::Vec2| {
let q = plane.to_world(p);
[q.x, q.y, q.z]
};
let d = |v: Vec3| [v.x, v.y, v.z];
let bezier = |pts: &[solidcraft_geom::Vec2]| {
let bezier = |pts: &[solidcore_record::Vec2]| {
let n = pts.len().checked_sub(1)?;
let knots = std::iter::repeat_n(0.0, n + 1).chain(std::iter::repeat_n(1.0, n + 1)).collect();
Some((brep::Curve::Spline { knots, points: pts.iter().map(|p| w(*p)).collect() }, [0.0, 1.0]))
@@ -328,7 +329,7 @@ pub fn sketch_record_curve(plane: &Plane, s: &solidcraft_geom::Seg2) -> Option<(
Seg2::Cubic { p0, p1, p2, p3 } => bezier(&[p0, p1, p2, p3])?,
Seg2::Bezier { n, p } => bezier(p.get(..=usize::from(n))?)?,
Seg2::Conic { a, apex, b, w: wt } => {
let h = |p: solidcraft_geom::Vec2, k: f64| {
let h = |p: solidcore_record::Vec2, k: f64| {
let q = w(p);
[q[0] * k, q[1] * k, q[2] * k, k]
};
+3 -1
View File
@@ -3,9 +3,11 @@
//! SMLib's boolean takes with the body as it is. The result's history is over the body and the
//! mesh, the mesh's faces being its triangles.
use solidcraft_geom::prelude::*;
use std::collections::{BTreeMap, BTreeSet};
use solidcraft_geom::{Mesh, Vec3};
use solidcore_record::Vec3;
use solidcraft_geom::Mesh;
use crate::body::Body;
use crate::heal::find;
+5 -4
View File
@@ -4,10 +4,11 @@
//! planes (vertices are triple-plane intersections, edges lines, faces planes, pcurves exact),
//! taken by SMLib and checked there.
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::{self as rec, Curve2, EdgeUseRef, Loop, OrientedEdge, OrientedFace};
use solidcore_record::Vec3;
use solidcore_record::brep::{self as rec, Curve2, EdgeUseRef, Loop, OrientedEdge, OrientedFace};
use crate::body::Body;
use crate::{KernelError, Result};
@@ -180,7 +181,7 @@ fn polyhedron_record(hs: &[HalfSpace], verts: &[Vec3], faces: &[(usize, Vec<usiz
edges,
vertices,
};
brep.validate().map_err(|e| KernelError::Failed(format!("polyhedron: {e}")))?;
solidcraft_geom::brep::check::validate(&brep).map_err(|e| KernelError::Failed(format!("polyhedron: {e}")))?;
Ok(brep)
}
@@ -196,7 +197,7 @@ pub fn shell(b: &Body, open: &[Vec3], thickness: f64) -> Result<Body> {
/// Tilt the faces near `faces` by `angle` about their line on the neutral plane, so that they
/// lean in (positive angle) going along `pull` (SMLib's draft).
pub fn draft(b: &Body, faces: &[Vec3], neutral: &solidcraft_geom::Plane, pull: Vec3, angle: f64) -> Result<Body> {
pub fn draft(b: &Body, faces: &[Vec3], neutral: &solidcore_record::Plane, pull: Vec3, angle: f64) -> Result<Body> {
let _span = solidcraft_profile::span("kernel", "draft");
b.require_brep("draft")?;
crate::offset_backend::draft(b, faces, neutral, pull, angle)
+10 -9
View File
@@ -4,7 +4,8 @@
//! result's boundaries are the operands' curves, cut at their crossings and never refitted.
//! Also the test of whether a record surface is a wall swept along a direction.
use solidcraft_geom::{Plane, Region2, Seg2, Vec2};
use solidcore_record::{Plane, Region2, Seg2, Vec2};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::{BoolOp, KernelError, Result};
@@ -109,10 +110,10 @@ struct Regions {
}
mod sheets {
use solidcraft_geom::Loop2;
use solidcraft_geom::Vec3;
use solidcraft_geom::brep::Loop;
use solidcraft_geom::brep::Surface;
use solidcore_record::Loop2;
use solidcore_record::Vec3;
use solidcore_record::brep::Loop;
use solidcore_record::brep::Surface;
use solidcraft_smlib::{BooleanOp, Brep};
use super::*;
@@ -292,7 +293,7 @@ mod sheets {
#[allow(clippy::unwrap_used, clippy::panic)]
mod planar_tests {
use super::*;
use solidcraft_geom::Loop2;
use solidcore_record::Loop2;
#[test]
fn single_prism_intersection_uses_common_height_in_both_orders() {
for k in [1.0, 0.05] {
@@ -303,9 +304,9 @@ mod planar_tests {
(22.5, 10.0, None),
(25.0, 10.0, None),
] {
let a = crate::cylinder(solidcraft_geom::Vec3::new(12.5, 5.0, 5.0) * k, solidcraft_geom::Vec3::Z, 2.5 * k, 17.5 * k).unwrap();
let b =
crate::box_solid(solidcraft_geom::Vec3::new(10.0, 5.0, lo) * k, solidcraft_geom::Vec3::new(22.5, 10.0, lo + height) * k).unwrap();
let a = crate::cylinder(solidcore_record::Vec3::new(12.5, 5.0, 5.0) * k, solidcore_record::Vec3::Z, 2.5 * k, 17.5 * k).unwrap();
let b = crate::box_solid(solidcore_record::Vec3::new(10.0, 5.0, lo) * k, solidcore_record::Vec3::new(22.5, 10.0, lo + height) * k)
.unwrap();
for (lhs, rhs) in [(&a, &b), (&b, &a)] {
let result = crate::boolean(lhs, rhs, BoolOp::Intersect).unwrap();
if let Some((bottom, top)) = expected {
+6 -5
View File
@@ -2,10 +2,11 @@
//! record edges. A record's lines and circles are read as they are; a spline is read span by
//! span (its Bézier pieces): samples propose a circle, and only positive rational Bernstein
//! bounds accept it.
use solidcore_record::brep::{Brep, Curve};
use solidcore_record::{Plane, Seg2, Vec2, Vec3};
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::brep::{Brep, Curve};
use solidcraft_geom::bspline::{self, HPoint};
use solidcraft_geom::{Plane, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
const MAX_DEGREE: usize = 32;
/// How far an arc read off a curve may end from the curve's end (mm): half the gap a profile
@@ -587,7 +588,7 @@ fn off_chord(pts: &[Vec2]) -> f64 {
/// One Bézier span that is neither a line nor an arc, as the exact free-form segment it is
/// (a font's quadratic or cubic, a conic), its ends `a` and `b`. `None` for several spans (a
/// curve that may wind about more than once), degrees past [`solidcraft_geom::MAX_BEZIER_DEGREE`],
/// curve that may wind about more than once), degrees past [`solidcore_record::MAX_BEZIER_DEGREE`],
/// rational spans other than conics, and control polygons with no area (a curve doubling back
/// along a line).
fn free_form(spans: &[Vec<H>], a: Vec2, b: Vec2, tol: f64) -> Option<Vec<Seg2>> {
@@ -755,8 +756,8 @@ mod tests {
/// `c` over its whole domain, run forward (or back).
fn run(c: &Curve, forward: bool) -> Run<'_> {
let interval = match c.natural() {
solidcraft_geom::brep::Natural::Range(a, b) => [a, b],
solidcraft_geom::brep::Natural::Periodic => [0., std::f64::consts::TAU],
solidcore_record::brep::Natural::Range(a, b) => [a, b],
solidcore_record::brep::Natural::Periodic => [0., std::f64::consts::TAU],
};
let ends = [at(c, interval[0]), at(c, interval[1])];
Run { curve: c, interval, forward, ends: if forward { ends } else { [ends[1], ends[0]] } }
+10 -8
View File
@@ -1,9 +1,11 @@
//! Independent current-geometry intervals for uniform prisms, read off the body's schema 4
//! record. These are not mesh measurements or certificates of construction history.
use crate::prism_curve::{Run, segment};
use solidcore_record::brep::{Brep, Curve, Loop, Shell, Surface};
use solidcore_record::{Plane, Seg2, Vec2, Vec3};
use solidcraft_geom::Ring;
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::brep::{Brep, Curve, Loop, Shell, Surface};
use solidcraft_geom::{Plane, Ring, Seg2, Vec2, Vec3};
use solidcraft_geom::prelude::*;
fn v3(p: [f64; 3]) -> Vec3 {
Vec3::new(p[0], p[1], p[2])
@@ -645,7 +647,7 @@ pub struct PrismSection {
pub lo: f64,
pub hi: f64,
/// Its section, exact: lines and arcs, the outer loop counter-clockwise, the holes clockwise.
pub region: solidcraft_geom::Region2,
pub region: solidcore_record::Region2,
/// How far the levels may be off the body's caps (the caps' vertices lie within it of them).
pub tolerance: f64,
}
@@ -668,7 +670,7 @@ pub fn certified_prism_section(body: &crate::Body, plane: &Plane) -> crate::Resu
let mut holes = Vec::new();
for lp in c.loops {
let positive = lp.area.lo > 0.;
let lp = solidcraft_geom::Loop2 { segs: lp.segments.into_vec() };
let lp = solidcore_record::Loop2 { segs: lp.segments.into_vec() };
if positive {
if outer.replace(lp).is_some() {
return Ok(None);
@@ -681,7 +683,7 @@ pub fn certified_prism_section(body: &crate::Body, plane: &Plane) -> crate::Resu
// The caps' vertices are within twice the tolerance of their levels (`certificate`), and
// the levels are worked out from the plane's origin.
let tolerance = 2. * tol + 128. * f64::EPSILON * (plane.origin.len() + c.lo.abs() + c.hi.abs()).max(1.);
Ok(Some(PrismSection { lo: c.lo, hi: c.hi, region: solidcraft_geom::Region2 { outer, holes }, tolerance }))
Ok(Some(PrismSection { lo: c.lo, hi: c.hi, region: solidcore_record::Region2 { outer, holes }, tolerance }))
})
}
@@ -850,7 +852,7 @@ mod tests {
use super::*;
fn drilled(radius: f64, shift: f64) -> crate::Body {
use solidcraft_geom::{Loop2, Region2};
use solidcore_record::{Loop2, Region2};
let region = Region2 {
outer: Loop2::polygon(&[Vec2::ZERO, Vec2::new(20., 0.), Vec2::new(20., 20.), Vec2::new(0., 20.)]),
holes: vec![Loop2::circle(Vec2::new(10. + shift, 10.), radius)],
@@ -877,7 +879,7 @@ mod tests {
/// above it steps (the pin stands up through it) and is no prism.
#[test]
fn a_trimmed_tool_reads_as_the_prism_of_its_current_section() {
use solidcraft_geom::{Loop2, Region2};
use solidcore_record::{Loop2, Region2};
let pin = crate::cylinder(Vec3::new(25., 25., 0.), Vec3::Z, 2., 20.).unwrap();
let stop = crate::box_solid(Vec3::new(19., 19., 1.), Vec3::new(31., 31., 2.)).unwrap();
let roof = crate::boolean(&pin, &stop, crate::BoolOp::Union).unwrap().unwrap();
@@ -1026,7 +1028,7 @@ mod tests {
let retraced =
CapLoop { segments: Ring::from([arc, arc.reversed(), arc]), area: Interval::enclosing(36. * std::f64::consts::PI, 1e-8).unwrap() };
assert!(circle(&retraced, 1e-6).is_none());
let region = solidcraft_geom::Loop2::polygon(&[Vec2::ZERO, Vec2::new(20., 0.), Vec2::new(20., 20.), Vec2::new(0., 20.)]);
let region = solidcore_record::Loop2::polygon(&[Vec2::ZERO, Vec2::new(20., 0.), Vec2::new(20., 20.), Vec2::new(0., 20.)]);
let doubled = CapLoop { segments: region.segs.iter().chain(&region.segs).copied().collect(), area: Interval::enclosing(800., 1e-8).unwrap() };
assert!(separated_material(&[doubled], 1e-6, &mut 16_000_000).is_none());
// Thinner than a body's tolerance (2e-5): SMLib refuses it as a solid; built, it gets none.
+2 -2
View File
@@ -166,7 +166,7 @@ mod tests {
#[test]
fn a_faceted_boolean_is_boolean_time_and_a_reference_mesh_tessellation() {
use crate::{BoolOp, box_solid, faceted_boolean};
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
let a = box_solid(Vec3::ZERO, Vec3::new(10.0, 10.0, 10.0)).unwrap();
let tool = box_solid(Vec3::new(5.0, 5.0, 5.0), Vec3::new(15.0, 15.0, 15.0)).unwrap().mesh(&crate::MeshTolerance::chord(0.1)).unwrap();
// The thread groove's route: the faceting it does first is the boolean's time too.
@@ -181,7 +181,7 @@ mod tests {
#[test]
fn kernel_operations_are_profiler_spans_with_smlib_calls_inside() {
use crate::{BoolOp, boolean, box_solid};
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
solidcraft_profile::set_enabled(true);
let mark = solidcraft_profile::mark();
let a = box_solid(Vec3::ZERO, Vec3::new(10.0, 10.0, 10.0)).unwrap();
+6 -3
View File
@@ -8,9 +8,11 @@
//! name the same one. Operations that know more (which profile segment a side face sweeps,
//! which edge a blend replaces) fill in generated faces' origins themselves.
use solidcraft_geom::prelude::*;
use std::collections::BTreeSet;
use solidcraft_geom::{Aabb3, Mesh, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Plane, Region2, Seg2, Vec2, Vec3};
use solidcraft_geom::{Aabb3, Mesh};
use crate::Result;
use crate::body::Body;
@@ -376,7 +378,8 @@ pub fn compose(prov: &mut History, operand: usize, tool: &[FaceOrigin]) {
#[cfg(test)]
mod tests {
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use super::{Change, FaceOrigin, trace};
use crate::{BoolOp, boolean, box_solid, cylinder};
@@ -437,7 +440,7 @@ mod tests {
#[test]
fn provenance_of_sweeps_blends_and_shells() {
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
use solidcore_record::{Loop2, Plane, Region2, Vec2};
use super::{History, blend_origins, compose, extrude_origins, offset_origins, revolve_origins};
let plane = Plane::named("XY").unwrap();
+2 -2
View File
@@ -7,7 +7,7 @@
use std::collections::BTreeSet;
use solidcraft_geom::brep::Brep;
use solidcore_record::brep::Brep;
use crate::body::Body;
use crate::history::{Change, EdgeOrigin, EdgeProv, FaceOrigin, FaceProv, History, edge_faces};
@@ -39,7 +39,7 @@ pub(crate) fn generated(origins: Vec<FaceOrigin>) -> FaceProv {
FaceProv { origins, change: Change::Generated }
}
pub(crate) use solidcraft_geom::brep::history::mark_shared_split;
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`.
+2 -1
View File
@@ -1,9 +1,10 @@
//! The creation builders' histories: every face's origin checked against the geometry the
//! builder made it from.
use solidcraft_geom::prelude::*;
use std::f64::consts::{FRAC_PI_2, PI, TAU};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use crate::body::Body;
use crate::build::PathSeg;
@@ -1,5 +1,5 @@
use super::*;
use solidcraft_geom::Plane;
use solidcore_record::Plane;
fn stamped_stock() -> Body {
crate::box_solid(Vec3::new(-20., -15., 0.), Vec3::new(20., 15., 24.)).unwrap().with_box_certificate(7).unwrap()
+7 -6
View File
@@ -16,9 +16,10 @@
//! Nothing is moved: a face rebuilt keeps its surface, a sewn edge keeps its curve (SMLib keeps
//! one of the pair), a patch is a new face. What was done comes back in [`RepairReport`].
use solidcraft_geom::Vec3;
use solidcore_record::Vec3;
use solidcore_record::brep::{self as b, Brep};
use solidcraft_geom::brep::eval::CurveEval;
use solidcraft_geom::brep::{self as b, Brep};
use solidcraft_geom::prelude::*;
use crate::body::{Body, SurfaceKind};
use crate::{Continuity, KernelError, Result};
@@ -250,12 +251,12 @@ fn rebuild_refused(record: &mut Brep, report: &mut RepairReport) -> Result<()> {
/// Face `f` of `r` rebuilt on its own surface: a cylinder, cone, sphere or torus face on a
/// NURBS form of the surface laid on arcs from where the face starts
/// ([`b::form::surface_on_own_arcs`]) instead of its frame's quarter grid, the same surface
/// ([`solidcraft_geom::brep::form::surface_on_own_arcs`]) instead of its frame's quarter grid, the same surface
/// exactly, with SMLib's own trims of the face's edges on it (`SmlibTrims`, as the import makes the
/// trims it has no closed form for). The face's edges and loops stay as they were. `None` for a
/// face on another surface.
fn rebuilt_face(r: &Brep, f: usize) -> Result<Option<b::Face>> {
use b::pcurve::{TrimEdge, TrimFace, TrimUse, Trims};
use solidcraft_geom::brep::pcurve::{TrimEdge, TrimFace, TrimUse, Trims};
let face = r.faces.get(f).ok_or_else(|| invalid(format!("no face {f}")))?;
if !matches!(face.surface, b::Surface::Cylinder { .. } | b::Surface::Cone { .. } | b::Surface::Sphere { .. } | b::Surface::Torus { .. }) {
return Ok(None);
@@ -304,8 +305,8 @@ fn rebuilt_face(r: &Brep, f: usize) -> Result<Option<b::Face>> {
.iter()
.map(|&v| r.vertices.get(v as usize).map(|v| v.point).ok_or_else(|| invalid(format!("no vertex {v}"))))
.collect::<Result<Vec<_>>>()?;
let extent = b::form::extent(&face.surface, &boundary).ok_or_else(|| invalid("its boundary does not lie on its surface"))?;
let (form, domain) = b::form::surface_on_own_arcs(
let extent = solidcraft_geom::brep::form::extent(&face.surface, &boundary).ok_or_else(|| invalid("its boundary does not lie on its surface"))?;
let (form, domain) = solidcraft_geom::brep::form::surface_on_own_arcs(
&face.surface,
extent,
local.iter().filter_map(|&e| r.edges.get(e as usize)).map(|e| e.tolerance).fold(r.tolerance, f64::max),
+1 -1
View File
@@ -1,7 +1,7 @@
//! Round faces read from STEP: a whole turn bounded by one wire that runs along its seam twice.
//! A boolean whose intersection loop lies wholly inside such a face is exact.
use crate::*;
use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Vec2, Vec3};
use std::f64::consts::PI;
const R: f64 = 4.5;
+13 -9
View File
@@ -10,12 +10,15 @@
//! body from. No tolerance stitching is involved: two sheets of material meeting along one
//! geometric edge keep an edge each.
use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
use solidcore_record::Vec3;
use solidcore_record::brep::{self as b, Curve2};
use solidcraft_geom::Ring;
use solidcraft_geom::brep::eval::{SurfaceEval, face_flux};
use solidcraft_geom::brep::{self as b, Curve2, pcurve};
use solidcraft_geom::{Ring, Vec3};
use solidcraft_geom::brep::pcurve;
use crate::body::Body;
use crate::{KernelError, Result, guard};
@@ -1379,7 +1382,7 @@ pub(crate) fn assemble(parts: Parts, solid: bool) -> Result<Assembled> {
// keeps it, and an edge the caller gave a pcurve for keeps the parameter that pcurve is on.
let mut frames_of: Vec<Vec<b::Frame>> = vec![Vec::new(); edges.len()];
for f in &faces {
let Some(frame) = b::form::frame_of(&f.surface) else { continue };
let Some(frame) = solidcraft_geom::brep::form::frame_of(&f.surface) else { continue };
for u in f.loops.iter().flatten() {
if let Some(slot) = frames_of.get_mut(u.edge as usize) {
slot.push(frame.clone());
@@ -1390,8 +1393,8 @@ pub(crate) fn assemble(parts: Parts, solid: bool) -> Result<Assembled> {
let mut forms: Vec<Option<(b::Curve, [f64; 2])>> = Vec::with_capacity(edges.len());
for ((e, frames), given) in edges.iter().zip(&frames_of).zip(&given_on) {
if let Some(form) = &e.nurbs {
let on_label =
b::curve_interval(&e.curve, Some(form), e.interval).ok_or_else(|| fail("an edge's NURBS form does not evaluate".into()))?;
let on_label = solidcraft_geom::brep::label::curve_interval(&e.curve, Some(form), e.interval)
.ok_or_else(|| fail("an edge's NURBS form does not evaluate".into()))?;
labels.push((e.curve.clone(), on_label));
forms.push(Some((form.clone(), e.interval)));
continue;
@@ -1402,7 +1405,7 @@ pub(crate) fn assemble(parts: Parts, solid: bool) -> Result<Assembled> {
continue;
}
let (label, interval, form) =
b::form::edge(&e.curve, e.interval, frames.iter(), tol).ok_or_else(|| fail("an arc of more than one turn".into()))?;
solidcraft_geom::brep::form::edge(&e.curve, e.interval, frames.iter(), tol).ok_or_else(|| fail("an arc of more than one turn".into()))?;
labels.push((label, interval));
forms.push(form);
}
@@ -1432,8 +1435,9 @@ pub(crate) fn assemble(parts: Parts, solid: bool) -> Result<Assembled> {
.iter()
.map(|l| l.iter().filter_map(|&(e, forward, _)| labels.get(e as usize).map(|(c, i)| (c, *i, forward))).collect())
.collect();
let extent = b::form::extent(&f.surface, &boundary).ok_or_else(|| fail(format!("face {fi}: its boundary is not on its surface")))?;
Some(b::form::surface(&f.surface, extent).ok_or_else(|| fail(format!("face {fi}: more than one turn")))?)
let extent = solidcraft_geom::brep::form::extent(&f.surface, &boundary)
.ok_or_else(|| fail(format!("face {fi}: its boundary is not on its surface")))?;
Some(solidcraft_geom::brep::form::surface(&f.surface, extent).ok_or_else(|| fail(format!("face {fi}: more than one turn")))?)
}
_ => None,
};
@@ -1636,7 +1640,7 @@ fn domain_of(surface: &b::Surface, pcs: &[Vec<Curve2>]) -> Option<[[f64; 2]; 2]>
}
}
}
let natural = surface.natural();
let natural = solidcraft_geom::brep::label::surface_natural(surface);
let mut out = [[0.0; 2]; 2];
for d in 0..2 {
let (mut a, mut z) = (lo[d], hi[d]);
+3 -1
View File
@@ -1,7 +1,9 @@
//! Group disconnected material regions without moving a cavity to another enclosing shell.
//! A valid shell hierarchy alternates material and void at every nesting level.
use solidcraft_geom::{Aabb3, BoxedTriangle, Mesh, Vec3, find_close_pair};
use solidcore_record::Vec3;
use solidcraft_geom::prelude::*;
use solidcraft_geom::{Aabb3, BoxedTriangle, Mesh, find_close_pair};
use crate::{KernelError, Result};
+14 -8
View File
@@ -17,7 +17,8 @@
//! revolutions); the face in the start plane is the start cap, the one in the end plane (or,
//! where the sweep has no end plane, the planar face left over) the end cap.
use solidcraft_geom::{Plane, Region2, Seg2, Vec3};
use solidcore_record::{Plane, Region2, Seg2, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
use crate::numbered::{NumberedLoop, NumberedRegion};
@@ -86,7 +87,7 @@ mod imp {
use solidcraft_smlib::sweeps::{Affine, Curve, DraftCorner, Ends, SweepFrame};
use solidcraft_smlib::{Brep, CheckLevel};
use solidcraft_geom::Vec2;
use solidcore_record::Vec2;
use super::*;
use crate::history::FaceProv;
@@ -172,7 +173,7 @@ mod imp {
/// The body (a solid or a sheet) a schema 4 record describes, taken by SMLib as a
/// modeller's own record (no healing) and checked there.
pub(crate) fn body_from_record(record: &solidcraft_geom::brep::Brep, what: &str) -> Result<Body> {
pub(crate) fn body_from_record(record: &solidcore_record::brep::Brep, what: &str) -> Result<Body> {
let brep = Brep::from_record(record, true).map_err(|e| failed(what, e))?;
body_of(brep, what)
}
@@ -187,7 +188,7 @@ mod imp {
plane: &Plane,
segs: &[Seg2],
direction: Vec3,
) -> Result<Vec<(solidcraft_geom::brep::Curve, [f64; 2])>> {
) -> Result<Vec<(solidcore_record::brep::Curve, [f64; 2])>> {
let c = segs.iter().map(|s| curve(plane, s)).collect::<Result<Vec<_>>>()?;
let out = body
.smlib()?
@@ -198,7 +199,12 @@ mod imp {
/// The face of `body` at `face_at` cut by the plane through `plane_point` square to `normal`,
/// SMLib's section curves on that face, as record curves on their intervals.
pub(crate) fn face_section(body: &Body, face_at: Vec3, plane_point: Vec3, normal: Vec3) -> Result<Vec<(solidcraft_geom::brep::Curve, [f64; 2])>> {
pub(crate) fn face_section(
body: &Body,
face_at: Vec3,
plane_point: Vec3,
normal: Vec3,
) -> Result<Vec<(solidcore_record::brep::Curve, [f64; 2])>> {
let out = body
.smlib()?
.face_section(p(face_at), pick_reach(body), p(plane_point), p(normal), curve_tolerance(body))
@@ -226,12 +232,12 @@ mod imp {
}
/// SMLib's NURBS curves as record curves (rational splines) on their intervals.
fn record_curves(out: Vec<(Curve, [f64; 2])>, what: &str) -> Result<Vec<(solidcraft_geom::brep::Curve, [f64; 2])>> {
fn record_curves(out: Vec<(Curve, [f64; 2])>, what: &str) -> Result<Vec<(solidcore_record::brep::Curve, [f64; 2])>> {
out.into_iter()
.map(|(c, interval)| match c {
Curve::Nurbs { points, knots, .. } => {
let homogeneous = points.iter().map(|q| [q[0] * q[3], q[1] * q[3], q[2] * q[3], q[3]]).collect();
Ok((solidcraft_geom::brep::Curve::RationalSpline { knots, homogeneous }, interval))
Ok((solidcore_record::brep::Curve::RationalSpline { knots, homogeneous }, interval))
}
_ => Err(failed(what, "a curve SMLib made is not a B-spline")),
})
@@ -1083,7 +1089,7 @@ mod imp {
/// The centre and radius of `lp` when it is one circle (in one or several arcs) centred on the
/// line through `start` along the unit `k`.
fn circle_on_axis(plane: &Plane, lp: &solidcraft_geom::Loop2, start: Vec3, k: Vec3) -> Option<(Vec3, f64)> {
fn circle_on_axis(plane: &Plane, lp: &solidcore_record::Loop2, start: Vec3, k: Vec3) -> Option<(Vec3, f64)> {
let mut circle: Option<(Vec3, f64)> = None;
let mut turn = 0.0;
for s in &lp.segs {
+2 -1
View File
@@ -1,9 +1,10 @@
//! The sweeps through SMLib ([`crate::smlib_sweeps`]): analytic volumes, and the history and
//! construction sources the builders' vocabulary gives each face.
use solidcraft_geom::prelude::*;
use std::f64::consts::{PI, TAU};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use crate::FaceSource;
use crate::body::Body;
+9 -7
View File
@@ -14,9 +14,11 @@
//! display-only: the edge keeps its identity, stays pickable and stays in the wireframe, and its
//! faces stay apart (pieces of one surface are [`crate::topo::seam_flags`]'s business). Unknown
//! geometry (a station that does not evaluate) keeps its existing presentation.
use solidcore_record::Vec3;
use solidcore_record::brep::{Brep, Loop, Shell};
use solidcraft_geom::Mesh;
use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};
use solidcraft_geom::brep::{Brep, Loop, Shell};
use solidcraft_geom::{Mesh, Vec3};
use solidcraft_geom::prelude::*;
use crate::body::Body;
@@ -163,7 +165,7 @@ fn join(record: &Brep, faces: &[Option<FaceEval>], e: usize, length: f64, work:
let unknown = Join::default();
let Some(edge) = record.edges.get(e) else { return unknown };
let [a, b] = edge.uses.as_slice() else { return unknown };
let side = |u: &solidcraft_geom::brep::EdgeUseRef| {
let side = |u: &solidcore_record::brep::EdgeUseRef| {
let face = faces.get(u.face as usize)?.as_ref()?;
let Loop::Edges { edges } = record.faces.get(u.face as usize)?.loops.get(u.r#loop as usize)? else { return None };
let used = edges.get(u.position as usize)?;
@@ -180,7 +182,7 @@ fn join(record: &Brep, faces: &[Option<FaceEval>], e: usize, length: f64, work:
let Some(left) = work.checked_sub(2) else { return unknown };
*work = left;
let t = t0 + (t1 - t0) * (k as f64 + 0.5) / STATIONS as f64;
let (Some(ua), Some(ub)) = (pa.eval(t), pb.eval(t)) else { return unknown };
let (Some(ua), Some(ub)) = (solidcraft_geom::brep::pcurve::eval(pa, t), solidcraft_geom::brep::pcurve::eval(pb, t)) else { return unknown };
let (Some(sa), Some(sb)) = (station(fa, ua), station(fb, ub)) else { return unknown };
let (Some(sa), Some(sb)) = (sa, sb) else { continue };
let angle = sa.normal.cross(sb.normal).len().atan2(sa.normal.dot(sb.normal));
@@ -344,8 +346,8 @@ fn whole_joins(record: &Brep, measured: &[usize], smooth: &mut [bool], mut work:
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use solidcraft_geom::brep::Surface;
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2};
use solidcore_record::brep::Surface;
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2};
fn circle(radius: f64, count: usize) -> Loop2 {
let step = std::f64::consts::TAU / count as f64;
@@ -584,7 +586,7 @@ mod tests {
fn a_degenerate_normal_says_nothing() {
let face = FaceEval {
surface: SurfaceEval::new(&Surface::Sphere {
frame: solidcraft_geom::brep::Frame { origin: [0.; 3], x_axis: [1., 0., 0.], y_axis: [0., 1., 0.] },
frame: solidcore_record::brep::Frame { origin: [0.; 3], x_axis: [1., 0., 0.], y_axis: [0., 1., 0.] },
radius: 2.,
})
.unwrap(),
+1 -1
View File
@@ -2,7 +2,7 @@
//! cylinders encloses the target and only touches the sphere.
use crate::history::BodyHistory;
use crate::{Body, BoolOp};
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use solidcore_record::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
use std::f64::consts::{FRAC_PI_2, PI};
fn dome() -> Body {

Some files were not shown because too many files have changed in this diff Show More