Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Wave 258/509: Cargo.lock: resolved for the merged manifests (and 3 more)

jyvikod6dacbd6d82a
diff --git a/Cargo.lock b/Cargo.lock
index 2d7acdb880..15c547f20a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -188,15 +188,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "approx"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
-dependencies = [
- "num-traits",
-]
-
[[package]]
name = "arboard"
version = "3.6.1"
@@ -217,12 +208,6 @@ dependencies = [
"x11rb",
]
-[[package]]
-name = "array-macro"
-version = "2.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "220a2c618ab466efe41d0eace94dfeff1c35e3aa47891bdb95e1c0fefffd3c99"
-
[[package]]
name = "arrayref"
version = "0.3.9"
@@ -535,15 +520,6 @@ dependencies = [
"piper",
]
-[[package]]
-name = "branches"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f11502672c5570f77f6bdf573332483f8475bab6a7fda00f1fae8ddb5a6245c0"
-dependencies = [
- "rustc_version",
-]
-
[[package]]
name = "bumpalo"
version = "3.20.3"
@@ -791,17 +767,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "cgmath"
-version = "0.18.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
-dependencies = [
- "approx",
- "num-traits",
- "serde",
-]
-
[[package]]
name = "chacha20"
version = "0.10.2"
@@ -824,19 +789,6 @@ dependencies = [
"memchr",
]
-[[package]]
-name = "chrono"
-version = "0.4.45"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
-dependencies = [
- "iana-time-zone",
- "js-sys",
- "num-traits",
- "wasm-bindgen",
- "windows-link",
-]
-
[[package]]
name = "cipher"
version = "0.4.4"
@@ -907,12 +859,6 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
-[[package]]
-name = "convert_case"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
-
[[package]]
name = "core-foundation"
version = "0.9.4"
@@ -1090,19 +1036,6 @@ dependencies = [
"zeroize",
]
-[[package]]
-name = "derive_more"
-version = "0.99.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6edb4b64a43d977b8e99788fe3a04d483834fba1215a7e02caa415b626497f7f"
-dependencies = [
- "convert_case",
- "proc-macro2",
- "quote",
- "rustc_version",
- "syn 2.0.119",
-]
-
[[package]]
name = "digest"
version = "0.10.7"
@@ -1249,7 +1182,7 @@ dependencies = [
"bitflags 2.13.2",
"emath",
"epaint",
- "itertools 0.15.0",
+ "itertools",
"log",
"nohash-hasher",
"profiling",
@@ -1667,10 +1600,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
- "js-sys",
"libc",
"wasi",
- "wasm-bindgen",
]
[[package]]
@@ -1983,30 +1914,6 @@ dependencies = [
"typenum",
]
-[[package]]
-name = "iana-time-zone"
-version = "0.1.65"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
-dependencies = [
- "android_system_properties",
- "core-foundation-sys",
- "iana-time-zone-haiku",
- "js-sys",
- "log",
- "wasm-bindgen",
- "windows-core",
-]
-
-[[package]]
-name = "iana-time-zone-haiku"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
-dependencies = [
- "cc",
-]
-
[[package]]
name = "icu_collections"
version = "2.3.0"
@@ -2166,15 +2073,6 @@ dependencies = [
"generic-array",
]
-[[package]]
-name = "itertools"
-version = "0.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
-dependencies = [
- "either",
-]
-
[[package]]
name = "itertools"
version = "0.15.0"
@@ -2269,17 +2167,6 @@ dependencies = [
"wasm-bindgen",
]
-[[package]]
-name = "katexit"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ccfb0b7ce7938f84a5ecbdca5d0a991e46bc9d6d078934ad5e92c5270fe547db"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.119",
-]
-
[[package]]
name = "keyboard-types"
version = "0.8.3"
@@ -2430,15 +2317,6 @@ version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
-[[package]]
-name = "matext4cgmath"
-version = "0.1.0"
-dependencies = [
- "cgmath",
- "katexit",
- "num-complex",
-]
-
[[package]]
name = "memchr"
version = "2.8.3"
@@ -3314,30 +3192,6 @@ dependencies = [
"toml_edit",
]
-[[package]]
-name = "proc-macro-error"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
-dependencies = [
- "proc-macro-error-attr",
- "proc-macro2",
- "quote",
- "syn 1.0.109",
- "version_check",
-]
-
-[[package]]
-name = "proc-macro-error-attr"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
-dependencies = [
- "proc-macro2",
- "quote",
- "version_check",
-]
-
[[package]]
name = "proc-macro2"
version = "1.0.107"
@@ -3510,15 +3364,6 @@ dependencies = [
"crossbeam-utils",
]
-[[package]]
-name = "rclite"
-version = "0.2.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e09665c494a9de2bd230e1aedc0c2fb20481a51f28f7db84d0c9bcfe2fe537b2"
-dependencies = [
- "branches",
-]
-
[[package]]
name = "read-fonts"
version = "0.41.0"
@@ -4371,10 +4216,6 @@ dependencies = [
"solidcraft-step",
"spade",
"thiserror 2.0.21",
- "truck-modeling",
- "truck-shapeops",
- "truck-stepio",
- "truck-topology",
"web-time",
]
@@ -4414,7 +4255,7 @@ dependencies = [
[[package]]
name = "solidcraft-smlib"
-version = "0.18.1"
+version = "0.24.0"
dependencies = [
"cc",
"flate2",
@@ -4432,7 +4273,7 @@ dependencies = [
[[package]]
name = "solidcraft-step"
-version = "0.18.1"
+version = "0.24.0"
dependencies = [
"solidcraft-geom",
]
@@ -4530,16 +4371,6 @@ version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
-[[package]]
-name = "syn"
-version = "1.0.109"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
-dependencies = [
- "proc-macro2",
- "unicode-ident",
-]
-
[[package]]
name = "syn"
version = "2.0.119"
@@ -4777,144 +4608,6 @@ dependencies = [
"once_cell",
]
-[[package]]
-name = "truck-base"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c279de9e92e5dc20a188deb0bb9a4bd421a6a185e57e03e19025e84a36c5a05"
-dependencies = [
- "cgmath",
- "matext4cgmath",
- "rustc-hash 2.1.3",
- "serde",
-]
-
-[[package]]
-name = "truck-derivers"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "421ff1c5a303aed64e295d9b30e8424ee7a2fa251617a59ae4acfd078496009f"
-dependencies = [
- "proc-macro-error",
- "proc-macro2",
- "quote",
- "syn 2.0.119",
-]
-
-[[package]]
-name = "truck-geometry"
-version = "0.5.0"
-dependencies = [
- "serde",
- "thiserror 1.0.69",
- "truck-base",
- "truck-geotrait",
-]
-
-[[package]]
-name = "truck-geotrait"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97a31fe98d5a0589ad20576260e214af23dea21a8d125da81ad3bbcb666f411f"
-dependencies = [
- "getrandom 0.2.17",
- "rand 0.8.8",
- "thiserror 1.0.69",
- "truck-base",
- "truck-derivers",
-]
-
-[[package]]
-name = "truck-meshalgo"
-version = "0.4.0"
-dependencies = [
- "array-macro",
- "derive_more",
- "itertools 0.13.0",
- "rayon",
- "rustc-hash 2.1.3",
- "spade",
- "truck-base",
- "truck-geometry",
- "truck-modeling",
- "truck-polymesh",
- "truck-topology",
-]
-
-[[package]]
-name = "truck-modeling"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8082c2dfac8c2732a014d81807fb5d24dbac0d72ee4de2a705b7fbc05fa05b18"
-dependencies = [
- "derive_more",
- "rustc-hash 2.1.3",
- "serde",
- "thiserror 1.0.69",
- "truck-base",
- "truck-geometry",
- "truck-geotrait",
- "truck-polymesh",
- "truck-topology",
-]
-
-[[package]]
-name = "truck-polymesh"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8f22def310af4a89c37beb4839bbf702b302d2c112ea29553759f0e16622fbf"
-dependencies = [
- "array-macro",
- "bytemuck",
- "itertools 0.13.0",
- "rustc-hash 2.1.3",
- "serde",
- "thiserror 1.0.69",
- "truck-base",
- "truck-geotrait",
-]
-
-[[package]]
-name = "truck-shapeops"
-version = "0.4.0"
-dependencies = [
- "derive_more",
- "itertools 0.13.0",
- "rustc-hash 2.1.3",
- "truck-base",
- "truck-geometry",
- "truck-geotrait",
- "truck-meshalgo",
- "truck-topology",
-]
-
-[[package]]
-name = "truck-stepio"
-version = "0.3.0"
-dependencies = [
- "chrono",
- "truck-geometry",
- "truck-modeling",
- "truck-polymesh",
- "truck-topology",
-]
-
-[[package]]
-name = "truck-topology"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf62a1610405c5e39ab5eb6948f326fc1641689734a6b8207a80792133fe0e78"
-dependencies = [
- "parking_lot",
- "rayon",
- "rclite",
- "rustc-hash 2.1.3",
- "serde",
- "thiserror 1.0.69",
- "truck-base",
- "truck-geotrait",
-]
-
[[package]]
name = "ttf-parser"
version = "0.25.1"
diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs
index 3a3e422a30..e286793f32 100644
--- a/crates/engine/src/cmd/features.rs
+++ b/crates/engine/src/cmd/features.rs
@@ -1451,7 +1451,9 @@ fn edge_points(s: &Session, p: &Value, cmd: &str) -> Result<Vec<Vec3>> {
// The display mesh flags seams (a smooth surface meeting itself, as down the side
// of a cylinder), which nobody means by a pick where they end.
match b.body.mesh(&solidcraft_kernel::MeshTolerance::chord(tol)) {
- Ok(m) => Some((size, m.edges, m.seams)),
+ // An edge where the faces meet tangentially (the spans of a spline wall
+ // meeting) can't be blended either: nobody means it by a pick.
+ Ok(m) => Some((size, m.edges, m.seams.iter().zip(&m.smooth_edges).map(|(s, t)| *s || *t).chain(m.seams.iter().skip(m.smooth_edges.len()).copied()).collect())),
Err(_) => b.body.edges(tol).ok().map(|edges| (size, edges.into_iter().map(|e| e.points).collect(), Vec::new())),
}
})
@@ -1459,7 +1461,8 @@ fn edge_points(s: &Session, p: &Value, cmd: &str) -> Result<Vec<Vec3>> {
});
// A point where several edges meet (a corner) is ambiguous: the kernel would round one of
// them, picked silently (#5173). Edges that carry straight on through the point (the two
- // halves of a circle) are one edge to whoever picked it, and seams don't count. Directions
+ // halves of a circle) are one edge to whoever picked it, and seams and tangent joins don't
+ // count. Directions
// come from the polylines' end chords, which lean off a curve's tangent: within about 45°
// of opposite counts as carrying on (edges at a real corner are far from opposite).
let mut nearest = f64::INFINITY;
diff --git a/crates/kernel/src/iges_in.rs b/crates/kernel/src/iges_in.rs
index 7a6765b5b8..f9adb7aead 100644
--- a/crates/kernel/src/iges_in.rs
+++ b/crates/kernel/src/iges_in.rs
@@ -288,7 +288,8 @@ fn parse(text: &str) -> R<Iges> {
/// A model curve segment ready for an edge: STEP curve id, its end points, points a quarter and
/// three quarters of the way along and one at the middle (for matching shared edges), and
-/// whether the curve runs from `b` to `a`.
+/// whether the curve runs from `b` to `a`; and its geometry, for a curve that has to be made to
+/// end where its piece meets the next ([`Tr::closed`]).
#[derive(Clone, Copy, Debug)]
struct Seg {
curve: u64,
@@ -298,11 +299,28 @@ struct Seg {
q3: V3,
mid: V3,
rev: bool,
+ shape: Shape,
+}
+
+/// A segment's curve as it can be rebuilt: a line, or the B-spline `Tr::splines[i]`; another
+/// curve keeps its ends.
+#[derive(Clone, Copy, Debug, PartialEq)]
+enum Shape {
+ Line,
+ Spline(usize),
+ Other,
}
impl Seg {
fn along(curve: u64, f: impl Fn(f64) -> V3) -> Seg {
- Seg { curve, a: f(0.0), b: f(1.0), q: f(0.25), q3: f(0.75), mid: f(0.5), rev: false }
+ Seg { curve, a: f(0.0), b: f(1.0), q: f(0.25), q3: f(0.75), mid: f(0.5), rev: false, shape: Shape::Other }
+ }
+ fn with(self, shape: Shape) -> Seg {
+ Seg { shape, ..self }
+ }
+ /// Its length, along the points it keeps.
+ fn length(&self) -> f64 {
+ norm(sub(self.q, self.a)) + norm(sub(self.mid, self.q)) + norm(sub(self.q3, self.mid)) + norm(sub(self.b, self.q3))
}
fn reversed(self) -> Seg {
Seg { a: self.b, b: self.a, q: self.q3, q3: self.q, rev: !self.rev, ..self }
@@ -343,6 +361,7 @@ fn perp(z: V3) -> V3 {
}
/// A rational B-spline curve evaluated by de Boor's algorithm.
+#[derive(Clone)]
struct Nurbs {
deg: usize,
knots: Vec<f64>,
@@ -431,8 +450,8 @@ struct Tr<'a> {
curve_work: usize,
/// Composite curves (102) on the path being expanded.
composites: Vec<i64>,
- /// Farthest a trim loop's end was moved to close a gap (mm; see `close_gaps`).
- snapped: f64,
+ /// The B-splines of segments ([`Shape::Spline`]).
+ splines: Vec<Nurbs>,
}
fn xf_key(x: &Xf) -> [u64; 12] {
@@ -539,7 +558,7 @@ impl<'a> Tr<'a> {
let dd = self.o.dir(d);
let v = self.o.add(format!("VECTOR('',#{dd},{})", r(norm(sub(b, a)))));
let c = self.o.add(format!("LINE('',#{pa},#{v})"));
- Ok(vec![Seg::along(c, |t| add(a, mul(sub(b, a), t)))])
+ Ok(vec![Seg::along(c, |t| add(a, mul(sub(b, a), t))).with(Shape::Line)])
}
100 => {
let Arc { c, rad, a0, a1 } = self.arc(seq)?;
@@ -577,7 +596,9 @@ impl<'a> Tr<'a> {
nb.eval(t0 + (t1 - t0) * k as f64 / 4.0).ok_or_else(|| format!("entity {seq}: B-spline cannot be evaluated"))?;
}
let c = self.write_nurbs_curve(&nb);
- Ok(vec![Seg::along(c, |t| nb.eval(t0 + (t1 - t0) * t).unwrap_or([0.0; 3]))])
+ let seg = Seg::along(c, |t| nb.eval(t0 + (t1 - t0) * t).unwrap_or([0.0; 3]));
+ self.splines.push(nb);
+ Ok(vec![seg.with(Shape::Spline(self.splines.len() - 1))])
}
104 => {
// Ellipse (form 1) in canonical position: A x² + C y² + F = 0.
@@ -970,6 +991,59 @@ impl<'a> Tr<'a> {
Nurbs { deg: m2, knots: t_knots, pts: column }.eval(v).ok_or_else(|| "surface cannot be evaluated".into())
}
+ /// Segment `s` made to run from `pa` to `pb`, the vertices its piece meets the pieces before
+ /// and after it at. A line is the line between them; a clamped B-spline has its end control
+ /// points moved onto them (it ends at them exactly, its shape inside changed by no more than
+ /// the gap). Any other curve keeps its ends, and the gap is reported.
+ fn closed(&mut self, s: &Seg, pa: V3, pb: V3) -> Seg {
+ let gap = norm(sub(s.a, pa)).max(norm(sub(s.b, pb)));
+ if gap <= self.tol {
+ return *s;
+ }
+ match s.shape {
+ Shape::Line if norm(sub(pb, pa)) > self.tol => {
+ let (p, d) = (self.o.point(pa), unit(sub(pb, pa)).unwrap_or([1.0, 0.0, 0.0]));
+ let dd = self.o.dir(d);
+ let v = self.o.add(format!("VECTOR('',#{dd},{})", r(norm(sub(pb, pa)))));
+ let c = self.o.add(format!("LINE('',#{p},#{v})"));
+ return Seg::along(c, |t| add(pa, mul(sub(pb, pa), t))).with(Shape::Line);
+ }
+ Shape::Spline(i) => {
+ if let Some(mut nb) = self.splines.get(i).cloned() {
+ let (n, p) = (nb.pts.len(), nb.deg);
+ let clamped = n > p
+ && nb.knots.len() == n + p + 1
+ && nb.knots[..=p].iter().all(|k| *k == nb.knots[0])
+ && nb.knots[n..].iter().all(|k| *k == nb.knots[n + p]);
+ if clamped {
+ // The curve runs from `a` to `b`, or from `b` to `a` when reversed.
+ let (start, end) = if s.rev { (pb, pa) } else { (pa, pb) };
+ for (k, q) in [(0, start), (n - 1, end)] {
+ let w = nb.pts[k][3];
+ nb.pts[k] = [q[0] * w, q[1] * w, q[2] * w, w];
+ }
+ let (t0, t1) = nb.range();
+ let c = self.write_nurbs_curve(&nb);
+ let seg = Seg::along(c, |t| nb.eval(t0 + (t1 - t0) * t).unwrap_or([0.0; 3]));
+ self.splines.push(nb);
+ let seg = seg.with(Shape::Spline(self.splines.len() - 1));
+ return if s.rev { seg.reversed() } else { seg };
+ }
+ }
+ }
+ _ => {}
+ }
+ let near = if norm(sub(s.a, pa)) >= norm(sub(s.b, pb)) { pa } else { pb };
+ self.warn(format!(
+ "trim curve pieces miss each other by {} mm at ({}, {}, {}): the gap is left open within the vertex's tolerance",
+ r(gap),
+ r(near[0]),
+ r(near[1]),
+ r(near[2])
+ ));
+ *s
+ }
+
/// The natural boundary of a B-spline surface (its four edge curves), for trimmed surfaces
/// with no outer curve.
fn natural_boundary(&mut self, seq: i64, xf: &Xf) -> R<Vec<Seg>> {
@@ -1004,7 +1078,8 @@ impl<'a> Tr<'a> {
continue; // a pole
}
let c = self.write_nurbs_curve(&nb);
- let seg = Seg::along(c, |t| ev(t).unwrap_or([0.0; 3]));
+ let seg = Seg::along(c, |t| ev(t).unwrap_or([0.0; 3])).with(Shape::Spline(self.splines.len()));
+ self.splines.push(nb.clone());
out.push(if rev { seg.reversed() } else { seg });
}
Ok(out)
@@ -1075,6 +1150,10 @@ impl Sewer {
/// the segment runs along it.
fn edge(&mut self, s: &Seg) -> (usize, bool) {
let (a, b) = (self.vertex(s.a), self.vertex(s.b));
+ self.edge_between(s, a, b)
+ }
+ /// [`Sewer::edge`] for a segment from vertex `a` to vertex `b`.
+ fn edge_between(&mut self, s: &Seg, a: usize, b: usize) -> (usize, bool) {
let key = (a.min(b), a.max(b));
let close = |x: V3, y: V3| norm(sub(x, y)) <= self.tol * 10.0 + 1e-9;
if let Some(list) = self.by_ends.get(&key) {
@@ -1253,13 +1332,12 @@ fn translate(text: &str) -> std::result::Result<(String, Vec<String>), String> {
surf_cache: HashMap::new(),
curve_work: 0,
composites: Vec::new(),
- snapped: 0.0,
+ splines: Vec::new(),
};
// Header: units and context.
let mm = t.o.add("(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.))");
let rad = t.o.add("(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.))");
let sr = t.o.add("(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT())");
- let unc_line = t.o.lines.len();
let unc = t.o.add(format!("UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE({}),#{mm},'distance_accuracy_value','')", r(tol)));
let ctx = t.o.add(format!(
"(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#{unc}))GLOBAL_UNIT_ASSIGNED_CONTEXT((#{mm},#{rad},#{sr}))REPRESENTATION_CONTEXT('',''))"
@@ -1305,13 +1383,6 @@ fn translate(text: &str) -> std::result::Result<(String, Vec<String>), String> {
}
}
assembly.write(&mut t, &seqs, &solids, &mut styles, ctx)?;
- if t.snapped > 0.0 {
- // The STEP reader takes vertices up to ten times the stated accuracy off their curves:
- // state enough to cover the ends `close_gaps` moved, and no more.
- if let Some(l) = t.o.lines.get_mut(unc_line) {
- *l = format!("UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE({}),#{mm},'distance_accuracy_value','')", r(tol.max(t.snapped * 0.2)));
- }
- }
for (item, c) in styles {
let rgb = t.o.add(format!("COLOUR_RGB('',{},{},{})", r(c[0] as f64), r(c[1] as f64), r(c[2] as f64)));
let fasc = t.o.add(format!("FILL_AREA_STYLE_COLOUR('',#{rgb})"));
@@ -1366,11 +1437,7 @@ fn sew_surfaces(
Err(e) => t.warn(format!("surface {seq}: not read: {e}")),
}
}
- close_gaps(t, &mut drafts, sw.tol);
- for d in drafts {
- let loops = d.loops.iter().map(|l| l.iter().map(|s| sw.edge(s)).collect()).collect();
- faces.push(FaceB { surface: d.surface, sense: true, loops, color: d.color });
- }
+ faces.extend(sew(t, sw, drafts));
if faces.is_empty() {
return Ok(Vec::new());
}
@@ -1441,75 +1508,97 @@ const MAX_TRIM_GAP: f64 = 0.1;
/// ...and a gap must also be at most this share of the shorter piece on either side.
const MAX_TRIM_GAP_SHARE: f64 = 0.05;
-/// Close the small gaps between consecutive pieces of the faces' trim loops. Some exporters
-/// write each piece's model-space curve separately, and consecutive pieces can then miss by a
-/// few micrometres to a tenth of a millimetre, well past the file's stated resolution: the loop
-/// does not close, its face is lost and the shell stays open. The two ends of each such gap, and
-/// every other piece end at either of them (the neighbouring faces at that corner), move to
-/// their mean, so all the faces there sew to one vertex. A gap wider than `MAX_TRIM_GAP`, or not
-/// small next to its pieces, is left open; the sewing tolerance stays the file's.
-fn close_gaps(t: &mut Tr, faces: &mut [Draft], tol: f64) {
- let length = |s: &Seg| norm(sub(s.q, s.a)) + norm(sub(s.mid, s.q)) + norm(sub(s.q3, s.mid)) + norm(sub(s.b, s.q3));
- // The gaps' ends as vertices, joined into groups (union-find).
- let mut ends = Sewer { tol, verts: Vec::new(), grid: HashMap::new(), edges: Vec::new(), by_ends: HashMap::new() };
- let mut parent: Vec<usize> = Vec::new();
- let root = |parent: &[usize], mut i: usize| {
- while let Some(&p) = parent.get(i).filter(|p| **p != i) {
- i = p;
- }
- i
- };
- for l in faces.iter().flat_map(|f| f.loops.iter()) {
- for (i, prev) in l.iter().enumerate() {
- let Some(next) = l.get((i + 1) % l.len()) else { continue };
- let gap = norm(sub(next.a, prev.b));
- if gap <= tol || gap > MAX_TRIM_GAP || gap > MAX_TRIM_GAP_SHARE * length(prev).min(length(next)) {
- continue;
- }
- let (a, b) = (ends.vertex(prev.b), ends.vertex(next.a));
- while parent.len() < ends.verts.len() {
- parent.push(parent.len());
+/// Faces read from trimmed surfaces, sewn by their shared edges. A boundary loop is one closed
+/// curve: each piece ends where the next one starts (IGES 5.3, 4.24 composite curve, and
+/// 4.34/4.35 a trimmed surface's boundaries are closed curves). Some exporters write each
+/// piece's model-space curve separately, and consecutive pieces can then miss by a few
+/// micrometres to a tenth of a millimetre, well past the file's stated resolution. Each meeting
+/// point of two pieces is then still one vertex, unless the gap is wider than `MAX_TRIM_GAP` or
+/// not small next to its pieces (`MAX_TRIM_GAP_SHARE`): past that the ends may be different
+/// corners of the model, and the gap stays open. The vertex goes where most of the piece ends
+/// meeting there agree (the neighbouring faces at that corner), and a piece that misses it is
+/// made to end there ([`Tr::closed`]): the edges then meet at their vertices exactly, as the
+/// file means them to, and the sewing tolerance stays the file's.
+fn sew(t: &mut Tr, sw: &mut Sewer, faces: Vec<Draft>) -> Vec<FaceB> {
+ // Every piece's end vertices, then the vertices each meeting point joins made one.
+ let ends: Vec<Vec<Vec<[usize; 2]>>> =
+ faces.iter().map(|f| f.loops.iter().map(|l| l.iter().map(|s| [sw.vertex(s.a), sw.vertex(s.b)]).collect()).collect()).collect();
+ let mut same: Vec<usize> = (0..sw.verts.len()).collect();
+ fn root(same: &mut [usize], mut i: usize) -> usize {
+ while let Some(&p) = same.get(i) {
+ if p == i {
+ break;
}
- let (ra, rb) = (root(&parent, a), root(&parent, b));
- if let Some(x) = parent.get_mut(ra) {
- *x = rb;
+ let up = same.get(p).copied().unwrap_or(p);
+ if let Some(slot) = same.get_mut(i) {
+ *slot = up;
}
+ i = p;
}
+ i
}
- if ends.verts.is_empty() {
- return;
- }
- // Each group's mean; a group that spreads wider than a gap may be is left alone.
- let mut sums: HashMap<usize, (V3, usize)> = HashMap::new();
- for (i, p) in ends.verts.iter().enumerate() {
- let e = sums.entry(root(&parent, i)).or_insert(([0.0; 3], 0));
- e.0 = add(e.0, *p);
- e.1 += 1;
- }
- let mean: HashMap<usize, V3> = sums.into_iter().map(|(r, (s, n))| (r, mul(s, 1.0 / n as f64))).collect();
- let mut to: Vec<Option<V3>> = ends.verts.iter().enumerate().map(|(i, _)| mean.get(&root(&parent, i)).copied()).collect();
- for (i, p) in ends.verts.iter().enumerate() {
- if to.get(i).copied().flatten().is_some_and(|m| norm(sub(m, *p)) > MAX_TRIM_GAP / 2.0) {
- let r = root(&parent, i);
- for (k, x) in to.iter_mut().enumerate() {
- if root(&parent, k) == r {
- *x = None;
+ for (f, fe) in faces.iter().zip(&ends) {
+ for (l, le) in f.loops.iter().zip(fe) {
+ for (k, (prev, e)) in l.iter().zip(le).enumerate() {
+ let (Some(next), Some(next_ends)) = (l.get((k + 1) % l.len()), le.get((k + 1) % le.len())) else { continue };
+ let gap = norm(sub(next.a, prev.b));
+ if gap > MAX_TRIM_GAP || gap > MAX_TRIM_GAP_SHARE * prev.length().min(next.length()) {
+ continue;
+ }
+ let (a, b) = (root(&mut same, e[1]), root(&mut same, next_ends[0]));
+ if let Some(slot) = same.get_mut(a.max(b)) {
+ *slot = a.min(b);
}
}
}
}
- let mut moved = 0.0f64;
- let mut snap = |p: &mut V3| {
- if let Some(m) = ends.find(*p).and_then(|i| to.get(i).copied().flatten()) {
- moved = moved.max(norm(sub(m, *p)));
- *p = m;
+ // The piece ends at each joined vertex, and the vertex where most of them are.
+ let mut at: HashMap<usize, Vec<V3>> = HashMap::new();
+ for (f, fe) in faces.iter().zip(&ends) {
+ for (l, le) in f.loops.iter().zip(fe) {
+ for (s, [a, b]) in l.iter().zip(le) {
+ at.entry(root(&mut same, *a)).or_default().push(s.a);
+ at.entry(root(&mut same, *b)).or_default().push(s.b);
+ }
}
- };
- for s in faces.iter_mut().flat_map(|f| f.loops.iter_mut()).flat_map(|l| l.iter_mut()) {
- snap(&mut s.a);
- snap(&mut s.b);
}
- t.snapped = t.snapped.max(moved);
+ for (v, pts) in at {
+ let agree = |p: V3| pts.iter().filter(|q| norm(sub(**q, p)) <= sw.tol).count();
+ let Some(here) = sw.verts.get(v).copied() else { continue };
+ let mut best = (agree(here), here);
+ for p in &pts {
+ let n = agree(*p);
+ if n > best.0 {
+ best = (n, *p);
+ }
+ }
+ if let Some(slot) = sw.verts.get_mut(v) {
+ *slot = best.1;
+ }
+ }
+ faces
+ .into_iter()
+ .zip(ends)
+ .map(|(f, ends)| {
+ let loops = f
+ .loops
+ .iter()
+ .zip(ends)
+ .map(|(l, e)| {
+ l.iter()
+ .zip(e)
+ .map(|(s, [a, b])| {
+ let (a, b) = (root(&mut same, a), root(&mut same, b));
+ let (pa, pb) = (sw.verts.get(a).copied().unwrap_or(s.a), sw.verts.get(b).copied().unwrap_or(s.b));
+ let s = t.closed(s, pa, pb);
+ sw.edge_between(&s, a, b)
+ })
+ .collect()
+ })
+ .collect();
+ FaceB { surface: f.surface, sense: true, loops, color: f.color }
+ })
+ .collect()
}
/// A trimmed (144) or bounded (143) surface, or a bare B-spline surface, as a face.
@@ -1588,10 +1677,16 @@ fn cos_curve(t: &mut Tr, seq: i64, xf: &Xf, surface: i64) -> R<Vec<Seg>> {
}
/// Pieces of a composite curve turned so that each starts where the one before ends, the first
-/// at the end nearer `start` (when known). A closed piece (its ends within `tol`, the sewing
-/// tolerance that decides they are one vertex) keeps its direction.
+/// at the end nearer `start` (when known), else at its end away from the second piece. A closed
+/// piece (its ends within `tol`, the sewing tolerance that decides they are one vertex) keeps
+/// its direction.
fn head_to_tail(segs: Vec<Seg>, start: Option<V3>, tol: f64) -> Vec<Seg> {
- let mut prev = start;
+ let from_second = || {
+ let (f, n) = (segs.first()?, segs.get(1)?);
+ let to_second = |p: V3| norm(sub(p, n.a)).min(norm(sub(p, n.b)));
+ Some(if to_second(f.a) < to_second(f.b) { f.b } else { f.a })
+ };
+ let mut prev = start.or_else(from_second);
segs.into_iter()
.map(|s| {
let s = match prev {
diff --git a/crates/kernel/src/step_in/mod.rs b/crates/kernel/src/step_in/mod.rs
index d48b240e06..3b93b60b4d 100644
--- a/crates/kernel/src/step_in/mod.rs
+++ b/crates/kernel/src/step_in/mod.rs
@@ -141,21 +141,35 @@ fn mat_mul(a: &M4, b: &M4) -> M4 {
out
}
-/// The inverse of a rigid placement (an orthonormal rotation and a translation): the rotation
-/// transposed, and the translation taken back through it.
-fn rigid_inverse(m: &M4) -> M4 {
+/// The determinant of a placement's linear part (its first three columns).
+fn linear_det(m: &M4) -> f64 {
+ let [a, b, c] = [m[0], m[1], m[2]];
+ a[0] * (b[1] * c[2] - b[2] * c[1]) - b[0] * (a[1] * c[2] - a[2] * c[1]) + c[0] * (a[1] * b[2] - a[2] * b[1])
+}
+
+/// The inverse of a placement: a rotation, scaled (a transformation operator may scale), and a
+/// translation. Its linear part is inverted by its adjugate, and the translation taken back
+/// through that. Placements are checked non-singular where they are read
+/// ([`Reader::placement_matrix`]; a frame's axes are orthonormal).
+fn placement_inverse(m: &M4) -> M4 {
+ let det = linear_det(m);
+ let [a, b, c] = [m[0], m[1], m[2]];
+ // The rows of the inverse are the cross products of the columns, over the determinant.
+ let cross = |u: [f64; 4], v: [f64; 4]| [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]];
+ let rows = [cross(b, c), cross(c, a), cross(a, b)];
let mut out = IDENTITY;
- for (i, col) in out.iter_mut().take(3).enumerate() {
- for (j, cell) in col.iter_mut().take(3).enumerate() {
- *cell = m[j][i];
+ for (i, row) in rows.iter().enumerate() {
+ for (j, col) in out.iter_mut().take(3).enumerate() {
+ col[i] = row[j] / det;
}
}
for i in 0..3 {
- out[3][i] = -(0..3).map(|k| m[i][k] * m[3][k]).sum::<f64>();
+ out[3][i] = -(0..3).map(|k| out[k][i] * m[3][k]).sum::<f64>();
}
out
}
+#[cfg(test)]
fn translation(t: [f64; 3]) -> M4 {
let mut m = IDENTITY;
m[3] = [t[0], t[1], t[2], 1.0];
@@ -487,13 +501,41 @@ impl Reader {
}
/// The placement an item states: an AXIS2_PLACEMENT's frame, or a
- /// CARTESIAN_TRANSFORMATION_OPERATOR_3D's origin.
+ /// CARTESIAN_TRANSFORMATION_OPERATOR_3D, uniform or not: its axes, scales and origin (an
+ /// omitted axis is the global one, an omitted scale 1, an omitted second or third scale the
+ /// first).
fn placement_matrix(&mut self, item: u64, u: Units) -> R<M4> {
let reader = solidcraft_step::read::Reader::new(&self.ex, u.units);
let e = self.ex.get(item).ok_or_else(|| format!("missing entity #{item}"))?;
- if e.name() == "CARTESIAN_TRANSFORMATION_OPERATOR_3D" {
- let o = reader.point(e.params().get(4).and_then(Param::as_ref_id).ok_or("transformation without origin")?)?;
- return Ok(translation(o));
+ if matches!(e.name(), "CARTESIAN_TRANSFORMATION_OPERATOR_3D" | "CARTESIAN_TRANSFORMATION_OPERATOR_3D_NON_UNIFORM") {
+ let p = e.params();
+ let o = reader.point(p.get(4).and_then(Param::as_ref_id).ok_or("transformation without origin")?)?;
+ let direction = |i: usize, global: [f64; 3]| -> R<[f64; 3]> {
+ match p.get(i) {
+ None | Some(Param::Null) => Ok(global),
+ Some(Param::Ref(id)) => reader.direction(*id),
+ _ => Err("invalid transformation direction".into()),
+ }
+ };
+ let scale = |i: usize, default: f64| -> R<f64> {
+ match p.get(i) {
+ None | Some(Param::Null) => Ok(default),
+ Some(v) => v.as_f64().filter(|x| x.is_finite() && *x != 0.0).ok_or_else(|| "invalid transformation scale".into()),
+ }
+ };
+ let sx = scale(5, 1.0)?;
+ let (sy, sz) = (scale(7, sx)?, scale(8, sx)?);
+ let (x, y, z) = (direction(2, [1.0, 0.0, 0.0])?, direction(3, [0.0, 1.0, 0.0])?, direction(6, [0.0, 0.0, 1.0])?);
+ let col = |d: [f64; 3], s: f64| [d[0] * s, d[1] * s, d[2] * s, 0.0];
+ let m = [col(x, sx), col(y, sy), col(z, sz), [o[0], o[1], o[2], 1.0]];
+ if !m.iter().flatten().all(|x| x.is_finite()) {
+ return Err("invalid transformation scale".into());
+ }
+ let det = linear_det(&m);
+ if !det.is_finite() || det == 0.0 {
+ return Err("singular transformation".into());
+ }
+ return Ok(m);
}
Ok(frame_matrix(&reader.frame(item)?))
}
@@ -596,7 +638,7 @@ impl Reader {
let mu = self.units_of(mapped);
match (self.placement_matrix(target, u), self.placement_matrix(origin, mu)) {
(Ok(t), Ok(o)) => {
- let mm = mat_mul(m, &mat_mul(&t, &rigid_inverse(&o)));
+ let mm = mat_mul(m, &mat_mul(&t, &placement_inverse(&o)));
for r in self.rep_closure(&[mapped]) {
self.rep_bodies(r, &mm, path, product, instance, out, depth + 1);
}
@@ -713,7 +755,7 @@ impl Reader {
// Every instance of a part placed more than once shows its first instance's
// mesh, placed (the first one too: meshing its own would mesh the part twice).
let body = match self.shown.get(&item) {
- Some((shared, first)) => body.with_display_of(shared.clone(), mat_mul(&m, &rigid_inverse(first))),
+ Some((shared, first)) => body.with_display_of(shared.clone(), mat_mul(&m, &placement_inverse(first))),
None if self.uses.get(&item).is_some_and(|n| *n > 1) => {
let shared = Arc::new(crate::body::SharedDisplay::new(body.clone()));
self.shown.insert(item, (shared.clone(), m));
@@ -803,7 +845,7 @@ impl Reader {
let m2 = self.placement_matrix(i2, u2)?;
// rep_1 is normally the component: map its item onto the assembly's item.
let child_is_1 = child_reps.contains(&r1) || !child_reps.contains(&r2);
- Ok(if child_is_1 { mat_mul(&m2, &rigid_inverse(&m1)) } else { mat_mul(&m1, &rigid_inverse(&m2)) })
+ Ok(if child_is_1 { mat_mul(&m2, &placement_inverse(&m1)) } else { mat_mul(&m1, &placement_inverse(&m2)) })
} else {
self.placement_matrix(op, u2)
}
diff --git a/tests/kernel-cases/booleans/3383-combine-tool-into-rotated-occurrence/recipe.json b/tests/kernel-cases/booleans/3383-combine-tool-into-rotated-occurrence/recipe.json
index 20b7d7745e..b875c6d94b 100644
--- a/tests/kernel-cases/booleans/3383-combine-tool-into-rotated-occurrence/recipe.json
+++ b/tests/kernel-cases/booleans/3383-combine-tool-into-rotated-occurrence/recipe.json
@@ -26,6 +26,13 @@
"component": "root"
}
},
+ {
+ "command": "occurrence.ground",
+ "params": {
+ "occurrence": "Part:1",
+ "grounded": false
+ }
+ },
{
"command": "occurrence.move",
"params": {
diff --git a/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/expected.json b/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/expected.json
index 7776c0508f..f84cf595a2 100644
--- a/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/expected.json
+++ b/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/expected.json
@@ -2,9 +2,9 @@
"sources": [
"tangency-labs/solidcraft#5024"
],
- "what": "a drilled O8 hole, 10 deep with a 118 deg point, placed 1 mm off a 40x30x20 box's top face, across its edge: 17-54 s in truck",
+ "what": "a drilled O8 hole, 10 deep with a 118 deg point, centred on the top edge of a 40x30x20 box (x = 0): half of it in the box, across the edge: 17-54 s in truck",
"source": "analytic",
- "method": "the hole's axis is at x = -1, y = 15, so only its part at x >= 0 removes material: the circular segment of the O8 section beyond x = 0 (r^2 acos(d/r) - d sqrt(r^2-d^2), d = 1) over the 10 mm to the shoulder, plus the same segment of the point cone's section (radius 4 - s tan59 at s below the shoulder, down to radius 1), integrated (python quadrature). V = 24000 - 172.16874 - 11.10370",
+ "method": "the hole's axis lies in the box's side plane x = 0, so the box keeps half of the drilled cut: V = 40*30*20 - (pi r^2 d + pi r^2 h/3)/2, r = 4, d = 10, the point's height h = r / tan 59 deg (main refuses a position off the face, so the centre is on the edge, not 1 mm past it)",
"body_count": 1,
- "volume_mm3": 23816.7276
+ "volume_mm3": 23728.5376
}
diff --git a/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/recipe.json b/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/recipe.json
index 9718779505..58bffc023e 100644
--- a/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/recipe.json
+++ b/tests/kernel-cases/booleans/5024-drilled-hole-across-box-edge/recipe.json
@@ -12,7 +12,7 @@
"command": "solid.hole",
"params": {
"position": [
- -1,
+ 0,
15,
20
],