mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-15 21:20:54 +00:00
dc38349cbf
* Kernel: the B-rep record and the native body file come from solidcore-record
SolidCraft's portable B-rep record (`solidcraft_geom::brep`: brep.rs, topology, history,
envelope, part, curve2) and the native body file (`solidcraft_kernel::native`: the tagged binary
codec and the container) move to solidcore's `solidcore-record` crate: geometry as data, with
structural validation and no maths (solidcore's docs/layers.md, stage 1). Every caller uses
`solidcore_record::brep` and `solidcore_record::native`; the old copies are deleted.
What computes from coordinates stays with the kernel, in geom's `brep`:
- `brep::check`: the record's geometric checks (orthonormal frames, non-degenerate planes,
unit revolution axes, non-singular placements). `check::validate` and
`check::validate_built` are the record's validation and these together, and every caller of
`Brep::validate` uses them, so what is accepted is unchanged;
- `brep::label`: a surface's natural ranges (a cone's apex), `curve_interval`,
`edge_curve_interval` and `form_turns`;
- `brep::pcurve::eval`: a pcurve's point;
- `geometry::check`, `placement::moved` and `split_edges` become functions on the record.
The kernel's native module keeps the conversion between a body and its saved record
(metadata.rs) and checks the decoded record's geometry. `native/analytic.rs`, which no module
declared, is deleted.
solidcore-record is pinned to its rev on solidcore's `layer-record` branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
* Geometry: Vec2, Vec3, Plane and the profile types come from solidcore-record
The plain data of vectors and points, sketch planes and planar profiles (`Seg2`, `Loop2`,
`Region2`) moves to `solidcore-record`, with its constants and component-wise operators only
(owner decision, solidcore layer split). Their geometry stays in geom as traits:
`Vec2Geom`, `Vec3Geom`, `PlaneGeom`, `Seg2Geom`, `Loop2Geom`, `Region2Geom`, `Seg2ArcFit`,
`Loop2ArcFit` and `Region2ArcFit`, in scope with `use solidcraft_geom::prelude::*`. Every caller
names the types from `solidcore_record`; geom no longer defines or re-exports them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
* Kernel: pin solidcore-record to solidcore main f5e8e9a29
solidcore-record is merged on solidcore main (tangency-labs/solidcore#2519); its crate there is
identical to the rev pinned before but for its clippy configuration. The lock is regenerated
against the merged rev.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
---------
Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
4.1 KiB
Rust
90 lines
4.1 KiB
Rust
//! Straight edges stay one edge after many cuts (#1049). The owner's design
|
|
//! (`tests/action_matrix/designs/crazy-geom-cuts.sc`, saved by 0.10.0): five extrudes,
|
|
//! joins and cuts, over four sketches, three of them on faces of the body with the faces'
|
|
//! edges projected. Cuts used to leave the straight edges of the walls they sliced split at
|
|
//! vertices nothing else used, so an edge that is one straight line was drawn (and lit on hover)
|
|
//! as many pieces, and a sketch on such a face projected every piece.
|
|
|
|
use solidcraft_engine::geom::prelude::*;
|
|
use std::collections::HashMap;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use serde_json::json;
|
|
use solidcore_record::Vec3;
|
|
use solidcraft_engine::Session;
|
|
use solidcraft_engine::doc::kernel::{FaceSurface, face_surface};
|
|
|
|
fn design() -> PathBuf {
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/action_matrix/designs/crazy-geom-cuts.sc")
|
|
}
|
|
|
|
fn open(path: &Path) -> Session {
|
|
let mut s = Session::default();
|
|
s.execute("doc.open", &json!({"path": path.to_string_lossy()})).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
|
s
|
|
}
|
|
|
|
/// The design built from scratch: saved without cached geometry and opened again.
|
|
fn rebuilt() -> Session {
|
|
let s = open(&design());
|
|
let dir = std::env::temp_dir().join(format!("solidcraft-straight-edges-{}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
let path = dir.join("crazy-geom-cuts.json");
|
|
let mut t = s.scratch();
|
|
t.execute("file.save", &json!({"path": path.to_string_lossy(), "format": "json"})).unwrap();
|
|
let out = open(&path);
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
out
|
|
}
|
|
|
|
fn errors(s: &Session) -> Vec<(u64, String)> {
|
|
s.model.results.iter().filter_map(|r| r.error.clone().map(|e| (r.id, e))).collect()
|
|
}
|
|
|
|
fn key(v: Vec3) -> [i64; 3] {
|
|
[v.x, v.y, v.z].map(|c| (c * 1e5).round() as i64)
|
|
}
|
|
|
|
#[test]
|
|
fn straight_edges_are_one_edge_after_many_cuts() {
|
|
for (what, s) in [("as saved", open(&design())), ("built from scratch", rebuilt())] {
|
|
assert_eq!(errors(&s), vec![], "{what}: every feature evaluates");
|
|
let st = s.world_state().unwrap();
|
|
let bodies: Vec<_> = st.bodies.iter().filter(|b| !b.body.is_mesh()).collect();
|
|
assert_eq!(bodies.len(), 1, "{what}: one body");
|
|
let body = &bodies[0].body;
|
|
let mesh = body.mesh(&solidcraft_kernel::MeshTolerance::chord(0.01)).unwrap();
|
|
// Every edge is drawn as one polyline; a straight one as one segment.
|
|
let mut at: HashMap<[i64; 3], Vec<usize>> = HashMap::new();
|
|
for (i, e) in mesh.edges.iter().enumerate() {
|
|
let (Some(a), Some(z)) = (e.first(), e.last()) else { panic!("{what}: edge {i} is empty") };
|
|
at.entry(key(*a)).or_default().push(i);
|
|
at.entry(key(*z)).or_default().push(i);
|
|
}
|
|
let straight = |i: usize| mesh.edges.get(i).filter(|e| e.len() == 2).and_then(|e| (e[1] - e[0]).normalized());
|
|
let split: Vec<_> = at
|
|
.iter()
|
|
.filter(|(_, es)| match es.as_slice() {
|
|
[a, b] => straight(*a).zip(straight(*b)).is_some_and(|(u, w)| u.dot(w).abs() > 1. - 1e-9),
|
|
_ => false,
|
|
})
|
|
.map(|(k, _)| k.map(|c| c as f64 / 1e5))
|
|
.collect();
|
|
assert_eq!(split, Vec::<[f64; 3]>::new(), "{what}: straight edges split where nothing else meets them");
|
|
// No two faces side by side in one plane.
|
|
let plane = |f: usize| match face_surface(body, f) {
|
|
Some(FaceSurface::Plane { normal, point }) => Some((normal, normal.dot(point))),
|
|
_ => None,
|
|
};
|
|
for (i, faces) in mesh.edge_faces.iter().enumerate() {
|
|
if let [a, b] = faces.as_slice()
|
|
&& a != b
|
|
&& let (Some((na, da)), Some((nb, db))) = (plane(*a as usize), plane(*b as usize))
|
|
{
|
|
assert!(na.dot(nb) < 1. - 1e-9 || (da - db).abs() > 1e-6, "{what}: faces {a} and {b} meet at edge {i} in one plane");
|
|
}
|
|
}
|
|
assert_eq!((body.face_count(), body.edge_count(), body.vertex_count()), (35, 107, 71), "{what}: faces, edges and vertices");
|
|
}
|
|
}
|