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>
139 lines
7.4 KiB
Rust
139 lines
7.4 KiB
Rust
use serde_json::{Value, json};
|
||
use solidcore_record::Vec3;
|
||
use solidcraft_geom::prelude::*;
|
||
|
||
use crate::Session;
|
||
|
||
fn run(s: &mut Session, id: &str, p: Value) -> Value {
|
||
match s.execute(id, &p) {
|
||
Ok(v) => v,
|
||
Err(e) => panic!("{id} {p}: {e}"),
|
||
}
|
||
}
|
||
|
||
/// A tray: a base `w` x 200 (its width a sketch dimension: the parameter returned), 1 mm thick
|
||
/// with 1 mm bends, front and back flanges 30 high in one feature, left and right in another,
|
||
/// and a 6.6 mm hole in the base: the two flange features' ids.
|
||
fn tray(s: &mut Session, w: f64) -> (String, u64, u64) {
|
||
run(s, "sheet.manage_rules", json!({"name": "R1", "thickness": "1 mm", "bend_radius": "1 mm", "active": true}));
|
||
run(s, "sketch.create", json!({"plane": "XY", "name": "Base"}));
|
||
run(s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [w, 200]}));
|
||
let d = run(s, "sketch.dimension", json!({"entities": ["l1"], "value": w}));
|
||
run(s, "sketch.finish", json!({}));
|
||
run(s, "sheet.flange", json!({"sketch": "Base"}));
|
||
run(s, "sheet.flange", json!({"edges": [[100, 0, 1], [100, 200, 1]], "height": 30}));
|
||
let front_back = s.doc.features.last().map_or(0, |f| f.id);
|
||
run(s, "sheet.flange", json!({"edges": [[0, 100, 1], [w, 100, 1]], "height": 30}));
|
||
let sides = s.doc.features.last().map_or(0, |f| f.id);
|
||
run(s, "solid.hole", json!({"position": [100, 100, 1], "diameter": 6.6}));
|
||
let param = d["param"].as_str().or_else(|| d["name"].as_str()).map(str::to_string).unwrap_or_else(|| "d1".into());
|
||
(param, front_back, sides)
|
||
}
|
||
|
||
/// Each face's readable sheet name, with its centroid and cylinder radius.
|
||
fn faces(s: &mut Session) -> Vec<(Option<String>, Vec3, Option<f64>)> {
|
||
let body = s.model.state().bodies.first().map(|b| b.name.clone()).unwrap_or_default();
|
||
let r = run(s, "model.faces", json!({"body": body}));
|
||
r["faces"]
|
||
.as_array()
|
||
.into_iter()
|
||
.flatten()
|
||
.map(|f| {
|
||
let c = &f["centroid"];
|
||
let at = Vec3::new(c[0].as_f64().unwrap_or(f64::NAN), c[1].as_f64().unwrap_or(f64::NAN), c[2].as_f64().unwrap_or(f64::NAN));
|
||
(f["sheet_face"].as_str().map(str::to_string), at, f["cylinder"]["radius"].as_f64())
|
||
})
|
||
.collect()
|
||
}
|
||
|
||
fn named<'a>(faces: &'a [(Option<String>, Vec3, Option<f64>)], name: &str) -> Vec<&'a (Option<String>, Vec3, Option<f64>)> {
|
||
faces.iter().filter(|f| f.0.as_deref() == Some(name)).collect()
|
||
}
|
||
|
||
/// The point on the face with this name, as a command taking a face name finds it.
|
||
fn point(s: &Session, name: &str) -> Vec3 {
|
||
solidcraft_doc::naming::named_face_point(&s.model.state(), None, name).unwrap_or_else(|e| panic!("{name}: {e}"))
|
||
}
|
||
|
||
#[test]
|
||
fn a_trays_faces_have_readable_sheet_names_that_follow_its_size() {
|
||
let mut s = Session::default();
|
||
let (width, fb, sd) = tray(&mut s, 320.0);
|
||
let all = faces(&mut s);
|
||
// Every face but the hole's wall (r 3.3, however many faces the kernel makes it of) has a
|
||
// sheet name, and no two faces share one.
|
||
let unnamed: Vec<_> = all.iter().filter(|f| f.0.is_none()).collect();
|
||
assert!(!unnamed.is_empty() && unnamed.iter().all(|f| f.2.is_some_and(|r| (r - 3.3).abs() < 1e-6)), "only the hole's wall: {unnamed:?}");
|
||
let mut names: Vec<&str> = all.iter().filter_map(|f| f.0.as_deref()).collect();
|
||
names.sort_unstable();
|
||
let n = names.len();
|
||
names.dedup();
|
||
assert_eq!(names.len(), n, "{names:?}");
|
||
for (name, at) in [
|
||
("sheet:Body1:base:top".to_string(), Vec3::new(160.0, 100.0, 1.0)),
|
||
("sheet:Body1:base:bottom".to_string(), Vec3::new(160.0, 100.0, 0.0)),
|
||
(format!("sheet:Body1:F{sd}.1:top"), Vec3::new(319.0, 100.0, 16.0)),
|
||
(format!("sheet:Body1:F{sd}.1:bottom"), Vec3::new(320.0, 100.0, 16.0)),
|
||
(format!("sheet:Body1:F{sd}.1:rim.far"), Vec3::new(319.5, 100.0, 30.0)),
|
||
(format!("sheet:Body1:F{fb}.0:bottom"), Vec3::new(160.0, 0.0, 16.0)),
|
||
// The front flange runs on past its bend to the right one, under its corner.
|
||
(format!("sheet:Body1:F{fb}.0:rim.ext1"), Vec3::new(319.0, 0.5, 2.0)),
|
||
] {
|
||
let f = named(&all, &name);
|
||
assert!(f.len() == 1 && f[0].1.dist(at) < 2.5, "{name}: {f:?}");
|
||
}
|
||
// A bend's two curved faces: its radius and the radius plus the thickness.
|
||
let radius = |name: &str| named(&all, name).first().and_then(|f| f.2);
|
||
assert_eq!(radius(&format!("sheet:Body1:F{fb}.0:bend.inner")).map(|r| (r * 1e6).round() / 1e6), Some(1.0));
|
||
assert_eq!(radius(&format!("sheet:Body1:F{fb}.0:bend.outer")).map(|r| (r * 1e6).round() / 1e6), Some(2.0));
|
||
// 80 mm wider: the same names, each on the same face where it now is. A name's point is
|
||
// somewhere on its face: the right flange's top is the plane x = w − 1, the back flange's
|
||
// far rim the strip z = 30, 199 <= y <= 200 (the flange 1 thick, its outside at y = 200).
|
||
let right = point(&s, &format!("sheet:Body1:F{sd}.1:top"));
|
||
assert!((right.x - 319.0).abs() < 1e-3, "{right:?}");
|
||
run(&mut s, "parameters.change", json!({"name": width, "expression": "400"}));
|
||
let wider = faces(&mut s);
|
||
let mut again: Vec<&str> = wider.iter().filter_map(|f| f.0.as_deref()).collect();
|
||
again.sort_unstable();
|
||
assert_eq!(again, names);
|
||
let right = point(&s, &format!("sheet:Body1:F{sd}.1:top"));
|
||
assert!((right.x - 399.0).abs() < 1e-3, "{right:?}");
|
||
let far = point(&s, &format!("sheet:Body1:F{fb}.1:rim.far"));
|
||
assert!((199.0 - 1e-3..=200.0 + 1e-3).contains(&far.y) && (0.0..=400.0).contains(&far.x) && (far.z - 30.0).abs() < 1e-3, "{far:?}");
|
||
}
|
||
|
||
#[test]
|
||
fn a_flanges_sheet_names_hold_when_another_flange_goes() {
|
||
let mut s = Session::default();
|
||
let (_, fb, sd) = tray(&mut s, 320.0);
|
||
let right = format!("sheet:Body1:F{sd}.1:top");
|
||
let before = point(&s, &right);
|
||
run(&mut s, "timeline.suppress", json!({"feature": fb, "suppressed": true}));
|
||
let after = point(&s, &right);
|
||
assert!((after.x - 319.0).abs() < 1e-3 && (after.z - before.z).abs() < 16.0, "{before:?} {after:?}");
|
||
// The names of the flanges that went are gone; asking for one says so.
|
||
let gone = format!("sheet:Body1:F{fb}.0:top");
|
||
assert!(solidcraft_doc::naming::named_face_point(&s.model.state(), None, &gone).is_err());
|
||
assert!(solidcraft_doc::naming::named_face_point(&s.model.state(), Some("Body2"), &right).is_err());
|
||
}
|
||
|
||
/// A fold at 45° across a strip, with a bend zone wide for the strip: about a third of the bend's
|
||
/// faces lies beyond the ends of its start line, along the bend, and they still take its names.
|
||
#[test]
|
||
fn a_bend_askew_across_a_sheet_keeps_its_names() {
|
||
let mut s = Session::default();
|
||
run(&mut s, "sheet.manage_rules", json!({"name": "R10", "thickness": "1 mm", "bend_radius": "10 mm", "active": true}));
|
||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Strip"}));
|
||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [200, 20]}));
|
||
run(&mut s, "sketch.finish", json!({}));
|
||
run(&mut s, "sheet.flange", json!({"sketch": "Strip"}));
|
||
run(&mut s, "sheet.fold", json!({"points": [[90, -5, 1], [115, 20, 1]], "fixed": [10, 10, 1]}));
|
||
let fold = s.doc.features.last().map_or(0, |f| f.id);
|
||
let all = faces(&mut s);
|
||
for (side, radius) in [("inner", 10.0), ("outer", 11.0)] {
|
||
let name = format!("sheet:Body1:F{fold}.0:bend.{side}");
|
||
let f = named(&all, &name);
|
||
assert!(f.len() == 1 && f[0].2.is_some_and(|r| (r - radius).abs() < 1e-6), "{name}: {all:?}");
|
||
}
|
||
}
|