Merge develop b0d1ba345 (SMLib 26cc451) through ws/develop-b0d1ba
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MNXLXkZLQ6T7TSi4wswcmk
This commit is contained in:
commit
ed16c4bfc1
163 files changed
+1663
-4836
No files matched your search
@@ -110,8 +110,6 @@ Editable drawing code, native projects and shipped exports are collected under `
|
||||
| tests/kernel-cases/import/3208-extruded-ellipse-face-over-parameter-seam/input.step | SolidCraft contributors | synthetic STEP file written by hand from ISO 10303-21 for the kernel regression case of tangency-labs/solidcraft#3208 | MIT OR Apache-2.0 |
|
||||
| tests/kernel-cases/import/3352-vertex-off-its-edge-curve/input.step | SolidCraft contributors | synthetic STEP file written by hand from ISO 10303-21 for the kernel regression case of tangency-labs/solidcraft#3352 | MIT OR Apache-2.0 |
|
||||
| tests/kernel-cases/import/3730-void-oriented-shell-false/input.step | SolidCraft contributors | synthetic STEP file written by hand from ISO 10303-21 for the kernel regression case of tangency-labs/solidcraft#3730 | MIT OR Apache-2.0 |
|
||||
| tests/kernel-cases/import/3871-cone-base-circle-with-vertex-loop/input.step | step-conformance contributors | copy of tests/step-conformance/cone_point_vertex.step (generated from formulas by https://github.com/dan335/step-conformance, corpus/generated, 96f30bb); kernel regression case for tangency-labs/solidcraft#3871 | CC0-1.0 |
|
||||
| tests/kernel-cases/import/3871-cone-bounded-only-by-its-base-circle/input.step | step-conformance contributors | copy of tests/step-conformance/cone_point.step (generated from formulas by https://github.com/dan335/step-conformance, corpus/generated, 96f30bb); kernel regression case for tangency-labs/solidcraft#3871 | CC0-1.0 |
|
||||
| tests/kernel-cases/import/3880-cylinder-seam-edge/input.step | step-conformance contributors | copy of tests/step-conformance/cylinder_seam.step (generated from formulas by https://github.com/dan335/step-conformance, corpus/generated, 96f30bb); kernel regression case for tangency-labs/solidcraft#3880 | CC0-1.0 |
|
||||
| tests/kernel-cases/import/3880-nurbs-hemisphere-dome/input.step | step-conformance contributors | copy of tests/step-conformance/dome_nurbs.step (generated from formulas by https://github.com/dan335/step-conformance, corpus/generated, 96f30bb); kernel regression case for tangency-labs/solidcraft#3880 | CC0-1.0 |
|
||||
| tests/kernel-cases/import/3963-closed-spline-edge-vertex-past-start/input.step | SolidCraft contributors | synthetic STEP file written by hand from ISO 10303-21 for the kernel regression case of tangency-labs/solidcraft#3963 | MIT OR Apache-2.0 |
|
||||
|
||||
@@ -871,12 +871,18 @@ fn check_case(dir: &str, dumps: Option<&std::path::Path>, validation: solidcraft
|
||||
count(&mut c, "faces", got.faces);
|
||||
count(&mut c, "edges", edges);
|
||||
count(&mut c, "vertices", vertices);
|
||||
if has("volume_mm3") {
|
||||
c.rel("volume_mm3", got.volume, want["volume_mm3"].as_f64(), rel);
|
||||
}
|
||||
if has("area_mm2") {
|
||||
c.rel("area_mm2", got.area, want["area_mm2"].as_f64(), rel);
|
||||
}
|
||||
// A measure is a value within `rel`, or an inclusive range `[min, max]` where analysis only
|
||||
// bounds it (a cut removes at most its tool's volume).
|
||||
let measure = |c: &mut Checks, k: &str, g: f64| {
|
||||
if has(k) {
|
||||
match want[k].as_array() {
|
||||
Some(r) => c.push(k, json!(g), want[k].clone(), within(r, g)),
|
||||
None => c.rel(k, g, want[k].as_f64(), rel),
|
||||
}
|
||||
}
|
||||
};
|
||||
measure(&mut c, "volume_mm3", got.volume);
|
||||
measure(&mut c, "area_mm2", got.area);
|
||||
if has("center_of_mass") {
|
||||
c.vec("center_of_mass", got.com, v3(&want["center_of_mass"]), abs);
|
||||
}
|
||||
@@ -962,6 +968,14 @@ pub fn run(args: &[String]) -> Result<(), String> {
|
||||
if bad > 0 { Err(format!("{bad} kernel case(s) failed")) } else { Ok(()) }
|
||||
}
|
||||
|
||||
/// `g` lies in the inclusive range `[min, max]`; a range without both ends holds nothing.
|
||||
fn within(range: &[Value], g: f64) -> bool {
|
||||
match (range.first().and_then(Value::as_f64), range.get(1).and_then(Value::as_f64), range.len()) {
|
||||
(Some(lo), Some(hi), 2) => lo <= g && g <= hi,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::f64::consts::PI;
|
||||
@@ -1021,6 +1035,15 @@ mod tests {
|
||||
assert_eq!(surface_word(&face(1, 1, 1, 1)), "bspline");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_measure_range_holds_its_ends_and_nothing_outside() {
|
||||
let r = [json!(22500.0), json!(24000.0)];
|
||||
assert!(within(&r, 22500.0) && within(&r, 24000.0) && within(&r, 23000.0));
|
||||
assert!(!within(&r, 22499.9) && !within(&r, 24000.1));
|
||||
assert!(!within(&[json!(1.0)], 1.0), "one end is no range");
|
||||
assert!(!within(&[json!(1.0), json!(2.0), json!(3.0)], 1.5), "three ends are no range");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_parts_match_within_tolerance_and_whole_numbers_exactly() {
|
||||
let got = json!({"bends": [{"angle_deg": 90.00001, "direction": "up", "count": 3}], "extra": 1});
|
||||
|
||||
@@ -676,6 +676,7 @@ pub fn read(s: &str) -> Result<Document> {
|
||||
sketch.validate_wires().map_err(|e| DocError::Invalid(format!("damaged design: {e}")))?;
|
||||
sketch.validate_patterns().map_err(|e| DocError::Invalid(format!("damaged design: {e}")))?;
|
||||
sketch.validate_periodic_splines().map_err(|e| DocError::Invalid(format!("damaged design: {e}")))?;
|
||||
sketch.validate_spline_knots().map_err(|e| DocError::Invalid(format!("damaged design: {e}")))?;
|
||||
}
|
||||
if let crate::FeatureKind::BodyTransfer { from, to, .. } = &feature.kind
|
||||
&& [from, to].into_iter().any(|id| !component_ids.contains(id))
|
||||
@@ -1811,7 +1812,7 @@ mod tests {
|
||||
let first = pts[0];
|
||||
let neighbor = pts[1];
|
||||
let closing = pts[3];
|
||||
sketch.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic: true }, None).unwrap();
|
||||
sketch.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic: true, nurbs: None }, None).unwrap();
|
||||
let mut document = Document::new("periodic file validation");
|
||||
document.add_feature(crate::FeatureKind::Sketch { plane: crate::PlaneRef::Origin { name: "XY".into() }, sketch }, None).unwrap();
|
||||
assert_eq!(read(&document.to_json()).unwrap(), document);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
//! A sketch's control spline may save `nurbs`: its own `knots` (clamped, the point count plus
|
||||
//! the degree plus one) and `weights` (one per point; none: all 1). A projected free-form edge
|
||||
//! comes in as that one exact curve, where it came in as one spline per Bézier span. An older
|
||||
//! design has none: its splines are the clamped uniform B-splines they were, and its projected
|
||||
//! edges are read again as they rebuild. The last release refuses a design with this change
|
||||
//! (the newer format number).
|
||||
@@ -340,11 +340,7 @@ pub fn blend_seams(b: &ModelBody) -> Vec<BlendSeam> {
|
||||
all(j).into_iter().any(|name| {
|
||||
let (core, instance) = split_instance(name);
|
||||
let face = crate::piece_names::strip_qualifiers(core);
|
||||
edges.iter().any(|(edge, at)| {
|
||||
at == instance
|
||||
&& (edge.strip_prefix(face.as_str()).is_some_and(|r| r.starts_with('|'))
|
||||
|| edge.strip_suffix(face.as_str()).is_some_and(|r| r.ends_with('|')))
|
||||
})
|
||||
edges.iter().any(|(edge, at)| at == instance && edge_sides(edge).is_some_and(|(a, b)| a == face || b == face))
|
||||
})
|
||||
};
|
||||
let mut out = Vec::new();
|
||||
@@ -363,6 +359,44 @@ pub fn blend_seams(b: &ModelBody) -> Vec<BlendSeam> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The two faces an edge name `<face A>|<face B>` joins. A blend face's own name holds the edge it
|
||||
/// replaced (`F<feature>:blend:<face>|<face>`), so a side's name can hold `|` too: the split is the
|
||||
/// one `|` outside every blend face's edge (`F1:+y` and `F3:blend:F1:+z|F2:side` for
|
||||
/// `F1:+y|F3:blend:F1:+z|F2:side`). `None` for a name that is not two faces.
|
||||
fn edge_sides(edge: &str) -> Option<(&str, &str)> {
|
||||
let first = face_name_end(edge, 0)?;
|
||||
if edge.as_bytes().get(first) != Some(&b'|') || face_name_end(edge, first + 1)? != edge.len() {
|
||||
return None;
|
||||
}
|
||||
Some((edge.get(..first)?, edge.get(first + 1..)?))
|
||||
}
|
||||
|
||||
/// Where the face name starting at byte `from` of `s` ends: at the next `|`, or for a blend face
|
||||
/// past the two faces of the edge its name holds (and theirs, for blends of blends).
|
||||
fn face_name_end(s: &str, from: usize) -> Option<usize> {
|
||||
const MARK: &str = ":blend:";
|
||||
// The faces still to read: a blend face's name is read as the two of its edge.
|
||||
let (mut pending, mut at) = (1usize, from);
|
||||
loop {
|
||||
let rest = s.get(at..)?;
|
||||
let bar = rest.find('|').unwrap_or(rest.len());
|
||||
if let Some(m) = rest.get(..bar)?.find(MARK) {
|
||||
pending += 1;
|
||||
at += m + MARK.len();
|
||||
continue;
|
||||
}
|
||||
pending -= 1;
|
||||
at += bar;
|
||||
if pending == 0 {
|
||||
return Some(at);
|
||||
}
|
||||
if s.as_bytes().get(at) != Some(&b'|') {
|
||||
return None;
|
||||
}
|
||||
at += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// A name and the copy it names (`@F<feature>.<instance>`, a pattern's or a paste's copy of a
|
||||
/// tool face; empty for the original).
|
||||
fn split_instance(name: &str) -> (&str, &str) {
|
||||
|
||||
@@ -503,11 +503,33 @@ fn sketch_curves(ss: &crate::eval::SolvedSketch, ci: usize) -> Vec<WireCurve> {
|
||||
}
|
||||
|
||||
/// Edges `edges` of `body` (indices into its mesh's `edges`) on `plane` as their exact curves:
|
||||
/// lines, circles and arcs, and the Bézier pieces of a free-form curve. `None` for an edge that
|
||||
/// doesn't lie in a plane parallel to `plane` or isn't read exactly (a mesh body's): it is
|
||||
/// lines, circles and arcs, and a free-form curve as the one spline it is, its knots and weights
|
||||
/// its own. `None` for an edge that doesn't lie in a plane parallel to `plane`, isn't read
|
||||
/// exactly (a mesh body's) or is a spline no sketch holds (past degree 9 or 500 points): it is
|
||||
/// fitted to its polyline instead.
|
||||
fn exact_edges(body: &crate::ModelBody, plane: &Plane, edges: &[usize]) -> Vec<Option<Vec<LinkGeom>>> {
|
||||
body.body.planar_edges(plane, edges).into_iter().map(|segs| segs?.iter().map(link_geom).collect()).collect()
|
||||
body.body
|
||||
.planar_edges(plane, edges)
|
||||
.into_iter()
|
||||
.map(|pieces| {
|
||||
pieces?
|
||||
.iter()
|
||||
.map(|piece| match piece {
|
||||
crate::kernel::PlanarPiece::Seg(s) => link_geom(s),
|
||||
crate::kernel::PlanarPiece::Spline(s) => link_spline(s),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A free-form edge's B-spline as the control spline that is the same curve, with its own knots
|
||||
/// and weights. `None` for one a sketch can't hold.
|
||||
fn link_spline(s: &crate::kernel::PlanarSpline) -> Option<LinkGeom> {
|
||||
let degree = u8::try_from(s.degree).ok()?;
|
||||
let nurbs = solidcraft_sketch::Nurbs { knots: s.knots.clone(), weights: s.weights.clone() };
|
||||
nurbs.check(s.points.len(), degree).ok()?;
|
||||
Some(LinkGeom::Spline { pts: s.points.clone(), control: true, degree, periodic: false, nurbs: Some(nurbs) })
|
||||
}
|
||||
|
||||
/// `edges` of `body` projected on `plane`: each exactly ([`exact_edges`]) or fitted to its
|
||||
@@ -549,7 +571,16 @@ fn at_vertices(body: &crate::ModelBody, mesh: &Mesh, plane: &Plane, e: usize, g:
|
||||
for v in [plane.to_local(*first), plane.to_local(*last)] {
|
||||
let mut best: Option<(f64, &mut Vec2)> = None;
|
||||
for piece in g.iter_mut() {
|
||||
if let LinkGeom::Line(a, b) | LinkGeom::Arc { a, b, .. } | LinkGeom::Conic { a, b, .. } = piece {
|
||||
let ends = match piece {
|
||||
LinkGeom::Line(a, b) | LinkGeom::Arc { a, b, .. } | LinkGeom::Conic { a, b, .. } => Some((a, b)),
|
||||
// A control spline's end points are its ends.
|
||||
LinkGeom::Spline { pts, control: true, periodic: false, .. } => match pts.as_mut_slice() {
|
||||
[a, .., b] => Some((a, b)),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
if let Some((a, b)) = ends {
|
||||
for p in [a, b] {
|
||||
let d = p.dist(v);
|
||||
if d <= tol && best.as_ref().is_none_or(|(bd, _)| d < *bd) {
|
||||
@@ -587,8 +618,8 @@ fn link_geom(s: &Seg2) -> Option<LinkGeom> {
|
||||
LinkGeom::Arc { c: center, a, b }
|
||||
}
|
||||
Seg2::Conic { a, apex, b, w } => LinkGeom::Conic { a, apex, b, rho: w / (1. + w) },
|
||||
Seg2::Cubic { p0, p1, p2, p3 } => LinkGeom::Spline { pts: vec![p0, p1, p2, p3], control: true, degree: 3, periodic: false },
|
||||
Seg2::Bezier { n, p } => LinkGeom::Spline { pts: p.get(..=usize::from(n))?.to_vec(), control: true, degree: n, periodic: false },
|
||||
Seg2::Cubic { p0, p1, p2, p3 } => LinkGeom::Spline { pts: vec![p0, p1, p2, p3], control: true, degree: 3, periodic: false, nurbs: None },
|
||||
Seg2::Bezier { n, p } => LinkGeom::Spline { pts: p.get(..=usize::from(n))?.to_vec(), control: true, degree: n, periodic: false, nurbs: None },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1088,9 +1119,10 @@ fn project_sketch_curve(sk: &Sketch, from: &Plane, ci: usize, to: &Plane) -> Vec
|
||||
(Some(c), Some(m)) => vec![LinkGeom::Ellipse { c: map(c), major: map(m), minor: *r }],
|
||||
_ => Vec::new(),
|
||||
},
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic }) if parallel => {
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic, nurbs }) if parallel => {
|
||||
let p: Option<Vec<Vec2>> = pts.iter().map(|q| sk.point(*q).map(map)).collect();
|
||||
p.map(|pts| vec![LinkGeom::Spline { pts, control: *control, degree: *degree, periodic: *periodic }]).unwrap_or_default()
|
||||
p.map(|pts| vec![LinkGeom::Spline { pts, control: *control, degree: *degree, periodic: *periodic, nurbs: nurbs.clone() }])
|
||||
.unwrap_or_default()
|
||||
}
|
||||
Some(CurveKind::Conic { a, b, apex, rho }) if parallel => match (sk.point(*a), sk.point(*apex), sk.point(*b)) {
|
||||
(Some(a), Some(x), Some(b)) => vec![LinkGeom::Conic { a: map(a), apex: map(x), b: map(b), rho: *rho }],
|
||||
@@ -1206,7 +1238,7 @@ fn as_spline(pts: &[Vec2], tol: f64) -> Option<LinkGeom> {
|
||||
<= tol
|
||||
});
|
||||
if ok {
|
||||
return Some(LinkGeom::Spline { pts: fit, control: false, degree: 3, periodic: false });
|
||||
return Some(LinkGeom::Spline { pts: fit, control: false, degree: 3, periodic: false, nurbs: None });
|
||||
}
|
||||
}
|
||||
None
|
||||
|
||||
@@ -247,7 +247,9 @@ fn link_polyline(g: &solidcraft_sketch::LinkGeom) -> Vec<Vec2> {
|
||||
LinkGeom::Ellipse { c, major, minor } => {
|
||||
(0..=96).map(|i| solidcraft_sketch::ellipse_point(c, major, minor, i as f64 / 96.0 * std::f64::consts::TAU)).collect()
|
||||
}
|
||||
LinkGeom::Spline { ref pts, control, degree, periodic } => solidcraft_sketch::spline_polyline_mode(pts, control, degree, periodic),
|
||||
LinkGeom::Spline { ref pts, control, degree, periodic, ref nurbs } => {
|
||||
solidcraft_sketch::spline_polyline_mode(pts, control, degree, periodic, nurbs.as_ref())
|
||||
}
|
||||
LinkGeom::Point(_) => Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,13 @@ mod tests {
|
||||
vec![
|
||||
line(0., 1.),
|
||||
line(1., 2.),
|
||||
LinkGeom::Spline { pts: vec![Vec2::new(1., 0.), Vec2::new(2., 1.), Vec2::new(3., 1.)], control: false, degree: 2, periodic: false },
|
||||
LinkGeom::Spline {
|
||||
pts: vec![Vec2::new(1., 0.), Vec2::new(2., 1.), Vec2::new(3., 1.)],
|
||||
control: false,
|
||||
degree: 2,
|
||||
periodic: false,
|
||||
nurbs: None,
|
||||
},
|
||||
],
|
||||
vec![line(0., 1.), LinkGeom::Arc { c: Vec2::new(1., 1.), a: Vec2::new(1., 0.), b: Vec2::new(2., 1.) }],
|
||||
vec![line(0., 1.), line(1.00001, 2.)],
|
||||
|
||||
@@ -186,7 +186,17 @@ fn sketch_json(s: &Session, world: &solidcraft_doc::ModelState, id: u64) -> Opti
|
||||
CurveKind::Circle { c: cc, r } => json!({"id": c.id, "type": "circle", "center": pid(cc), "center_at": sk.point(cc), "radius": r, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Arc { c: cc, a, b } => json!({"id": c.id, "type": "arc", "center": pid(cc), "start": pid(a), "end": pid(b), "center_at": sk.point(cc), "start_at": sk.point(a), "end_at": sk.point(b), "radius": sk.radius(i), "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Ellipse { c: cc, m, r } => json!({"id": c.id, "type": "ellipse", "center": pid(cc), "major": pid(m), "center_at": sk.point(cc), "major_at": sk.point(m), "minor_radius": r, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Spline { ref pts, control, degree, periodic } => json!({"id": c.id, "type": "spline", "points": pts.iter().map(|q| pid(*q)).collect::<Vec<_>>(), "points_at": pts.iter().map(|q| sk.point(*q)).collect::<Vec<_>>(), "control": control, "degree": degree, "periodic": periodic, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Spline { ref pts, control, degree, periodic, ref nurbs } => {
|
||||
let mut v = json!({"id": c.id, "type": "spline", "points": pts.iter().map(|q| pid(*q)).collect::<Vec<_>>(), "points_at": pts.iter().map(|q| sk.point(*q)).collect::<Vec<_>>(), "control": control, "degree": degree, "periodic": periodic, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det});
|
||||
// A control spline with its own knots (a projected free-form edge) says them.
|
||||
if let (Some(n), Some(o)) = (nurbs, v.as_object_mut()) {
|
||||
o.insert("knots".into(), json!(n.knots));
|
||||
if !n.weights.is_empty() {
|
||||
o.insert("weights".into(), json!(n.weights));
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
CurveKind::Conic { a, b, apex, rho } => json!({"id": c.id, "type": "conic", "start": pid(a), "end": pid(b), "apex": pid(apex), "start_at": sk.point(a), "end_at": sk.point(b), "apex_at": sk.point(apex), "rho": rho, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
};
|
||||
if let (Some(l), Some(o)) = (&c.link, v.as_object_mut()) {
|
||||
|
||||
@@ -77,6 +77,9 @@ fn omission_retains_null_clears_and_unrelated_material_edits_retain_cards() {
|
||||
.and_then(|c| c.in_format(solidcraft_io::catalog::V1_FORMAT))
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("engineering cards"));
|
||||
// A library copy carries the card as it is.
|
||||
let copy = solidcraft_io::catalog::LibraryMaterial::from_material(&s.doc.user_materials[1]).unwrap();
|
||||
assert_eq!(copy.physical_card, original);
|
||||
s.execute("material.edit", &json!({"material":"Renamed","physical_card":null})).unwrap();
|
||||
assert!(s.doc.user_materials[1].physical_card.is_none());
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
@@ -137,15 +140,20 @@ fn configurations_rename_and_paste_new_keep_design_owned_material_semantics() {
|
||||
assert!(loaded.configs.rows.iter().any(|r| r.cells.iter().any(|c| c == "Renamed candidate")));
|
||||
}
|
||||
|
||||
/// Formats 20 (before engineering cards) and 21 (with them), as they were written (no pending
|
||||
/// format list): materials without cards come in with their optical look unchanged, upgraded.
|
||||
#[test]
|
||||
fn format21_materials_without_cards_keep_their_optical_look() {
|
||||
fn format20_and_21_materials_without_cards_keep_their_optical_look() {
|
||||
let s = fixture();
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["format"] = json!("solidcraft/21");
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials);
|
||||
assert!(loaded.user_materials[0].physical_card.is_none());
|
||||
assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
|
||||
for format in [20, 21] {
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["format"] = json!(format!("solidcraft/{format}"));
|
||||
saved.as_object_mut().unwrap().remove("format_pending");
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials, "format {format}");
|
||||
assert!(loaded.user_materials[0].physical_card.is_none(), "format {format}");
|
||||
assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT), "format {format}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -208,17 +216,6 @@ fn native_container_keeps_large_si_card_values_sources_conditions_and_density_se
|
||||
assert_eq!(material["physical_validation"]["source_review_required"], json!(["fixture"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format20_materials_without_cards_upgrade_to21_without_changing_their_optical_look() {
|
||||
let s = fixture();
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["format"] = json!("solidcraft/20");
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials);
|
||||
assert!(loaded.user_materials[0].physical_card.is_none());
|
||||
assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn card_number_admission_preserves_metadata_without_exempting_other_material_fields() {
|
||||
let s = fixture();
|
||||
|
||||
@@ -44,7 +44,7 @@ fn validate(_: &mut Session, params: &Value) -> Result<Value> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{doc::Document, product_scene};
|
||||
use crate::doc::Document;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn card() -> Value {
|
||||
@@ -69,43 +69,6 @@ mod tests {
|
||||
s
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn card_edits_preserve_mass_optics_and_geometry_and_survive_undo_reopen() {
|
||||
let mut s = fixture();
|
||||
let scene = product_scene::extract(&s).unwrap();
|
||||
let mass = s.execute("component.properties", &json!({})).unwrap();
|
||||
let before_undo = s.undo.len();
|
||||
let out = s.execute("material.edit", &json!({"material":"Synthetic","physical_card":card()})).unwrap();
|
||||
assert_eq!(out["physical_validation"]["isotropic_moduli"]["shear_pa"], 4.9e9);
|
||||
assert_eq!(out["density_comparison"]["assigned_density_kg_m3"], 800.0);
|
||||
assert_eq!(out["density_comparison"]["matches_within_relative_tolerance"], false);
|
||||
assert_eq!(out["physical_validation"]["source_review_required"], json!(["fixture"]));
|
||||
assert_eq!(out["physical_validation"]["analysis_solver_available"], false);
|
||||
assert_eq!(s.undo.len(), before_undo + 1);
|
||||
assert_eq!(s.execute("component.properties", &json!({})).unwrap(), mass);
|
||||
let after = product_scene::extract(&s).unwrap();
|
||||
assert!(Arc::ptr_eq(&scene.meshes[0].mesh, &after.meshes[0].mesh));
|
||||
assert_eq!(scene.meshes[0].surface, after.meshes[0].surface);
|
||||
let saved = s.doc.to_json();
|
||||
let saved_json: Value = serde_json::from_str(&saved).unwrap();
|
||||
assert_eq!(saved_json["format"], crate::doc::format::format_string(crate::doc::format::FORMAT));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(s.doc.user_materials[0].physical_card.is_none());
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
let mut reopened = Session::new(Document::from_json(&saved).unwrap());
|
||||
assert_eq!(reopened.execute("component.properties", &json!({})).unwrap(), mass);
|
||||
assert_eq!(reopened.doc.user_materials, s.doc.user_materials);
|
||||
let modulus = reopened.doc.user_materials[0].physical_card.as_ref().unwrap().card().directional_modulus([1., 2., 3.]).unwrap();
|
||||
assert_eq!(modulus.young_modulus_pa, 12.25e9);
|
||||
let doc = reopened.doc.clone();
|
||||
let before = (reopened.revision, reopened.undo.len(), reopened.camera, reopened.selection.clone());
|
||||
let list = reopened.execute("material.list", &json!({})).unwrap();
|
||||
let material = list["materials"].as_array().unwrap().iter().find(|m| m["name"] == "Synthetic").unwrap();
|
||||
assert_eq!(material["physical_card"], out["physical_card"]);
|
||||
assert!(Arc::ptr_eq(&doc, &reopened.doc));
|
||||
assert_eq!(before, (reopened.revision, reopened.undo.len(), reopened.camera, reopened.selection.clone()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn personal_format29_cards_upgrade_to_current_pending_format_without_changing_values() {
|
||||
let mut s = fixture();
|
||||
@@ -126,184 +89,6 @@ mod tests {
|
||||
assert_eq!(session.execute("component.properties", &json!({})).unwrap(), mass);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn omission_retains_null_clears_and_unrelated_material_edits_retain_cards() {
|
||||
let mut s = fixture();
|
||||
s.execute("material.create", &json!({"name":"With card","density_g_cm3":0.7,"physical_card":card()})).unwrap();
|
||||
let original = s.doc.user_materials[1].physical_card.clone();
|
||||
for p in [json!({"density_g_cm3":0.9}), json!({"color":"#112233"}), json!({"name":"Renamed"})] {
|
||||
let mut p = p;
|
||||
p["material"] = json!(s.doc.user_materials[1].name);
|
||||
s.execute("material.edit", &p).unwrap();
|
||||
assert_eq!(s.doc.user_materials[1].physical_card, original);
|
||||
}
|
||||
let copy = solidcraft_io::catalog::LibraryMaterial::from_material(&s.doc.user_materials[1]).unwrap();
|
||||
assert_eq!(copy.physical_card, original);
|
||||
s.execute("material.edit", &json!({"material":"Renamed","physical_card":null})).unwrap();
|
||||
assert!(s.doc.user_materials[1].physical_card.is_none());
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.user_materials[1].physical_card, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_cards_refuse_atomically_and_saved_card_admission_is_not_bypassed() {
|
||||
let mut s = fixture();
|
||||
let mut bad = card();
|
||||
bad["properties"][1]["data"]["model"]["poisson_ratio"] = json!(0.6);
|
||||
let mut oversized = card();
|
||||
oversized["sources"] = json!(vec![json!({}); 33]);
|
||||
let mut unknown = card();
|
||||
unknown["unrecognized"] = json!(true);
|
||||
let mut missing = card();
|
||||
missing["properties"][0]["source_id"] = json!("missing");
|
||||
let doc = s.doc.clone();
|
||||
let before = (s.undo.len(), s.redo.len(), s.revision, s.camera, s.selection.clone());
|
||||
for candidate in [bad, oversized, unknown, missing, json!(true)] {
|
||||
assert!(s.execute("material.edit", &json!({"material":"Synthetic","physical_card":candidate})).is_err());
|
||||
assert!(s.execute("material.create", &json!({"name":"Refused","density_g_cm3":1,"physical_card":candidate})).is_err());
|
||||
assert!(Arc::ptr_eq(&doc, &s.doc));
|
||||
assert_eq!(before, (s.undo.len(), s.redo.len(), s.revision, s.camera, s.selection.clone()));
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["user_materials"][0]["physical_card"] = candidate;
|
||||
assert!(Document::from_json(&saved.to_string()).is_err());
|
||||
assert!(serde_json::from_value::<Document>(saved).is_err());
|
||||
}
|
||||
// Large finite SI constants are accepted only in this typed card, not geometry.
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["user_materials"][0]["physical_card"] = card();
|
||||
assert!(Document::from_json(&saved.to_string()).is_ok());
|
||||
saved["hostile_numeric_probe"] = json!(12.25e9);
|
||||
assert!(Document::from_json(&saved.to_string()).unwrap_err().to_string().contains("number"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configurations_rename_and_paste_new_keep_design_owned_material_semantics() {
|
||||
let mut s = Session::default();
|
||||
let part = s.execute("component.create", &json!({"name":"Part"})).unwrap()["component"].as_u64().unwrap();
|
||||
s.execute("solid.box", &json!({"body_name":"Specimen","length":10,"width":10,"height":10})).unwrap();
|
||||
s.execute("material.create", &json!({"name":"Synthetic","density_g_cm3":0.8,"physical_card":card()})).unwrap();
|
||||
s.execute("config.configure", &json!({"materials":["Specimen"]})).unwrap();
|
||||
s.execute("config.row", &json!({"name":"Candidate","values":{"material:Specimen":"Synthetic"}})).unwrap();
|
||||
s.execute("config.activate", &json!({"row":"Candidate"})).unwrap();
|
||||
s.execute("component.activate", &json!({"component":0})).unwrap();
|
||||
s.execute("component.paste_new", &json!({"component":part,"translate":[30,0,0]})).unwrap();
|
||||
assert_eq!(s.doc.user_materials.len(), 1);
|
||||
assert_eq!(s.doc.materials.values().filter(|m| *m == "Synthetic").count(), 2);
|
||||
let original = s.doc.user_materials[0].physical_card.clone();
|
||||
s.execute("material.edit", &json!({"material":"Synthetic","name":"Renamed candidate"})).unwrap();
|
||||
s.execute("config.activate", &json!({"row":"Default"})).unwrap();
|
||||
s.execute("config.activate", &json!({"row":"Candidate"})).unwrap();
|
||||
let loaded = Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(loaded.user_materials[0].physical_card, original);
|
||||
assert_eq!(loaded.materials.values().filter(|m| *m == "Renamed candidate").count(), 2);
|
||||
assert!(loaded.configs.rows.iter().any(|r| r.cells.iter().any(|c| c == "Renamed candidate")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format21_materials_without_cards_keep_their_optical_look() {
|
||||
let s = fixture();
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["format"] = json!("solidcraft/21");
|
||||
saved.as_object_mut().unwrap().remove("format_pending");
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials);
|
||||
assert!(loaded.user_materials[0].physical_card.is_none());
|
||||
assert_eq!(loaded.format, crate::doc::format::format_string(crate::doc::format::FORMAT));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_catalog_refuses_card_export_without_creating_or_replacing_files_or_history() {
|
||||
struct ProbeFile(std::path::PathBuf);
|
||||
impl Drop for ProbeFile {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_file(&self.0);
|
||||
}
|
||||
}
|
||||
let unique = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
|
||||
let file = ProbeFile(std::env::temp_dir().join(format!("solidcraft-card-refusal-{}-{unique}.json", std::process::id())));
|
||||
let mut s = Session::default();
|
||||
s.execute("material.create", &json!({"name":"Card only","density_g_cm3":0.8,"physical_card":card()})).unwrap();
|
||||
s.mark_saved();
|
||||
let doc = s.doc.clone();
|
||||
let history = (s.undo.len(), s.redo.len(), s.revision);
|
||||
for existing in [false, true] {
|
||||
if existing {
|
||||
std::fs::write(&file.0, b"keep existing catalog").unwrap();
|
||||
}
|
||||
for overwrite in [false, true] {
|
||||
let error = s
|
||||
.execute("library.export", &json!({"path":file.0,"format":solidcraft_io::catalog::V1_FORMAT,"overwrite":overwrite}))
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("cannot preserve PBR or engineering cards"));
|
||||
if existing {
|
||||
assert_eq!(std::fs::read(&file.0).unwrap(), b"keep existing catalog");
|
||||
} else {
|
||||
assert!(!file.0.exists());
|
||||
}
|
||||
assert!(Arc::ptr_eq(&doc, &s.doc));
|
||||
assert_eq!((s.undo.len(), s.redo.len(), s.revision), history);
|
||||
assert!(!s.is_dirty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_container_keeps_large_si_card_values_sources_conditions_and_density_separate() {
|
||||
let mut s = fixture();
|
||||
s.execute("material.edit", &json!({"material":"Synthetic","physical_card":card()})).unwrap();
|
||||
let before = s.execute("component.properties", &json!({})).unwrap();
|
||||
let scene = product_scene::extract(&s).unwrap();
|
||||
let native = solidcraft_io::write_design_container(&s.doc).unwrap();
|
||||
assert!(solidcraft_io::is_design_container(&native));
|
||||
let loaded = solidcraft_io::read_design(&native).unwrap();
|
||||
assert_eq!(loaded.format, crate::doc::format::format_string(crate::doc::format::FORMAT));
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials);
|
||||
let mut reopened = Session::new(loaded);
|
||||
assert_eq!(reopened.execute("component.properties", &json!({})).unwrap(), before);
|
||||
assert_eq!(product_scene::extract(&reopened).unwrap().meshes[0].surface, scene.meshes[0].surface);
|
||||
let list = reopened.execute("material.list", &json!({})).unwrap();
|
||||
let material = list["materials"].as_array().unwrap().iter().find(|m| m["name"] == "Synthetic").unwrap();
|
||||
assert_eq!(material["physical_card"], serde_json::to_value(s.doc.user_materials[0].physical_card.as_ref().unwrap()).unwrap());
|
||||
assert_eq!(material["density_comparison"]["assigned_density_kg_m3"], 800.0);
|
||||
assert_eq!(material["density_comparison"]["card_density_kg_m3"], 700.0);
|
||||
assert_eq!(material["physical_validation"]["source_review_required"], json!(["fixture"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format20_materials_without_cards_upgrade_without_changing_their_optical_look() {
|
||||
let s = fixture();
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["format"] = json!("solidcraft/20");
|
||||
saved.as_object_mut().unwrap().remove("format_pending");
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
assert_eq!(loaded.user_materials, s.doc.user_materials);
|
||||
assert!(loaded.user_materials[0].physical_card.is_none());
|
||||
assert_eq!(loaded.format, crate::doc::format::format_string(crate::doc::format::FORMAT));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn card_number_admission_preserves_metadata_without_exempting_other_material_fields() {
|
||||
let s = fixture();
|
||||
let mut saved = serde_json::to_value(&*s.doc).unwrap();
|
||||
saved["user_materials"][0]["physical_card"] = card();
|
||||
let metadata = json!({"org.example.measurement":{"value":12.25e9,"physical_card":{"untyped":12.25e9}}});
|
||||
saved["metadata"] = metadata.clone();
|
||||
let loaded = Document::from_json(&saved.to_string()).unwrap();
|
||||
let reopened = solidcraft_io::read_design(&solidcraft_io::write_design_container(&loaded).unwrap()).unwrap();
|
||||
assert_eq!(serde_json::to_value(&reopened.metadata).unwrap(), metadata);
|
||||
assert_eq!(reopened.user_materials, loaded.user_materials);
|
||||
|
||||
// Only the exact root user-material card receives SI admission. The same key
|
||||
// nested elsewhere must not exempt a hostile number from geometry limits.
|
||||
for field in ["appearance", "unrecognized"] {
|
||||
let mut hostile = saved.clone();
|
||||
hostile["user_materials"][0][field] = json!({"physical_card":{"untyped":12.25e9}});
|
||||
assert!(Document::from_json(&hostile.to_string()).unwrap_err().to_string().contains("number"));
|
||||
}
|
||||
saved["user_materials"][0]["density"] = json!(12.25e9);
|
||||
assert!(Document::from_json(&saved.to_string()).unwrap_err().to_string().contains("number"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn material_inspection_preserves_legacy_entries_and_reports_unknowns_and_density_separately() {
|
||||
let mut s = fixture();
|
||||
|
||||
@@ -926,8 +926,13 @@ fn circular_pattern_of_a_hole_and_its_chamfers_copies_all_of_them() {
|
||||
assert!(rel(v0, v1) < 1e-9);
|
||||
run(&mut s, "solid.pattern.circular", json!({"features": ["Bore", "TopChamfer", "BottomChamfer"], "axis": "Z", "count": 6, "angle": 360}));
|
||||
let v = volume(&mut s);
|
||||
println!("{v1} -> {v}");
|
||||
assert!(v < v1 - 5.0 * 0.9 * (std::f64::consts::PI * 9.0 * 10.0), "pattern had no effect: {v1} -> {v}");
|
||||
// One chamfered hole takes its bore, π·3²·10, and two rings of the chamfer's triangle,
|
||||
// 0.5 × 0.5 / 2, about the bore's axis at its centroid's radius 3 + 0.5/3 (Pappus). The
|
||||
// copies, 20 apart on the radius 20, do not meet: the pattern takes five more.
|
||||
let pi = std::f64::consts::PI;
|
||||
let hole = pi * 9.0 * 10.0 + 2.0 * 2.0 * pi * (3.0 + 0.5 / 3.0) * 0.125;
|
||||
assert!((v1 - (pi * 900.0 * 10.0 - hole)).abs() < 4e-7 * v1, "{v1}");
|
||||
assert!((v - (v1 - 5.0 * hole)).abs() < 4e-7 * v1, "{v1} -> {v}, expected {}", v1 - 5.0 * hole);
|
||||
}
|
||||
|
||||
/// The features are copied in timeline order, not in the order they were picked in: a chamfer
|
||||
|
||||
@@ -505,7 +505,7 @@ fn blend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (sp, cons) = if order <= 1 {
|
||||
let c1 = sk.add_point(qa + ta * (l / 3.0), None)?;
|
||||
let c2 = sk.add_point(qb + tb * (l / 3.0), None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts: vec![pa, c1, c2, pb], control: true, degree: 3, periodic: false }, None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts: vec![pa, c1, c2, pb], control: true, degree: 3, periodic: false, nurbs: None }, None)?;
|
||||
let cons = vec![add_c(sk, ConstraintKind::Tangent { a: ca, b: sp })?, add_c(sk, ConstraintKind::Tangent { a: cb, b: sp })?];
|
||||
(sp, cons)
|
||||
} else {
|
||||
@@ -527,7 +527,7 @@ fn blend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
});
|
||||
}
|
||||
let degree = u8::try_from(cps.len().saturating_sub(1)).map_err(|_| bad(cmd, "the blend curve needs too many control points"))?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts, control: true, degree, periodic: false }, None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts, control: true, degree, periodic: false, nurbs: None }, None)?;
|
||||
(sp, Vec::new())
|
||||
};
|
||||
solve_new_only(sk, first_new);
|
||||
@@ -655,7 +655,7 @@ fn spline(s: &mut Session, p: &Value, cmd: &str, control: bool, degree: u8) -> R
|
||||
{
|
||||
pts.push(*pts.first().ok_or_else(|| bad(cmd, "missing first point"))?);
|
||||
}
|
||||
let c = sk.add_curve(CurveKind::Spline { pts, control, degree, periodic }, None)?;
|
||||
let c = sk.add_curve(CurveKind::Spline { pts, control, degree, periodic, nurbs: None }, None)?;
|
||||
mark_construction(sk, &[c], p);
|
||||
Ok((ids_of(sk, &[c]), Vec::new()))
|
||||
})?;
|
||||
@@ -1344,13 +1344,13 @@ mod blend_tests {
|
||||
let mut broken = solidcraft_sketch::Sketch::new();
|
||||
let p0 = broken.add_point(Vec2::new(1.0, 1.0), None).unwrap();
|
||||
let p1 = broken.add_point(Vec2::ZERO, None).unwrap();
|
||||
let l = broken.add_curve(CurveKind::Spline { pts: vec![p1, p0], control: true, degree: 1, periodic: false }, None).unwrap();
|
||||
let l = broken.add_curve(CurveKind::Spline { pts: vec![p1, p0], control: true, degree: 1, periodic: false, nurbs: None }, None).unwrap();
|
||||
broken.points[p0].pos = Vec2::new(f64::NAN, 4.0);
|
||||
assert!(super::joint_derivatives(&broken, l, p1, 2, true, "a", "sketch.blend_curve").is_err(), "non-finite geometry");
|
||||
let mut flat = solidcraft_sketch::Sketch::new();
|
||||
let q0 = flat.add_point(Vec2::new(3.0, 3.0), None).unwrap();
|
||||
let q1 = flat.add_point(Vec2::new(3.0, 3.0), None).unwrap();
|
||||
let d = flat.add_curve(CurveKind::Spline { pts: vec![q0, q1], control: true, degree: 1, periodic: false }, None).unwrap();
|
||||
let d = flat.add_curve(CurveKind::Spline { pts: vec![q0, q1], control: true, degree: 1, periodic: false, nurbs: None }, None).unwrap();
|
||||
let e = super::joint_derivatives(&flat, d, q0, 2, true, "a", "sketch.blend_curve").unwrap_err().to_string();
|
||||
assert!(e.contains("no tangent"), "{e}");
|
||||
assert!(solidcraft_geom::hermite_bezier(Vec2::ZERO, Vec2::X, &[Vec2::Y; 5], &[Vec2::Y; 5]).is_none(), "no order above g4");
|
||||
|
||||
@@ -156,7 +156,7 @@ fn add_pieces(sk: &mut Sketch, segs: &[Seg2], start: Option<usize>, end: Option<
|
||||
Seg2::Line { .. } => CurveKind::Line { a: prev, b: to },
|
||||
Seg2::Cubic { p1, p2, .. } => {
|
||||
let (c1, c2) = (sk.add_point(p1, None)?, sk.add_point(p2, None)?);
|
||||
CurveKind::Spline { pts: vec![prev, c1, c2, to], control: true, degree: 3, periodic: false }
|
||||
CurveKind::Spline { pts: vec![prev, c1, c2, to], control: true, degree: 3, periodic: false, nurbs: None }
|
||||
}
|
||||
Seg2::Conic { apex, w, .. } => {
|
||||
let x = sk.add_point(apex, None)?;
|
||||
@@ -169,7 +169,7 @@ fn add_pieces(sk: &mut Sketch, segs: &[Seg2], start: Option<usize>, end: Option<
|
||||
pts.push(sk.add_point(*q, None)?);
|
||||
}
|
||||
pts.push(to);
|
||||
CurveKind::Spline { pts, control: true, degree: n, periodic: false }
|
||||
CurveKind::Spline { pts, control: true, degree: n, periodic: false, nurbs: None }
|
||||
}
|
||||
Seg2::Arc { .. } => return Err(bad("trim", "unexpected arc piece")),
|
||||
};
|
||||
|
||||
@@ -101,7 +101,7 @@ pub(super) fn add_geometry(sk: &mut Sketch, geom: &[Geom2], f: &dyn Fn(Vec2) ->
|
||||
idx.push(i);
|
||||
}
|
||||
}
|
||||
(idx.len() >= 2).then_some(CurveKind::Spline { pts: idx, control: *control, degree: *degree, periodic: false })
|
||||
(idx.len() >= 2).then_some(CurveKind::Spline { pts: idx, control: *control, degree: *degree, periodic: false, nurbs: None })
|
||||
}
|
||||
Geom2::Conic { a, apex, b, rho } => {
|
||||
let (a, x, b) = (pt(sk, *a)?, pt(sk, *apex)?, pt(sk, *b)?);
|
||||
|
||||
@@ -1764,7 +1764,7 @@ fn offset_side(sk: &mut Sketch, cmd: &str, order: &[(usize, bool)], sources: &[(
|
||||
idx.push(pb);
|
||||
idx.dedup();
|
||||
if idx.len() >= 2 {
|
||||
made.push(sk.add_curve(CurveKind::Spline { pts: idx, control: false, degree: 3, periodic: false }, None)?);
|
||||
made.push(sk.add_curve(CurveKind::Spline { pts: idx, control: false, degree: 3, periodic: false, nurbs: None }, None)?);
|
||||
}
|
||||
}
|
||||
Piece::Line(..) => {
|
||||
|
||||
@@ -936,3 +936,38 @@ fn intersect_on_a_top_face_gives_its_outline() {
|
||||
let ends = outline(&intersect_curves(&block, json!({"plane": "XY", "offset": 20})).unwrap());
|
||||
assert_eq!(ends, vec![[0.0, 0.0, 0.0, 30.0], [0.0, 0.0, 40.0, 0.0], [0.0, 30.0, 40.0, 30.0], [40.0, 0.0, 40.0, 30.0]]);
|
||||
}
|
||||
|
||||
/// A free-form edge projects as the one exact spline it is, its knots and weights its own: the
|
||||
/// bottom face of a 40 x 20 x 10 box whose upright edges have G2 rounds (each round's bottom
|
||||
/// edge a B-spline of several spans) comes into its sketch as four lines and four splines, one a
|
||||
/// corner, each meeting the lines at their ends (#3604, where each span was a curve of its own).
|
||||
/// The profile they bound, extruded the box's height, is the box: its sides are upright.
|
||||
#[test]
|
||||
fn a_free_form_edge_projects_as_one_spline_with_its_own_knots() {
|
||||
use solidcraft_sketch::CurveKind;
|
||||
let volume = |s: &Session, body: &str| solidcraft_kernel::measure(&s.world_state().unwrap().body(body).unwrap().body).unwrap().volume;
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"corner":[0,0,0],"length":40,"width":20,"height":10,"body_name":"B"}));
|
||||
run(&mut s, "solid.fillet", json!({"body":"B","edges":[[0,0,5],[40,0,5],[40,20,5],[0,20,5]],"radius":5,"type":"g2"}));
|
||||
let id = run(&mut s, "sketch.create", json!({"plane":{"face":[20,10,0]},"project_edges":true,"name":"Bottom"}))["sketch"].as_u64().unwrap();
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
let st = s.model.state();
|
||||
let sketch = &st.sketch(id).unwrap().sketch;
|
||||
let lines = sketch.curves.iter().filter(|c| matches!(c.kind, CurveKind::Line { .. })).count();
|
||||
let splines: Vec<_> = sketch.curves.iter().filter(|c| matches!(c.kind, CurveKind::Spline { .. })).collect();
|
||||
assert_eq!((lines, splines.len(), sketch.curves.len()), (4, 4, 8), "{:?}", sketch.curves);
|
||||
for c in &splines {
|
||||
let CurveKind::Spline { pts, control: true, nurbs: Some(nurbs), .. } = &c.kind else { panic!("{:?}", c.kind) };
|
||||
assert_eq!(nurbs.knots.len(), pts.len() + 4, "a cubic's knots");
|
||||
let (a, b) = c.kind.ends().unwrap();
|
||||
for end in [a, b] {
|
||||
let meets = sketch.curves.iter().filter(|o| matches!(o.kind, CurveKind::Line { a, b } if a == end || b == end)).count();
|
||||
assert_eq!(meets, 1, "{} end {end}", c.id);
|
||||
}
|
||||
}
|
||||
drop(st);
|
||||
let rounded = volume(&s, "B");
|
||||
run(&mut s, "solid.extrude", json!({"sketch":"Bottom","distance":10,"operation":"new","body_name":"P"}));
|
||||
let prism = volume(&s, "P");
|
||||
assert!((prism - rounded).abs() < rounded * 1e-6, "{prism} vs {rounded}");
|
||||
}
|
||||
@@ -1617,8 +1617,17 @@ fn the_first_dimension_scales_shapes_joined_by_a_constraint() {
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [20, 10]}));
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [30, 10], "p1": [45, 20]}));
|
||||
run(&mut s, "sketch.constraint.coincident", json!({"a": "l1.start", "b": "l5.start"}));
|
||||
let before = sketch(&s);
|
||||
let f = 40.0 / pt(&s, "l1.end").dist(pt(&s, "l1.start"));
|
||||
let out = run(&mut s, "sketch.dimension", json!({"entities": ["l1"], "value": "40 mm", "scale_sketch": true}));
|
||||
assert!(out.get("scaled").is_some(), "{out}");
|
||||
assert!((out["scaled"].as_f64().unwrap() - f).abs() < 1e-6, "{out}");
|
||||
// l1 measures its value, and every point of both rectangles, the joined one too, scaled
|
||||
// about the origin by the same factor: the joined rectangle keeps its shape at its scaled place.
|
||||
assert!((pt(&s, "l1.end").dist(pt(&s, "l1.start")) - 40.0).abs() < 1e-6);
|
||||
let after = sketch(&s);
|
||||
for (p, q) in before.points.iter().zip(&after.points) {
|
||||
assert!(q.pos.dist(p.pos * f) < 1e-6, "{} {:?} -> {:?}", p.id, p.pos, q.pos);
|
||||
}
|
||||
}
|
||||
|
||||
/// The cursor fallback shares the held solves' frame budget; a scripted drag can finish later.
|
||||
|
||||
@@ -1976,15 +1976,16 @@ mod tests {
|
||||
let before: Vec<solidcraft_geom::Vec3> = st.body("Shell").unwrap().body.edges(0.1).unwrap().iter().flat_map(|e| e.points.clone()).collect();
|
||||
assert!(!before.is_empty());
|
||||
let area_before = area(&s, "Shell");
|
||||
// The fairing reports both energies, the second no larger than the first.
|
||||
// The fairing reports both energies. The fit is not the fairest surface on its own rim, so
|
||||
// the energy falls strictly and the face moves: its area changes.
|
||||
let reply = run(&mut s, "surface.fair", json!({"body": "Shell", "tolerance": 1.0, "iterations": 3}));
|
||||
let (energy_before, energy_after) = energies(&reply);
|
||||
let area_after = area(&s, "Shell");
|
||||
eprintln!("surface.fair: {reply}\nenergies {energy_before:e} → {energy_after:e}, area {area_before} → {area_after}");
|
||||
assert!(energy_before > 0.0 && energy_after <= energy_before, "{energy_before:e} → {energy_after:e}");
|
||||
// The face moved (the fit is not the flattest surface on its own rim), but not its edges:
|
||||
// every boundary point of the body is where it was, bit for bit.
|
||||
assert!((area_after - area_before).abs() > 0.0 || energy_after < energy_before);
|
||||
assert!(energy_before > 0.0 && energy_after < energy_before, "{energy_before:e} → {energy_after:e}");
|
||||
assert_ne!(area_after, area_before, "the fairing did not move the face");
|
||||
// The edges do not move: every boundary point of the faired body is where it was, bit for
|
||||
// bit, and the sheet is still the one face.
|
||||
let st = s.world_state().unwrap();
|
||||
let after: Vec<solidcraft_geom::Vec3> = st.body("Shell").unwrap().body.edges(0.1).unwrap().iter().flat_map(|e| e.points.clone()).collect();
|
||||
assert_eq!(after, before, "fairing must not move the face's edges");
|
||||
assert_eq!(st.body("Shell").unwrap().body.face_count(), 1);
|
||||
|
||||
@@ -72,9 +72,13 @@ fn sketches_and_planes_move_with_the_component() {
|
||||
fn world_picks_map_into_the_component() {
|
||||
let mut s = moved_part();
|
||||
let v0 = volume(&mut s);
|
||||
assert!((v0 - 6000.0).abs() < 1e-6, "{v0}"); // 30 x 20 x 10
|
||||
// The edge along X at the top front: world (65, 0, 10).
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[65, 0, 10]], "radius": 2}));
|
||||
assert!(volume(&mut s) < v0 - 1.0, "the fillet cut material");
|
||||
let filleted = volume(&mut s);
|
||||
// A round of radius 2 along the 30 mm edge removes r²(1 − π/4) of section along its length.
|
||||
let round = 4.0 * (1.0 - std::f64::consts::PI / 4.0) * 30.0;
|
||||
assert!((v0 - filleted - round).abs() < 4e-7 * v0, "the fillet cut {} against {round}", v0 - filleted);
|
||||
// The modified face has no certified lineage; explicitly freeze its picked plane.
|
||||
// Its world pick still maps into the moved component exactly once.
|
||||
run(&mut s, "sketch.create", json!({"plane": {"face": [70, 10, 10],"fixed":true}, "name": "Pad"}));
|
||||
@@ -88,7 +92,10 @@ fn world_picks_map_into_the_component() {
|
||||
assert!(near(pad, Vec3::new(70.0, 10.0, 10.0)), "{pad:?}");
|
||||
let v1 = volume(&mut s);
|
||||
let h = run(&mut s, "solid.hole", json!({"position": [60, 10, 10], "diameter": 4, "depth": 5}));
|
||||
assert!(volume(&mut s) < v1 - 1.0, "the hole cut material: {h}");
|
||||
// A simple (flat-bottomed) hole: a cylinder of radius 2, 5 deep, clear of the round at y < 2.
|
||||
let bore = std::f64::consts::PI * 4.0 * 5.0;
|
||||
let v2 = volume(&mut s);
|
||||
assert!((v1 - v2 - bore).abs() < 4e-7 * v1, "the hole cut {} against {bore}: {h}", v1 - v2);
|
||||
// A box made at world (100, 0, 0) in the active (moved) component shows there.
|
||||
run(&mut s, "solid.box", json!({"length": 5, "width": 5, "height": 5, "corner": [100, 0, 0], "operation": "new"}));
|
||||
let last = s.model.state().bodies.last().map(|b| b.name.clone()).unwrap();
|
||||
@@ -108,7 +115,11 @@ fn picks_on_an_instance_map_through_its_placement() {
|
||||
// An edge of the second instance only (world y = 40).
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[5, 40, 10]], "radius": 2}));
|
||||
let v1 = volume(&mut s);
|
||||
assert!(v1 < v0 - 1.0, "{v0} {v1}");
|
||||
// Two 10 mm cubes; the round of radius 2 along one 10 mm edge of the component removes
|
||||
// r²(1 − π/4)·10 from every instance, the picked one and the other.
|
||||
assert!((v0 - 2000.0).abs() < 1e-6, "{v0}");
|
||||
let round = 4.0 * (1.0 - std::f64::consts::PI / 4.0) * 10.0;
|
||||
assert!((v0 - v1 - 2.0 * round).abs() < 4e-7 * v0, "{v0} {v1}");
|
||||
}
|
||||
|
||||
/// (c) Moving a body into a moved component keeps it where it is in the world.
|
||||
|
||||
@@ -375,6 +375,34 @@ fn blend_seams_are_a_rounds_contacts_and_the_blends_beside_it() {
|
||||
assert!(corner.iter().all(|x| x.kind == BlendSeamKind::Blend), "{seams:?}");
|
||||
}
|
||||
|
||||
/// A round along a chain onto an earlier round's end has that round for one of its faces, and
|
||||
/// that round's own faces are not its own: where it runs into the cylinder the earlier round
|
||||
/// rolls on, its end face, is no seam of it (a block's arc at a cylinder rounded r2, then the
|
||||
/// block's top edge with the round's end curve on its side face rounded r1; the earlier round's
|
||||
/// name holds a `|` of its own, `F3:blend:F1:+z|F2:side`).
|
||||
#[test]
|
||||
fn a_round_of_a_round_s_end_has_no_seam_with_that_round_s_faces() {
|
||||
use solidcraft_doc::naming::{blend_seams, face_names};
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 40, "width": 10, "height": 15, "corner": [0, -5, 0], "body_name": "Block"}));
|
||||
run(&mut s, "solid.cylinder", json!({"radius": 10, "height": 30, "base": [0, 0, 0], "operation": "join", "targets": ["Block"]}));
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[10, 0, 15]], "radius": 2}));
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[30, 5, 15]], "radius": 1}));
|
||||
let state = s.model.state();
|
||||
let body = &state.bodies[0];
|
||||
let names = face_names(body);
|
||||
let mesh = body.mesh();
|
||||
let sides = |edge: usize| -> Vec<&str> { mesh.edge_faces[edge].iter().filter_map(|f| names.get(*f as usize).map(String::as_str)).collect() };
|
||||
let seams = blend_seams(body);
|
||||
assert!(!seams.is_empty());
|
||||
for seam in &seams {
|
||||
let faces = sides(seam.edge);
|
||||
if faces.iter().any(|n| n.starts_with("F2:side")) {
|
||||
assert!(faces.iter().any(|n| n.starts_with("F3:blend:")), "a seam of the r2 round only: {faces:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A fillet of a shell's inner corners names those edges. Thinning the wall past the outer
|
||||
/// round removes them. The fillet must say the names are gone, not blend the seam nearest
|
||||
/// the old pick, which now sits on the axis of the inner round (#775).
|
||||
|
||||
@@ -177,17 +177,40 @@ mod tests {
|
||||
assert!(reopened_plate.contains(solidcraft_geom::Vec3::new(40., 35., 2.)));
|
||||
}
|
||||
|
||||
/// Every built-in sample builds without a failing feature or joint.
|
||||
/// Every built-in sample builds without a failing feature or joint, and without a panic on
|
||||
/// the way: panics inside the kernel are caught natively, but abort the web build (wasm
|
||||
/// can't unwind; the Plastic Enclosure's bosses used to panic 8 times).
|
||||
#[test]
|
||||
fn samples_build_cleanly() {
|
||||
fn samples_build_cleanly_without_panics() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let me = std::thread::current().id();
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let seen = count.clone();
|
||||
let prev = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |_| {
|
||||
if std::thread::current().id() == me {
|
||||
seen.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}));
|
||||
let mut failed = Vec::new();
|
||||
for s in super::samples() {
|
||||
let mut session = crate::Session::default();
|
||||
if let Err(e) = session.run_script(&(s.script)()) {
|
||||
panic!("{}: {e}", s.name);
|
||||
let built = session.run_script(&(s.script)());
|
||||
let panics = count.swap(0, Ordering::SeqCst);
|
||||
if panics > 0 {
|
||||
failed.push(format!("{}: {panics} panic(s)", s.name));
|
||||
}
|
||||
if let Err(e) = built {
|
||||
failed.push(format!("{}: {e}", s.name));
|
||||
continue;
|
||||
}
|
||||
failed.extend(session.model.results.iter().filter_map(|r| r.error.as_ref().map(|e| format!("{}: {}: {e}", s.name, r.name))));
|
||||
if session.model.state().bodies.is_empty() {
|
||||
failed.push(format!("{}: no bodies", s.name));
|
||||
}
|
||||
let failed: Vec<String> = session.model.results.iter().filter_map(|r| r.error.as_ref().map(|e| format!("{}: {e}", r.name))).collect();
|
||||
assert!(failed.is_empty(), "{}: {failed:?}", s.name);
|
||||
assert!(!session.model.state().bodies.is_empty(), "{}", s.name);
|
||||
}
|
||||
std::panic::set_hook(prev);
|
||||
assert!(failed.is_empty(), "{failed:?}");
|
||||
}
|
||||
}
|
||||
+31
-18
@@ -391,7 +391,6 @@ mod flush_join_loft;
|
||||
mod gltf_import;
|
||||
mod import_component;
|
||||
mod large_step_import;
|
||||
mod loft_cut;
|
||||
mod loft_ring;
|
||||
mod loft_spacing;
|
||||
mod mirror_placed;
|
||||
@@ -3116,9 +3115,13 @@ fn lip_after_boss() {
|
||||
run(&mut s, "plastic.boss", json!({"position": [70, 40, 2], "diameter": 7, "height": 12, "hole_diameter": 2.5}));
|
||||
let v0 = volume(&mut s);
|
||||
run(&mut s, "plastic.lip", json!({"face": [1, 25, 30], "width": 1, "height": 2}));
|
||||
let v = volume(&mut s);
|
||||
assert!(v > v0 + 1.0, "{v0} {v}");
|
||||
// Bosses up to the rim, with ribs, against a wall; lips, grooves and outside rims.
|
||||
// The band inside the rim, 1 wide and 2 high: (78 × 48 − 76 × 46) × 2; the bosses stop
|
||||
// at z = 14, well under it.
|
||||
let inside = (78.0 * 48.0 - 76.0 * 46.0) * 2.0;
|
||||
assert!(rel(volume(&mut s) - v0, inside) < 1e-6, "{}", volume(&mut s) - v0);
|
||||
// Bosses up to the rim, with ribs, against a wall; lips, grooves and outside rims. None
|
||||
// reaches the rim's bands, so each lip adds, and the groove (no gap) takes, its band: the
|
||||
// inside one (78 × 48 − 76 × 46) × 2, the outside one (80 × 50 − 78 × 48) × 2.
|
||||
let bosses = [
|
||||
json!({"position": [15, 15, 2], "diameter": 8, "height": 28, "hole_diameter": 3}),
|
||||
// Ribs out to the inner walls (15 − 4 − 9 = 2), and short of them.
|
||||
@@ -3127,13 +3130,14 @@ fn lip_after_boss() {
|
||||
json!({"position": [5.5, 25, 2], "diameter": 7, "height": 12, "hole_diameter": 2.5}),
|
||||
json!({"position": [40, 25, 2], "diameter": 8, "height": 20, "draft": "1 deg", "fillet": 1}),
|
||||
];
|
||||
let outside = (80.0 * 50.0 - 78.0 * 48.0) * 2.0;
|
||||
let lips = [
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2}),
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2, "type": "groove"}),
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2, "side": "outside"}),
|
||||
(json!({"face": [1, 25, 30], "width": 1, "height": 2}), inside),
|
||||
(json!({"face": [1, 25, 30], "width": 1, "height": 2, "type": "groove"}), -inside),
|
||||
(json!({"face": [1, 25, 30], "width": 1, "height": 2, "side": "outside"}), outside),
|
||||
];
|
||||
for (i, b) in bosses.iter().enumerate() {
|
||||
for (j, l) in lips.iter().enumerate() {
|
||||
for (j, (l, band)) in lips.iter().enumerate() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 80, "width": 50, "height": 30}));
|
||||
run(&mut s, "solid.shell", json!({"faces": [[40, 25, 30]], "thickness": 2}));
|
||||
@@ -3142,7 +3146,7 @@ fn lip_after_boss() {
|
||||
let v0 = volume(&mut s);
|
||||
let r = s.execute("plastic.lip", l);
|
||||
assert!(r.is_ok(), "boss {i} lip {j}: {r:?}");
|
||||
assert!((volume(&mut s) - v0).abs() > 1.0, "boss {i} lip {j}");
|
||||
assert!(rel(volume(&mut s) - v0, *band) < 1e-6, "boss {i} lip {j}: {} vs {band}", volume(&mut s) - v0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3168,16 +3172,24 @@ fn hole_as_deep_as_the_plate() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 50, "width": 25, "height": 10}));
|
||||
let v0 = volume(&mut s);
|
||||
// The depth is to the drill point's shoulder: the bore, radius 3, runs the plate's 10 and the
|
||||
// point is in the air below it.
|
||||
run(&mut s, "solid.hole", json!({"position": [25, 12.5, 10], "diameter": 6, "depth": 10, "type": "drilled"}));
|
||||
let v = volume(&mut s);
|
||||
assert!(v < v0 - PI * 9.0 * 9.0 && v > v0 - PI * 9.0 * 10.0 - 1.0, "{v0} {v}");
|
||||
// Other sizes and places, the defaults, and a tapped hole.
|
||||
for (i, p) in [
|
||||
json!({"position": [10, 10, 10], "diameter": 5, "depth": 10, "type": "drilled"}),
|
||||
json!({"position": [40, 15, 10], "diameter": 5, "depth": 10}),
|
||||
json!({"position": [12, 6, 10], "diameter": 8.5, "depth": 10}),
|
||||
json!({"position": [30, 7, 10], "thread": "M6", "depth": 10}),
|
||||
json!({"position": [20, 18, 10], "diameter": 4, "depth": 10, "tip_angle": 90}),
|
||||
assert!((v0 - v - PI * 9.0 * 10.0).abs() < 4e-7 * v0, "{v0} {v}");
|
||||
// Other sizes and places, the defaults, and a tapped hole: each a through bore of its drill,
|
||||
// 10 long. The 8.5 at (12, 6) overlaps the 5 at (10, 10) (√20 apart, under 2.5 + 4.25), so
|
||||
// it takes its bore less the lens they share, 10 long.
|
||||
let (r, q, d) = (2.5f64, 4.25f64, 20f64.sqrt());
|
||||
let lens = r * r * ((d * d + r * r - q * q) / (2.0 * d * r)).acos() + q * q * ((d * d + q * q - r * r) / (2.0 * d * q)).acos()
|
||||
- 0.5 * ((-d + r + q) * (d + r - q) * (d - r + q) * (d + r + q)).sqrt();
|
||||
for (i, (p, cut)) in [
|
||||
(json!({"position": [10, 10, 10], "diameter": 5, "depth": 10, "type": "drilled"}), PI * 6.25 * 10.0),
|
||||
(json!({"position": [40, 15, 10], "diameter": 5, "depth": 10}), PI * 6.25 * 10.0),
|
||||
(json!({"position": [12, 6, 10], "diameter": 8.5, "depth": 10}), (PI * q * q - lens) * 10.0),
|
||||
// M6 × 1: the tap maker's 5.0 drill.
|
||||
(json!({"position": [30, 7, 10], "thread": "M6", "depth": 10}), PI * 6.25 * 10.0),
|
||||
(json!({"position": [20, 18, 10], "diameter": 4, "depth": 10, "tip_angle": 90}), PI * 4.0 * 10.0),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
@@ -3185,7 +3197,8 @@ fn hole_as_deep_as_the_plate() {
|
||||
let before = volume(&mut s);
|
||||
let r = s.execute("solid.hole", &p);
|
||||
assert!(r.is_ok(), "{i} {p}: {r:?}");
|
||||
assert!(volume(&mut s) < before - 1.0, "{i} {p}");
|
||||
let v = volume(&mut s);
|
||||
assert!((before - v - cut).abs() < 4e-7 * before, "{i} {p}: {} vs {cut}", before - v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//! A hollow elbow: a tube lofted from round sections along an arc, minus a narrower tube lofted the
|
||||
//! same way (and running 5 mm past both ends, so the cut opens the ends).
|
||||
//!
|
||||
//! The boolean gave up with "no result" for some section counts and not for their neighbours: the
|
||||
//! points of the intersection curves lie on the seam between the two halves of a loft's circle,
|
||||
//! where truck's search for their parameters (from the previous point's) failed.
|
||||
|
||||
use std::f64::consts::PI;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// `sections` circles of radius `radius` centred on an arc of radius `path` turning `angle`
|
||||
/// (radians), in planes normal to the arc, lofted into the body `body`; `over` extends the
|
||||
/// sections past both ends along the tangent.
|
||||
fn tube(s: &mut Session, body: &str, radius: f64, path: f64, angle: f64, sections: usize, over: f64) {
|
||||
let mut stations: Vec<[f64; 4]> = (0..sections)
|
||||
.map(|i| {
|
||||
let t = angle * i as f64 / (sections - 1) as f64;
|
||||
[path * t.cos(), path * t.sin(), -t.sin(), t.cos()]
|
||||
})
|
||||
.collect();
|
||||
if over > 0.0 {
|
||||
let (a, b) = (stations[0], stations[sections - 1]);
|
||||
stations.insert(0, [a[0] - over * a[2], a[1] - over * a[3], a[2], a[3]]);
|
||||
stations.push([b[0] + over * b[2], b[1] + over * b[3], b[2], b[3]]);
|
||||
}
|
||||
let mut list = Vec::new();
|
||||
for (i, [x, y, tx, ty]) in stations.iter().enumerate() {
|
||||
let name = format!("{body}{i}");
|
||||
run(s, "sketch.create", json!({"plane": {"origin": [x, y, 0], "x_dir": [0, 0, 1], "y_dir": [ty, -tx, 0]}, "name": name}));
|
||||
run(s, "sketch.circle.center", json!({"center": [0, 0], "radius": radius}));
|
||||
run(s, "sketch.finish", json!({}));
|
||||
list.push(json!({"sketch": name}));
|
||||
}
|
||||
run(s, "solid.loft", json!({"sections": list, "operation": "new", "name": format!("Loft{body}"), "body_name": body}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hollow_elbow_cut_from_two_lofted_tubes() {
|
||||
let (path, outer, inner) = (100.0, 30.0, 18.0);
|
||||
// Each of these gave up in truck's `parameter boundary` step.
|
||||
for (degrees, sections) in [(60.0, 5), (60.0, 7), (90.0, 10), (120.0, 7), (120.0, 13)] {
|
||||
let angle = degrees * PI / 180.0;
|
||||
let mut s = Session::default();
|
||||
tube(&mut s, "Outer", outer, path, angle, sections, 0.0);
|
||||
tube(&mut s, "Inner", inner, path, angle, sections, 5.0);
|
||||
run(&mut s, "solid.combine", json!({"target": "Outer", "tools": ["Inner"], "operation": "cut", "name": "Hollow"}));
|
||||
assert_eq!(s.model.state().bodies.len(), 1, "{degrees} degrees, {sections} sections");
|
||||
let want = PI * (outer * outer - inner * inner) * path * angle;
|
||||
let got = volume(&mut s);
|
||||
assert!(rel(got, want) < 3e-3, "{degrees} degrees, {sections} sections: {got} vs {want}");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use std::f64::consts::PI;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{run, volume};
|
||||
use super::run;
|
||||
use crate::Session;
|
||||
use crate::fuzz;
|
||||
|
||||
@@ -174,37 +174,6 @@ fn shell_thicker_than_a_step_says_so() {
|
||||
assert!(e.to_string().contains("not supported yet"), "{e}");
|
||||
}
|
||||
|
||||
/// Panics inside the kernel are caught natively, but abort the web build (wasm can't unwind).
|
||||
/// Building the samples must not panic at all (the Plastic Enclosure's bosses used to, 8 times).
|
||||
#[test]
|
||||
fn samples_build_without_panics() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let me = std::thread::current().id();
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let c2 = count.clone();
|
||||
let prev = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
if std::thread::current().id() == me {
|
||||
c2.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
let _ = info;
|
||||
}));
|
||||
let mut failed = Vec::new();
|
||||
for sample in crate::sample::samples() {
|
||||
let mut s = Session::default();
|
||||
for c in (sample.script)()["commands"].as_array().into_iter().flatten() {
|
||||
let _ = s.execute(c["command"].as_str().unwrap_or(""), &c["params"]);
|
||||
}
|
||||
let n = count.swap(0, Ordering::SeqCst);
|
||||
if n > 0 {
|
||||
failed.push(format!("{}: {n} panic(s)", sample.name));
|
||||
}
|
||||
}
|
||||
std::panic::set_hook(prev);
|
||||
assert!(failed.is_empty(), "{failed:?}");
|
||||
}
|
||||
|
||||
fn total_volume(s: &Session) -> f64 {
|
||||
s.model.state().bodies.iter().map(|b| solidcraft_kernel::measure(&b.body).map(|m| m.volume).unwrap_or(0.0)).sum()
|
||||
}
|
||||
@@ -366,74 +335,6 @@ fn fixed_seeds_run_clean() {
|
||||
|
||||
const FIXED_SEEDS: &[u64] = &[3, 5, 11, 16, 21, 29, 33, 35];
|
||||
|
||||
/// A drilled hole as deep as the plate: the drill point breaks through the bottom.
|
||||
#[test]
|
||||
fn hole_as_deep_as_the_plate() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 50, "width": 25, "height": 10}));
|
||||
let v0 = volume(&mut s);
|
||||
run(&mut s, "solid.hole", json!({"position": [25, 12.5, 10], "diameter": 6, "depth": 10, "type": "drilled"}));
|
||||
let v = volume(&mut s);
|
||||
assert!(v < v0 - PI * 9.0 * 9.0 && v > v0 - PI * 9.0 * 10.0 - 1.0, "{v0} {v}");
|
||||
// Other sizes and places, the defaults, and a tapped hole.
|
||||
for (i, p) in [
|
||||
json!({"position": [10, 10, 10], "diameter": 5, "depth": 10, "type": "drilled"}),
|
||||
json!({"position": [40, 15, 10], "diameter": 5, "depth": 10}),
|
||||
json!({"position": [12, 6, 10], "diameter": 8.5, "depth": 10}),
|
||||
json!({"position": [30, 7, 10], "thread": "M6", "depth": 10}),
|
||||
json!({"position": [20, 18, 10], "diameter": 4, "depth": 10, "tip_angle": 90}),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let before = volume(&mut s);
|
||||
let r = s.execute("solid.hole", &p);
|
||||
assert!(r.is_ok(), "{i} {p}: {r:?}");
|
||||
assert!(volume(&mut s) < before - 1.0, "{i} {p}");
|
||||
}
|
||||
}
|
||||
|
||||
/// An enclosure built in the usual order: shell, bosses, then the lip on the rim.
|
||||
#[test]
|
||||
fn lip_after_boss() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 80, "width": 50, "height": 30}));
|
||||
run(&mut s, "solid.shell", json!({"faces": [[40, 25, 30]], "thickness": 2}));
|
||||
run(&mut s, "plastic.boss", json!({"position": [10, 10, 2], "diameter": 7, "height": 12, "hole_diameter": 2.5}));
|
||||
run(&mut s, "plastic.boss", json!({"position": [70, 40, 2], "diameter": 7, "height": 12, "hole_diameter": 2.5}));
|
||||
let v0 = volume(&mut s);
|
||||
run(&mut s, "plastic.lip", json!({"face": [1, 25, 30], "width": 1, "height": 2}));
|
||||
let v = volume(&mut s);
|
||||
assert!(v > v0 + 1.0, "{v0} {v}");
|
||||
// Bosses up to the rim, with ribs, against a wall; lips, grooves and outside rims.
|
||||
let bosses = [
|
||||
json!({"position": [15, 15, 2], "diameter": 8, "height": 28, "hole_diameter": 3}),
|
||||
// Ribs out to the inner walls (15 − 4 − 9 = 2), and short of them.
|
||||
json!({"position": [15, 15, 2], "diameter": 8, "height": 12, "ribs": 4, "rib_thickness": 1.5, "rib_length": 9}),
|
||||
json!({"position": [15, 15, 2], "diameter": 8, "height": 12, "ribs": 4, "rib_thickness": 1.5, "rib_length": 6}),
|
||||
json!({"position": [5.5, 25, 2], "diameter": 7, "height": 12, "hole_diameter": 2.5}),
|
||||
json!({"position": [40, 25, 2], "diameter": 8, "height": 20, "draft": "1 deg", "fillet": 1}),
|
||||
];
|
||||
let lips = [
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2}),
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2, "type": "groove"}),
|
||||
json!({"face": [1, 25, 30], "width": 1, "height": 2, "side": "outside"}),
|
||||
];
|
||||
for (i, b) in bosses.iter().enumerate() {
|
||||
for (j, l) in lips.iter().enumerate() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 80, "width": 50, "height": 30}));
|
||||
run(&mut s, "solid.shell", json!({"faces": [[40, 25, 30]], "thickness": 2}));
|
||||
let r = s.execute("plastic.boss", b);
|
||||
assert!(r.is_ok(), "boss {i}: {r:?}");
|
||||
let v0 = volume(&mut s);
|
||||
let r = s.execute("plastic.lip", l);
|
||||
assert!(r.is_ok(), "boss {i} lip {j}: {r:?}");
|
||||
assert!((volume(&mut s) - v0).abs() > 1.0, "boss {i} lip {j}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A lip, a groove and an outside lip on the rim of a rounded, shelled enclosure (#29: the
|
||||
/// lip's walls continue the shell's walls, which a boolean join couldn't do).
|
||||
#[test]
|
||||
|
||||
@@ -46,6 +46,13 @@ fn shell_box_on_box_overhanging_saddle_corner() {
|
||||
let mut s = box_on_box(2.5);
|
||||
run(&mut s, "solid.shell", json!({"faces": [[7.5, 17.5, 38.75]], "thickness": 1.5}));
|
||||
sound(&s);
|
||||
// The bottom closed and the top box's left face x = 7.5 open, so the cavity in the top box
|
||||
// runs out to it: [1.5, 23.5] × [1.5, 16] × [1.5, 33.5] in the lower box,
|
||||
// [7.5, 21] × [1.5, 16] × [33.5, 41] over it and [7.5, 21] × [16, 18.5] × [36.5, 41] in the
|
||||
// overhang, out of the solid's 25 × 17.5 × 35 + 15 × 20 × 7.5.
|
||||
let want = 25.0 * 17.5 * 35.0 + 15.0 * 20.0 * 7.5 - 22.0 * 14.5 * 32.0 - 13.5 * 14.5 * 7.5 - 13.5 * 2.5 * 4.5;
|
||||
let got = volume(&s);
|
||||
assert!((got - want).abs() < 1e-6 * want, "shell volume {got}, want {want}");
|
||||
}
|
||||
|
||||
/// The same saddle corner with the bottom open: every face round the corner moves, and the
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
//! A board-like assembly for issue #883, the worst case for a large STEP import: every
|
||||
//! component is its own product with a package body and its own pins (nothing shared).
|
||||
//!
|
||||
//! ```sh
|
||||
//! scripts/fetch-smlib.sh
|
||||
//! SOLIDCRAFT_STEP_PCB_COMPONENTS=600 SOLIDCRAFT_STEP_PCB_PINS=15 \
|
||||
//! cargo run --release -p solidcraft-kernel --features smlib --example step_board_fixture -- board.step
|
||||
//! ```
|
||||
//!
|
||||
//! 600 components of 15 pins give 52 MB. The defaults are 500 and 16; the path defaults to
|
||||
//! `board.step`.
|
||||
|
||||
#[cfg(not(feature = "smlib"))]
|
||||
fn main() {
|
||||
eprintln!("step_board_fixture needs SMLib: run scripts/fetch-smlib.sh, then add --features smlib");
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
#[cfg(feature = "smlib")]
|
||||
fn main() {
|
||||
if let Err(e) = run::main() {
|
||||
eprintln!("step_board_fixture: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "smlib")]
|
||||
mod run {
|
||||
use solidcraft_geom::Vec3;
|
||||
use solidcraft_kernel::{Body, ExportBody, ExportProduct, StepHeader, box_solid, cylinder, fillet, step_export_products};
|
||||
|
||||
/// A count from `SOLIDCRAFT_<name>`, or `default` when it is unset.
|
||||
fn count(name: &str, default: usize) -> Result<usize, String> {
|
||||
solidcraft_geom::env::var(name).map_or(Ok(default), |s| s.parse().map_err(|e| format!("SOLIDCRAFT_{name}: {e}")))
|
||||
}
|
||||
|
||||
/// A package: a box with its vertical edges and then its top edges rounded (left sharp where
|
||||
/// a round does not build).
|
||||
fn package(w: f64, d: f64, h: f64) -> Result<Body, String> {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(w, d, h)).map_err(|e| e.to_string())?;
|
||||
let vertical = [Vec3::new(0.0, 0.0, h / 2.0), Vec3::new(w, 0.0, h / 2.0), Vec3::new(w, d, h / 2.0), Vec3::new(0.0, d, h / 2.0)];
|
||||
let top = [Vec3::new(w / 2.0, 0.0, h), Vec3::new(w, d / 2.0, h), Vec3::new(w / 2.0, d, h), Vec3::new(0.0, d / 2.0, h)];
|
||||
let b = fillet(&b, &vertical, 0.3).unwrap_or(b);
|
||||
Ok(fillet(&b, &top, 0.1).unwrap_or(b))
|
||||
}
|
||||
|
||||
pub fn main() -> Result<(), String> {
|
||||
let components = count("STEP_PCB_COMPONENTS", 500)?;
|
||||
let pins = count("STEP_PCB_PINS", 16)?;
|
||||
let path = std::env::args().nth(1).unwrap_or_else(|| "board.step".into());
|
||||
let mut owned: Vec<Vec<Body>> = Vec::new();
|
||||
for c in 0..components {
|
||||
let w = 4.0 + (c % 7) as f64 * 0.37;
|
||||
let d = 3.0 + (c % 5) as f64 * 0.29;
|
||||
let mut bodies = vec![package(w, d, 1.2 + (c % 3) as f64 * 0.1)?];
|
||||
for p in 0..pins {
|
||||
let side = if p % 2 == 0 { -0.6 } else { d + 0.6 };
|
||||
let x = 0.3 + (p / 2) as f64 * (w - 0.6) / (pins / 2).max(1) as f64 + c as f64 * 1e-4;
|
||||
bodies.push(cylinder(Vec3::new(x, side, -1.5), Vec3::Z, 0.25, 2.0 + (p % 3) as f64 * 0.01).map_err(|e| e.to_string())?);
|
||||
}
|
||||
owned.push(bodies);
|
||||
}
|
||||
let mut products: Vec<ExportProduct> = owned
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(c, bodies)| ExportProduct {
|
||||
name: format!("U{c}"),
|
||||
bodies: bodies
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(k, b)| ExportBody { name: format!("U{c}_{k}"), body: b, color: Some([0.2, 0.2, 0.2]) })
|
||||
.collect(),
|
||||
children: Vec::new(),
|
||||
})
|
||||
.collect();
|
||||
let side = (components as f64).sqrt().ceil() as usize;
|
||||
let children = (0..components)
|
||||
.map(|c| {
|
||||
let (x, y) = ((c % side) as f64 * 12.0, (c / side) as f64 * 10.0);
|
||||
(c, [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [x, y, 1.6, 1.0]], format!("U{c}"))
|
||||
})
|
||||
.collect();
|
||||
products.push(ExportProduct { name: "Board".into(), bodies: Vec::new(), children });
|
||||
let root = products.len() - 1;
|
||||
let header = StepHeader { file_name: "board.step".into(), ..Default::default() };
|
||||
let text = step_export_products(&products, root, &header).map_err(|e| e.to_string())?;
|
||||
std::fs::write(&path, &text).map_err(|e| format!("{path}: {e}"))?;
|
||||
println!("wrote {path}: {} bytes, {components} components", text.len());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1287,10 +1287,11 @@ impl Body {
|
||||
}
|
||||
|
||||
/// Edges `indices` (record edge indices) in `plane`'s coordinates, exactly: lines, circular
|
||||
/// arcs, and free-form curves as the Bézier spans they are, 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<solidcraft_geom::Seg2>>> {
|
||||
/// arcs, single free-form segments, and a free-form curve of several spans as the one
|
||||
/// 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>>> {
|
||||
if self.is_mesh() {
|
||||
return vec![None; indices.len()];
|
||||
}
|
||||
@@ -1299,7 +1300,7 @@ impl Body {
|
||||
.iter()
|
||||
.map(|i| {
|
||||
let mut work = 262_144usize;
|
||||
crate::prism_curve::Run::of(&self.record, *i, true).and_then(|run| crate::prism_curve::projected(&run, plane, tol, &mut work))
|
||||
crate::prism_curve::Run::of(&self.record, *i, true).and_then(|run| crate::prism_curve::projected_curves(&run, plane, tol, &mut work))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -446,46 +446,19 @@ mod smlib {
|
||||
crate::sphere(Vec3::new(10.0, 10.0, 10.0), 4.0).unwrap(),
|
||||
crate::torus(Vec3::new(0.0, 0.0, 0.0), 10.0, 2.0).unwrap(),
|
||||
];
|
||||
// SMLib imports a record's faces and edges in the record's order, and the record is
|
||||
// already canonical: SMLib's face and edge i are the record's i (the order is the
|
||||
// identity, or empty, which says the same), with no edge split into pieces.
|
||||
for (i, b) in bodies.iter().enumerate() {
|
||||
let (_, order) = crate::native::smlib_body_ordered(b).unwrap();
|
||||
assert!(order.is_some(), "body {i}");
|
||||
let order = order.unwrap_or_else(|| panic!("body {i}: no order"));
|
||||
let identity = |to: &[usize], n: usize| to.is_empty() || to.iter().copied().eq(0..n);
|
||||
assert!(identity(&order.faces, b.face_count()), "body {i}: faces {:?}", order.faces);
|
||||
assert!(identity(&order.edges, b.edge_count()), "body {i}: edges {:?}", order.edges);
|
||||
assert!(order.pieces.is_empty(), "body {i}: {:?}", order.pieces);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn box_minus_sphere() {
|
||||
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
|
||||
let b = crate::sphere(Vec3::new(10.0, 10.0, 10.0), 4.0).unwrap();
|
||||
let r = through_smlib(&a, &b, BoolOp::Cut);
|
||||
let h = verified(&r, &[&a, &b], 0.02);
|
||||
// The three notched box faces, the three untouched, and the sphere's patches inside.
|
||||
assert_eq!(changes(h)[..2].iter().sum::<usize>() + changes(h)[2], h.faces.len(), "{}", show(h));
|
||||
assert!(
|
||||
meets(h).iter().all(|(x, y)| matches!((x, y), (FaceOrigin::Face { operand: 0, .. }, FaceOrigin::Face { operand: 1, .. }))),
|
||||
"{}",
|
||||
show(h)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn box_minus_cylinder() {
|
||||
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
|
||||
let b = crate::cylinder(Vec3::new(5.0, 5.0, -1.0), Vec3::Z, 2.0, 12.0).unwrap();
|
||||
let r = through_smlib(&a, &b, BoolOp::Cut);
|
||||
let h = verified(&r, &[&a, &b], 0.01);
|
||||
assert!(from(h, face(0, 0)).len() + from(h, face(0, 1)).len() >= 1, "{}", show(h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn box_union_box() {
|
||||
let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);
|
||||
let b = boxed(5.0, 2.0, 2.0, 15.0, 8.0, 8.0);
|
||||
let r = through_smlib(&a, &b, BoolOp::Union);
|
||||
let h = verified(&r, &[&a, &b], 0.02);
|
||||
assert_eq!(h.faces.len(), 11, "{}", show(h));
|
||||
assert_eq!(meets(h).len(), 4, "{}", show(h));
|
||||
}
|
||||
|
||||
/// Cubes sharing an edge, and cubes sharing a vertex: SMLib's union touches itself there;
|
||||
/// it comes back as two closed shells, the shared edge and vertices split into one copy per
|
||||
/// cube, each copy with its edge's history (verified against the geometry). The copies say
|
||||
|
||||
@@ -92,7 +92,11 @@ fn chamfers_crossing_each_other_are_refused() {
|
||||
// Below half the width both build.
|
||||
let b = crate::chamfer(&rib, &edges, 1.5).unwrap();
|
||||
assert!((b.volume_at(0.01).unwrap() - (3200.0 - 2.0 * 0.5 * 1.5 * 1.5 * 40.0)).abs() < 1e-6);
|
||||
assert!(crate::fillet(&rib, &edges, 1.5).is_ok());
|
||||
// Two rounds of radius 1.5 along 40: each removes (1 − π/4)·1.5² of section.
|
||||
let b = crate::fillet(&rib, &edges, 1.5).unwrap();
|
||||
let want = 3200.0 - 2.0 * (1.0 - std::f64::consts::FRAC_PI_4) * 2.25 * 40.0;
|
||||
let v = crate::measure(&b).unwrap().volume;
|
||||
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
|
||||
}
|
||||
|
||||
/// Edges meeting at a corner mitre: their chamfers overlap there and are not refused for it.
|
||||
@@ -100,6 +104,14 @@ fn chamfers_crossing_each_other_are_refused() {
|
||||
fn chamfers_meeting_at_a_corner_still_build() {
|
||||
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(20.0, 20.0, 20.0)).unwrap();
|
||||
let edges = [Vec3::new(10.0, 0.0, 20.0), Vec3::new(20.0, 10.0, 20.0), Vec3::new(10.0, 20.0, 20.0), Vec3::new(0.0, 10.0, 20.0)];
|
||||
assert!(crate::chamfer(&b, &edges, 5.0).is_ok());
|
||||
assert!(crate::fillet(&b, &edges, 5.0).is_ok());
|
||||
// The chamfers leave the 20 x 20 x 15 block under a frustum from 20 x 20 to 10 x 10, 5 high:
|
||||
// 6000 + (5/3)(400 + 100 + √(400·100)).
|
||||
let v = crate::measure(&crate::chamfer(&b, &edges, 5.0).unwrap()).unwrap().volume;
|
||||
let want = 6000.0 + 5.0 / 3.0 * (400.0 + 100.0 + 200.0);
|
||||
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
|
||||
// The rounds: (1 − π/4)·25 of section along each edge's 10 mm between the corners, and in each
|
||||
// 5 mm corner cube the two cylinders' intersection is kept, ∫₀⁵ (25 − w²) dw = 250/3 of 125.
|
||||
let v = crate::measure(&crate::fillet(&b, &edges, 5.0).unwrap()).unwrap().volume;
|
||||
let want = 8000.0 - 4.0 * (1.0 - std::f64::consts::FRAC_PI_4) * 25.0 * 10.0 - 4.0 * (125.0 - 250.0 / 3.0);
|
||||
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
|
||||
}
|
||||
@@ -210,6 +210,7 @@ pub use point_path::{
|
||||
pub use polybool::faceted_boolean;
|
||||
pub use polyhedron::{HalfSpace, convex_polyhedron, draft, offset_faces, shell};
|
||||
pub use prism::{PLANAR_FIT_TOL, extrude_planar_regions, planar_regions_boolean};
|
||||
pub use prism_curve::{PlanarPiece, PlanarSpline};
|
||||
pub use prism_measure::{PrismSection, certified_prism_equivalent, certified_prism_section};
|
||||
pub use repair::{Hole, RebuiltFace, RefusedFace, RepairOptions, RepairReport, SewnGap, repair};
|
||||
pub use sew::{EdgeSpec, FaceSpec, SurfSpec, sew, sew_touching};
|
||||
|
||||
@@ -55,6 +55,10 @@ fn face_at(b: &Body, p: Vec3) -> usize {
|
||||
(0..b.face_count()).min_by(|x, y| to_face(&m, *x, p).total_cmp(&to_face(&m, *y, p))).unwrap()
|
||||
}
|
||||
|
||||
fn volume(b: &Body) -> f64 {
|
||||
crate::measure(b).unwrap().volume
|
||||
}
|
||||
|
||||
fn cube() -> Body {
|
||||
box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap()
|
||||
}
|
||||
@@ -227,6 +231,8 @@ fn shell_lines_the_walls_with_offsets() {
|
||||
let b = cube();
|
||||
let top = Vec3::new(20.0, 15.0, 20.0);
|
||||
let r = crate::shell(&b, &[top], 2.0).unwrap();
|
||||
// The cavity is 36 x 26 x 18 (the floor 2 thick, the top open).
|
||||
assert!((volume(&r) - (24000.0 - 36.0 * 26.0 * 18.0)).abs() < 1e-3, "{}", volume(&r));
|
||||
let h = verified(&r, &b, reach(2.0));
|
||||
// Five inner walls, each an offset of the face it lines; the top is left as a rim.
|
||||
let top = face_at(&b, top);
|
||||
@@ -236,7 +242,7 @@ fn shell_lines_the_walls_with_offsets() {
|
||||
assert_eq!(h.faces[walls[0]].change, Change::Generated);
|
||||
}
|
||||
assert!(with(h, &[FaceOrigin::Offset { operand: 0, face: top }]).is_empty());
|
||||
assert_eq!(changes(h), [0, 6, 0, 0, 5]);
|
||||
assert_eq!(changes(h), [0, 6, 0, 0, 5], "{h:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -306,10 +312,17 @@ fn offset_moves_a_face() {
|
||||
let b = ell();
|
||||
let top = Vec3::new(5.0, 5.0, 20.0);
|
||||
let r = crate::offset_faces(&b, &[top], 3.0).unwrap();
|
||||
// The L's plan is 40 x 15 + 15 x 15 = 825; 23 high.
|
||||
assert!((volume(&r) - 825.0 * 23.0).abs() < 1e-3, "{}", volume(&r));
|
||||
let h = verified(&r, &b, Reach { made: 0.0, moved: 3.0 * 1.1 });
|
||||
assert_eq!(h.faces.len(), b.face_count());
|
||||
assert_eq!(with(h, &[face(face_at(&b, top))]).len(), 1);
|
||||
let moved = with(h, &[face(face_at(&b, top))]);
|
||||
assert_eq!(moved.len(), 1);
|
||||
assert_eq!(h.faces[moved[0]].change, Change::Modified);
|
||||
assert!(h.edges.iter().all(|e| matches!(e.origins.as_slice(), [EdgeOrigin::Edge { .. }])));
|
||||
// Into the body by its whole height: nothing is left behind the face.
|
||||
let e = crate::offset_faces(&b, &[top], -20.0).unwrap_err();
|
||||
assert!(e.to_string().contains("no room"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -403,10 +416,24 @@ fn surfaces_keep_their_faces() {
|
||||
fn thicken_offsets_the_surface() {
|
||||
let s = crate::patch_region(&Plane::XY, &Region2 { outer: square(0.0, 0.0, 10.0, 10.0), holes: vec![] }).unwrap();
|
||||
let t = crate::thicken(&s, 2.0, false).unwrap();
|
||||
assert!((volume(&t) - 200.0).abs() < 1e-6, "{}", volume(&t));
|
||||
// Along the sheet's normal (+Z).
|
||||
let m = t.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
|
||||
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
|
||||
assert!(lo.abs() < 1e-9 && (hi - 2.0).abs() < 1e-9, "z {lo}..{hi}");
|
||||
let h = verified(&t, &s, reach(2.0));
|
||||
assert_eq!(with(h, &[face(0)]).len(), 1);
|
||||
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1);
|
||||
assert_eq!(blends(h).len(), 4);
|
||||
assert_eq!(with(h, &[face(0)]).len(), 1, "{h:?}");
|
||||
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1, "{h:?}");
|
||||
assert_eq!(blends(h).len(), 4, "{h:?}");
|
||||
let both = crate::thicken(&s, 2.0, true).unwrap();
|
||||
let m = both.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
|
||||
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
|
||||
assert!((lo + 1.0).abs() < 1e-9 && (hi - 1.0).abs() < 1e-9, "z {lo}..{hi}");
|
||||
let h = verified(&both, &s, reach(1.0));
|
||||
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 2, "{h:?}");
|
||||
assert_eq!(blends(h).len(), 4, "{h:?}");
|
||||
let against = crate::thicken(&s, -2.0, false).unwrap();
|
||||
assert!((volume(&against) - 200.0).abs() < 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -484,9 +511,9 @@ fn chamfer_after_box_cuts() {
|
||||
for (name, cut, tool) in box_cuts_of(&b) {
|
||||
let r = crate::chamfer(&cut, &[at], 2.0).unwrap();
|
||||
let h = verified(&r, &cut, reach(2.0 * 1.5));
|
||||
// On the painted block the chamfer face keeps the boundaries the cut left.
|
||||
let faces = with(h, &[edge(edge_at(&cut, at))]).len();
|
||||
assert!(if painted { faces >= 1 } else { faces == 1 }, "{name} (painted: {painted}): {h:?}");
|
||||
// The picked edge is one edge of the cut body on either block (its round is one face,
|
||||
// `fillet_after_box_cuts`), so its chamfer is one face too.
|
||||
assert_eq!(with(h, &[edge(edge_at(&cut, at))]).len(), 1, "{name} (painted: {painted}): {h:?}");
|
||||
let mut through = h.clone();
|
||||
through.substitute(0, cut.history().unwrap()).unwrap();
|
||||
through.check(&r, &[&b, &tool]).unwrap();
|
||||
@@ -494,44 +521,13 @@ fn chamfer_after_box_cuts() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shell, offset faces and thicken through SMLib (`crate::offset_backend`), their histories
|
||||
/// checked against the geometry as truck's are, and their numbers against the analytic ones.
|
||||
/// Shell, offset faces and draft straight through `crate::offset_backend`: refusals, and their
|
||||
/// histories checked against the geometry and their numbers against the analytic ones.
|
||||
#[cfg(feature = "smlib")]
|
||||
mod smlib {
|
||||
use super::*;
|
||||
use crate::offset_backend;
|
||||
|
||||
fn volume(b: &Body) -> f64 {
|
||||
crate::measure(b).unwrap().volume
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_lines_the_walls_with_offsets() {
|
||||
let b = cube();
|
||||
let top = Vec3::new(20.0, 15.0, 20.0);
|
||||
let r = offset_backend::shell(&b, &[top], 2.0).unwrap();
|
||||
// The cavity is 36 x 26 x 18 (the floor 2 thick, the top open).
|
||||
assert!((volume(&r) - (24000.0 - 36.0 * 26.0 * 18.0)).abs() < 1e-3, "{}", volume(&r));
|
||||
let h = verified(&r, &b, reach(2.0));
|
||||
let top = face_at(&b, top);
|
||||
for f in (0..6).filter(|f| *f != top) {
|
||||
let walls = with(h, &[FaceOrigin::Offset { operand: 0, face: f }]);
|
||||
assert_eq!(walls.len(), 1, "{h:?}");
|
||||
assert_eq!(h.faces[walls[0]].change, Change::Generated);
|
||||
}
|
||||
assert!(with(h, &[FaceOrigin::Offset { operand: 0, face: top }]).is_empty());
|
||||
assert_eq!(changes(h), [0, 6, 0, 0, 5], "{h:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_of_a_body_that_is_not_convex() {
|
||||
let b = ell();
|
||||
let r = offset_backend::shell(&b, &[Vec3::new(5.0, 5.0, 20.0)], 2.0).unwrap();
|
||||
let h = verified(&r, &b, reach(2.0 * 1.5));
|
||||
let offsets = h.faces.iter().filter(|f| matches!(f.origins.as_slice(), [FaceOrigin::Offset { .. }])).count();
|
||||
assert_eq!(offsets, 7, "{h:?}");
|
||||
}
|
||||
|
||||
/// tangency-labs/solidcore#380: a closed shell whose wall leaves no room inside the body is
|
||||
/// refused before SMLib's offset sees it, by the body's own inradius (the L's legs are 15
|
||||
/// wide, the largest ball fits at the inner corner: 15 * sqrt(2) / (1 + sqrt(2)) = 8.79),
|
||||
@@ -573,25 +569,6 @@ mod smlib {
|
||||
assert!(e.contains("the 1.5 mm walls would meet along a line"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offset_moves_a_face() {
|
||||
let b = ell();
|
||||
let top = Vec3::new(5.0, 5.0, 20.0);
|
||||
let healed = crate::boolean_record::healed(&b).unwrap();
|
||||
let chosen = [face_at(&healed, top)];
|
||||
let r = offset_backend::offset_faces(&healed, &chosen, 3.0).unwrap();
|
||||
// The L's plan is 40 x 15 + 15 x 15 = 825; 23 high.
|
||||
assert!((volume(&r) - 825.0 * 23.0).abs() < 1e-3, "{}", volume(&r));
|
||||
let h = verified(&r, &healed, Reach { made: 0.0, moved: 3.0 * 1.1 });
|
||||
assert_eq!(h.faces.len(), healed.face_count());
|
||||
let moved = with(h, &[face(chosen[0])]);
|
||||
assert_eq!(moved.len(), 1);
|
||||
assert_eq!(h.faces[moved[0]].change, Change::Modified);
|
||||
// Into the body by its whole height: nothing is left behind the face.
|
||||
let e = offset_backend::offset_faces(&healed, &chosen, -20.0).unwrap_err();
|
||||
assert!(e.to_string().contains("no room"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draft_tilts_a_side_and_keeps_its_name() {
|
||||
let b = cube();
|
||||
@@ -616,28 +593,4 @@ mod smlib {
|
||||
let e = offset_backend::draft(&b, &[Vec3::new(20.0, 15.0, 20.0)], &Plane::XY, Vec3::Z, 5.0 * deg).unwrap_err();
|
||||
assert!(e.to_string().contains("not supported yet"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thicken_offsets_the_surface() {
|
||||
let s = crate::patch_region(&Plane::XY, &Region2 { outer: square(0.0, 0.0, 10.0, 10.0), holes: vec![] }).unwrap();
|
||||
let t = offset_backend::thicken(&s, 2.0, false).unwrap();
|
||||
assert!((volume(&t) - 200.0).abs() < 1e-6, "{}", volume(&t));
|
||||
// Along the sheet's normal (+Z).
|
||||
let m = t.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
|
||||
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
|
||||
assert!(lo.abs() < 1e-9 && (hi - 2.0).abs() < 1e-9, "z {lo}..{hi}");
|
||||
let h = verified(&t, &s, reach(2.0));
|
||||
assert_eq!(with(h, &[face(0)]).len(), 1, "{h:?}");
|
||||
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 1, "{h:?}");
|
||||
assert_eq!(blends(h).len(), 4, "{h:?}");
|
||||
let both = offset_backend::thicken(&s, 2.0, true).unwrap();
|
||||
let m = both.mesh(&crate::MeshTolerance::chord(TOL)).unwrap();
|
||||
let (lo, hi) = m.positions.iter().fold((f64::MAX, f64::MIN), |(lo, hi), p| (lo.min(p.z), hi.max(p.z)));
|
||||
assert!((lo + 1.0).abs() < 1e-9 && (hi - 1.0).abs() < 1e-9, "z {lo}..{hi}");
|
||||
let h = verified(&both, &s, reach(1.0));
|
||||
assert_eq!(with(h, &[FaceOrigin::Offset { operand: 0, face: 0 }]).len(), 2, "{h:?}");
|
||||
assert_eq!(blends(h).len(), 4, "{h:?}");
|
||||
let against = offset_backend::thicken(&s, -2.0, false).unwrap();
|
||||
assert!((volume(&against) - 200.0).abs() < 1e-6);
|
||||
}
|
||||
}
|
||||
@@ -299,14 +299,146 @@ pub(crate) fn segment(run: &Run, plane: &Plane, tol: f64, work: &mut usize) -> O
|
||||
read(run, plane, tol, work, false)
|
||||
}
|
||||
|
||||
/// `run` in `plane` exactly, for a sketch to project it: as [`segment`], and a curve of several
|
||||
/// Bézier spans (a chain of a font's curves, a spline through points) as one segment per span,
|
||||
/// each the line, conic or Bézier it is. `None` when the edge doesn't lie in a plane parallel to
|
||||
/// `plane` or isn't read exactly.
|
||||
/// `run` in `plane` exactly as segments: as [`segment`], and a curve of several Bézier spans
|
||||
/// (a chain of a font's curves, a spline through points) as one segment per span, each the
|
||||
/// line, conic or Bézier it is, for a planar region's outline. `None` when the edge doesn't lie
|
||||
/// in a plane parallel to `plane` or isn't read exactly.
|
||||
pub(crate) fn projected(run: &Run, plane: &Plane, tol: f64, work: &mut usize) -> Option<Vec<Seg2>> {
|
||||
read(run, plane, tol, work, true)
|
||||
}
|
||||
|
||||
/// A free-form curve of several Bézier spans in a plane, as the one B-spline it is: its degree,
|
||||
/// clamped knots, control points in the plane's coordinates and weights (none: a polynomial
|
||||
/// B-spline). Its first and last control points are its ends.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PlanarSpline {
|
||||
pub degree: usize,
|
||||
pub knots: Vec<f64>,
|
||||
pub points: Vec<Vec2>,
|
||||
pub weights: Vec<f64>,
|
||||
}
|
||||
|
||||
/// One piece of an edge read exactly in a plane: a line, arc or single free-form segment, or a
|
||||
/// free-form curve of several spans as one [`PlanarSpline`].
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PlanarPiece {
|
||||
Seg(Seg2),
|
||||
Spline(PlanarSpline),
|
||||
}
|
||||
|
||||
/// `run` in `plane` exactly, for a sketch to project it: as [`segment`], and a curve of several
|
||||
/// Bézier spans (a spline edge, an elliptical arc past a quarter turn, a chain of a font's
|
||||
/// curves) as the one B-spline it is, its knots and weights its own. `None` when the edge
|
||||
/// doesn't lie in a plane parallel to `plane` or isn't read exactly.
|
||||
pub(crate) fn projected_curves(run: &Run, plane: &Plane, tol: f64, work: &mut usize) -> Option<Vec<PlanarPiece>> {
|
||||
if let Some(segs) = read(run, plane, tol, work, false) {
|
||||
return Some(segs.into_iter().map(PlanarPiece::Seg).collect());
|
||||
}
|
||||
one_spline(run, plane, tol, work).map(|s| vec![PlanarPiece::Spline(s)])
|
||||
}
|
||||
|
||||
/// `run`'s spline (or ellipse) over its interval, in the direction it runs, as one clamped
|
||||
/// B-spline in `plane`: the piece of the curve between the interval's ends (Boehm insertion,
|
||||
/// exact up to rounding), its control points read in the plane. `None` when a control point lies
|
||||
/// off the level of the curve's start (the curve is not in a plane parallel to `plane`), the
|
||||
/// ends miss the run's ends, or the work budget runs out.
|
||||
fn one_spline(run: &Run, plane: &Plane, tol: f64, work: &mut usize) -> Option<PlanarSpline> {
|
||||
if !tol.is_finite() || tol <= 0. || run.interval[1] <= run.interval[0] {
|
||||
return None;
|
||||
}
|
||||
charge(work, 1)?;
|
||||
let [t0, t1] = run.interval;
|
||||
let clamped = |knots: &[f64], ctrl: Vec<HPoint>, work: &mut usize| -> Option<(usize, Vec<f64>, Vec<HPoint>)> {
|
||||
let degree = knots.len().checked_sub(ctrl.len() + 1)?;
|
||||
if !(1..=MAX_DEGREE).contains(°ree) || ctrl.len() > MAX_CONTROLS || knots.len() > 8192 {
|
||||
return None;
|
||||
}
|
||||
if knots.iter().any(|t| !t.is_finite()) || knots.windows(2).any(|w| w[1] < w[0]) || ctrl.iter().any(|p| !p.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
charge(work, ctrl.len().checked_mul(degree + 1)?.checked_mul(2)?)?;
|
||||
let (k, c) = bspline::segment(degree, knots, &ctrl, t0, t1).ok()?;
|
||||
Some((degree, k, c))
|
||||
};
|
||||
// In the curve's own direction, then the way the run goes.
|
||||
let (degree, knots, ctrl) = match run.curve {
|
||||
Curve::Spline { knots, points } => along(run, clamped(knots, points.iter().map(|p| HPoint::weighted(v3(*p), 1.0)).collect(), work)?)?,
|
||||
Curve::RationalSpline { knots, homogeneous } => {
|
||||
along(run, clamped(knots, homogeneous.iter().map(|p| HPoint { x: p[0], y: p[1], z: p[2], w: p[3] }).collect(), work)?)?
|
||||
}
|
||||
// Rational quadratic spans, already the way the run goes, joined: each joint knot twice.
|
||||
Curve::Ellipse { .. } => {
|
||||
let spans = spans_of(run, work)?;
|
||||
let mut knots = vec![0.0; 3];
|
||||
let mut ctrl: Vec<HPoint> = Vec::new();
|
||||
for (i, span) in spans.iter().enumerate() {
|
||||
let [p0, p1, p2] = span.as_slice() else { return None };
|
||||
if let Some(last) = ctrl.last() {
|
||||
if (last.w - p0.w).abs() > 1e-12 * last.w.abs().max(p0.w.abs()) {
|
||||
return None;
|
||||
}
|
||||
} else {
|
||||
ctrl.push(*p0);
|
||||
}
|
||||
ctrl.extend([*p1, *p2]);
|
||||
knots.extend([(i + 1) as f64; 2]);
|
||||
}
|
||||
knots.push(spans.len() as f64);
|
||||
(2, knots, ctrl)
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
let max_w = ctrl.iter().map(|p| p.w).fold(0., f64::max);
|
||||
if !(max_w.is_finite() && max_w > 0.) {
|
||||
return None;
|
||||
}
|
||||
let (Some(first), Some(last)) = (ctrl.first().and_then(|p| p.project()), ctrl.last().and_then(|p| p.project())) else { return None };
|
||||
let level = plane.height(first);
|
||||
let (a, b) = (plane.to_local(first), plane.to_local(last));
|
||||
if first.dist(run.ends[0]) > tol || last.dist(run.ends[1]) > tol {
|
||||
return None;
|
||||
}
|
||||
let mut points = Vec::with_capacity(ctrl.len());
|
||||
let mut weights = Vec::with_capacity(ctrl.len());
|
||||
for p in &ctrl {
|
||||
if p.w / max_w < 1e-12 {
|
||||
return None;
|
||||
}
|
||||
let v = p.project()?;
|
||||
let error = (v.x.abs() + v.y.abs() + v.z.abs() + plane.origin.len()) * f64::EPSILON * 256.;
|
||||
if (plane.height(v) - level).abs() + error > tol || error > tol * 0.1 {
|
||||
return None;
|
||||
}
|
||||
let local = plane.to_local(v);
|
||||
if !(local.x.is_finite() && local.y.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
points.push(local);
|
||||
weights.push(p.w / max_w);
|
||||
}
|
||||
// The ends exactly where the curve ends.
|
||||
if let Some(p) = points.first_mut() {
|
||||
*p = a;
|
||||
}
|
||||
if let Some(p) = points.last_mut() {
|
||||
*p = b;
|
||||
}
|
||||
if weights.iter().all(|w| (w - 1.).abs() <= 1e-12) {
|
||||
weights.clear();
|
||||
}
|
||||
Some(PlanarSpline { degree, knots, points, weights })
|
||||
}
|
||||
|
||||
/// A clamped B-spline `(degree, knots, control points)` run the way `run` goes: as it is
|
||||
/// forward, its knots mirrored and its control points reversed back.
|
||||
fn along(run: &Run, (degree, knots, ctrl): (usize, Vec<f64>, Vec<HPoint>)) -> Option<(usize, Vec<f64>, Vec<HPoint>)> {
|
||||
if run.forward {
|
||||
return Some((degree, knots, ctrl));
|
||||
}
|
||||
let sum = knots.first()? + knots.last()?;
|
||||
Some((degree, knots.iter().rev().map(|k| sum - k).collect(), ctrl.into_iter().rev().collect()))
|
||||
}
|
||||
|
||||
fn read(run: &Run, plane: &Plane, tol: f64, work: &mut usize, each_span: bool) -> Option<Vec<Seg2>> {
|
||||
if !tol.is_finite() || tol <= 0. {
|
||||
return None;
|
||||
|
||||
@@ -135,11 +135,13 @@ fn a_void_reads_as_a_cavity_whichever_way_its_shell_flag_points() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A ball whose one face is bounded by a meridian edge from the north pole that stops short of
|
||||
/// the south pole (at 2.5 rad), run out and back: the face is the whole sphere less a slit of no
|
||||
/// area, so it is the same 2 mm ball as when the seam runs pole to pole.
|
||||
#[test]
|
||||
fn non_antipodal_seam_sphere_does_not_panic() {
|
||||
fn non_antipodal_seam_sphere_imports_as_a_whole_ball() {
|
||||
let text = seam_sphere_step(Vec3::ZERO, 2.0, Vec3::Z, Vec3::X, 0.0, false, 2.5);
|
||||
let result = std::panic::catch_unwind(|| step_import(&text));
|
||||
assert!(result.is_ok());
|
||||
assert_seam_sphere(&text, 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1545,60 +1547,6 @@ fn faces_with_too_many_bounds_are_refused() {
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(10), "took {:?}", start.elapsed());
|
||||
}
|
||||
|
||||
/// A board-like assembly for issue #883: `SOLIDCRAFT_STEP_PCB_FIXTURE=path` writes it (with
|
||||
/// `SOLIDCRAFT_STEP_PCB_COMPONENTS` and `SOLIDCRAFT_STEP_PCB_PINS`; 600 and 15 give 52 MB). Every component is
|
||||
/// its own product with a package body and its own pins (nothing shared), the worst case for
|
||||
/// a large import.
|
||||
#[test]
|
||||
#[ignore = "manual fixture generator for large STEP imports"]
|
||||
fn generate_board_assembly_fixture() {
|
||||
use crate::step_out::{ExportBody, ExportProduct, StepHeader, step_export_products};
|
||||
let count: usize = solidcraft_geom::env::var("STEP_PCB_COMPONENTS").map(|s| s.parse().unwrap()).unwrap_or(500);
|
||||
let pins: usize = solidcraft_geom::env::var("STEP_PCB_PINS").map(|s| s.parse().unwrap()).unwrap_or(16);
|
||||
let mut owned: Vec<Vec<Body>> = Vec::new();
|
||||
for c in 0..count {
|
||||
let w = 4.0 + (c % 7) as f64 * 0.37;
|
||||
let d = 3.0 + (c % 5) as f64 * 0.29;
|
||||
let mut bodies = vec![fillet_box(w, d, 1.2 + (c % 3) as f64 * 0.1)];
|
||||
for p in 0..pins {
|
||||
let side = if p % 2 == 0 { -0.6 } else { d + 0.6 };
|
||||
let x = 0.3 + (p / 2) as f64 * (w - 0.6) / (pins / 2).max(1) as f64 + c as f64 * 1e-4;
|
||||
bodies.push(cylinder(Vec3::new(x, side, -1.5), Vec3::Z, 0.25, 2.0 + (p % 3) as f64 * 0.01).unwrap());
|
||||
}
|
||||
owned.push(bodies);
|
||||
}
|
||||
let mut products: Vec<ExportProduct> = owned
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(c, bodies)| ExportProduct {
|
||||
name: format!("U{c}"),
|
||||
bodies: bodies.iter().enumerate().map(|(k, b)| ExportBody { name: format!("U{c}_{k}"), body: b, color: Some([0.2, 0.2, 0.2]) }).collect(),
|
||||
children: Vec::new(),
|
||||
})
|
||||
.collect();
|
||||
let side = (count as f64).sqrt().ceil() as usize;
|
||||
let children = (0..count)
|
||||
.map(|c| {
|
||||
let (x, y) = ((c % side) as f64 * 12.0, (c / side) as f64 * 10.0);
|
||||
(c, [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [x, y, 1.6, 1.0]], format!("U{c}"))
|
||||
})
|
||||
.collect();
|
||||
products.push(ExportProduct { name: "Board".into(), bodies: Vec::new(), children });
|
||||
let root = products.len() - 1;
|
||||
let text = step_export_products(&products, root, &StepHeader { file_name: "board.step".into(), ..Default::default() }).unwrap();
|
||||
let path = solidcraft_geom::env::var("STEP_PCB_FIXTURE").unwrap_or_else(|| "board.step".into());
|
||||
std::fs::write(&path, &text).unwrap();
|
||||
println!("wrote {path}: {} bytes, {} components", text.len(), count);
|
||||
}
|
||||
|
||||
fn fillet_box(w: f64, d: f64, h: f64) -> Body {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(w, d, h)).unwrap();
|
||||
let vertical = [Vec3::new(0.0, 0.0, h / 2.0), Vec3::new(w, 0.0, h / 2.0), Vec3::new(w, d, h / 2.0), Vec3::new(0.0, d, h / 2.0)];
|
||||
let top = [Vec3::new(w / 2.0, 0.0, h), Vec3::new(w, d / 2.0, h), Vec3::new(w / 2.0, d, h), Vec3::new(0.0, d / 2.0, h)];
|
||||
let b = fillet(&b, &vertical, 0.3).unwrap_or(b);
|
||||
fillet(&b, &top, 0.1).unwrap_or(b)
|
||||
}
|
||||
|
||||
/// Independent boxes as one STEP file (about 3 KB a box).
|
||||
fn boxes_step(count: usize, name: &str) -> String {
|
||||
let bodies: Vec<_> = (0..count)
|
||||
|
||||
@@ -323,8 +323,15 @@ mod tests {
|
||||
// A triangle-like patch whose top side is a pole (two copies of one point in 3D).
|
||||
let b = vec![[0.0, 0.0], [0.5, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]];
|
||||
let Some(q) = quad(&b) else { panic!("a quad") };
|
||||
let Some((_, tris)) = structured(&b, &q, &[0.5], &[0.5]) else { panic!("meshes") };
|
||||
assert!(!tris.is_empty());
|
||||
let Some((extra, tris)) = structured(&b, &q, &[0.5], &[0.5]) else { panic!("meshes") };
|
||||
// One grid node, (0.5, 0.5), fanned to each of the five boundary segments: one triangle
|
||||
// each, the pole's single segment among them, every one of positive area, tiling the box.
|
||||
assert_eq!(extra, [[0.5, 0.5]]);
|
||||
assert_eq!(tris.len(), 5);
|
||||
let mut uv = b.clone();
|
||||
uv.extend(extra);
|
||||
assert!(tris.iter().all(|t| signed_area(&uv, *t).is_some_and(|a| a > 0.0)));
|
||||
assert!((area(&uv, &tris) - 1.0).abs() < 1e-12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -862,7 +862,18 @@ fn a_face_bounded_by_two_short_arcs_keeps_an_area_to_mesh() {
|
||||
let made = ok(assemble(parts, false));
|
||||
let (plan, _) = ok(plan(&made.brep, 0.5, None));
|
||||
let lens = made.faces.first().and_then(|&f| plan.faces.get(f)).expect("the lens's plan");
|
||||
assert!(!lens.triangles.is_empty(), "the lens has triangles");
|
||||
// One round of halving puts a node at each arc's middle, (0, ±(r − c)) (the plane's (u, v)
|
||||
// is its (x, y)): the triangles fill the rhombus with diagonals 2·half and 2(r − c).
|
||||
let area: f64 = lens
|
||||
.triangles
|
||||
.iter()
|
||||
.map(|t| {
|
||||
let [a, b, c] = t.map(|i| lens.uv[i as usize]);
|
||||
0.5 * ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]))
|
||||
})
|
||||
.sum();
|
||||
let rhombus = 2.0 * half * (r - c);
|
||||
assert!((area - rhombus).abs() < 1e-9 * rhombus, "{area} vs {rhombus}");
|
||||
}
|
||||
|
||||
/// Half of a square pyramid's sides as one spline face: degree 1, closed round the square
|
||||
|
||||
+35
-280
@@ -726,9 +726,11 @@ fn loft_and_sweep() {
|
||||
let sq = Loop2::polygon(&[Vec2::new(-20.0, -20.0), Vec2::new(20.0, -20.0), Vec2::new(20.0, 20.0), Vec2::new(-20.0, 20.0)]);
|
||||
let top = Plane::XY.offset(40.0);
|
||||
let l = loft(&[(Plane::XY, sq), (top, Loop2::circle(Vec2::ZERO, 10.0))]).unwrap();
|
||||
let m = measure(&l).unwrap();
|
||||
println!("loft volume {} faces {:?}", m.volume, m.merged);
|
||||
assert!(m.volume > 314.0 * 40.0 && m.volume < 1600.0 * 40.0);
|
||||
// Ruled, each side on the rational quarter of the circle between its corners' directions: the
|
||||
// section at t has area (1 − t)² A_S + t² A_C + t(1 − t) M, M = ½∮(S × C' + C × S'), so
|
||||
// V = h (A_S/3 + A_C/3 + M/6) = 35080.725 (M = 1433.790 by quadrature; tests/oracle/17-loft).
|
||||
let v = measure(&l).unwrap().volume;
|
||||
assert!(rel(v, 35080.725116) < 1e-6, "{v}");
|
||||
// A tube: up 30, quarter bend of radius 20, across 30.
|
||||
let disc = Region2 { outer: Loop2::circle(Vec2::ZERO, 3.0), holes: vec![] };
|
||||
let path = [
|
||||
@@ -742,9 +744,6 @@ fn loft_and_sweep() {
|
||||
PathSeg::Line { a: Vec3::new(20.0, 0.0, 50.0), b: Vec3::new(50.0, 0.0, 50.0) },
|
||||
];
|
||||
let t = sweep(&Plane::XY, &disc, &path).unwrap();
|
||||
for tol in [0.1, 0.01, 0.003, 0.001] {
|
||||
println!("tube tess {tol}: {}", t.mesh(&crate::MeshTolerance::chord(tol)).unwrap().measure().volume);
|
||||
}
|
||||
let area = PI * 9.0;
|
||||
let expect = area * (30.0 + 30.0 + 20.0 * std::f64::consts::FRAC_PI_2);
|
||||
assert!(rel(measure(&t).unwrap().volume, expect) < 1e-3, "{} vs {expect}", measure(&t).unwrap().volume);
|
||||
@@ -1023,78 +1022,6 @@ fn similar_spheres_meet() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_convergence() {
|
||||
let b = extrude(&Plane::XY, &[Region2 { outer: Loop2::circle(Vec2::ZERO, 15.0), holes: vec![] }], 0.0, 50.0).unwrap().pop().unwrap();
|
||||
for t in [0.1, 0.05, 0.02, 0.01, 0.005, 0.002] {
|
||||
let m = b.mesh(&crate::MeshTolerance::chord(t)).unwrap();
|
||||
let mm = m.measure();
|
||||
println!("tol {t}: tris {} vol {} err {:.3e}", m.triangles.len(), mm.volume, mm.volume / (PI * 225.0 * 50.0) - 1.0);
|
||||
}
|
||||
let m = b.mesh(&crate::MeshTolerance::chord(0.05)).unwrap();
|
||||
for f in 0..4u32 {
|
||||
let ns: Vec<Vec3> =
|
||||
m.triangles.iter().zip(&m.tri_face).filter(|(_, ff)| **ff == f).flat_map(|(t, _)| t.iter().map(|k| m.normals[*k as usize])).collect();
|
||||
println!("face {f}: {} normals, first {:?}, max |n.z| {}", ns.len(), ns.first(), ns.iter().map(|n| n.z.abs()).fold(0.0, f64::max));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_coplanar() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap();
|
||||
for (z0, z1) in [(0.0, 20.0), (-5.0, 20.0), (0.0, 25.0), (-5.0, 25.0), (5.0, 20.0), (5.0, 25.0)] {
|
||||
let c = cylinder(Vec3::new(20.0, 15.0, z0), Vec3::Z, 5.0, z1 - z0).unwrap();
|
||||
let r = boolean(&b, &c, BoolOp::Cut);
|
||||
println!("cut z {z0}..{z1}: {:?}", r.map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
let r = boolean(&b, &c, BoolOp::Union);
|
||||
println!("union z {z0}..{z1}: {:?}", r.map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
}
|
||||
let r =
|
||||
Region2 { outer: Loop2::polygon(&[Vec2::new(0.0, 0.0), Vec2::new(40.0, 0.0), Vec2::new(40.0, 30.0), Vec2::new(0.0, 30.0)]), holes: vec![] };
|
||||
for ang in [PI / 2.0, PI, 1.5 * PI, 2.0 * PI] {
|
||||
let q = revolve(&Plane::XY, std::slice::from_ref(&r), Vec2::ZERO, Vec2::Y, ang).unwrap().pop().unwrap();
|
||||
let m = measure(&q).unwrap();
|
||||
println!("revolve {ang}: vol {} expect {} faces {}", m.volume, ang / 2.0 * 1600.0 * 30.0, m.faces);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_blind() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap();
|
||||
let t = box_solid(Vec3::new(10.0, 10.0, 5.0), Vec3::new(20.0, 20.0, 25.0)).unwrap();
|
||||
println!("box pocket: {:?}", boolean(&b, &t, BoolOp::Cut).map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
let t = box_solid(Vec3::new(10.0, 10.0, 5.0), Vec3::new(20.0, 20.0, 15.0)).unwrap();
|
||||
println!("box void: {:?}", boolean(&b, &t, BoolOp::Cut).map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
for r in [5.0, 4.3] {
|
||||
for z in [5.0, 7.3, 13.1] {
|
||||
let c = cylinder(Vec3::new(20.3, 15.1, z), Vec3::Z, r, 30.0).unwrap();
|
||||
println!("cyl r{r} z{z}: {:?}", boolean(&b, &c, BoolOp::Cut).map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
}
|
||||
}
|
||||
let c = cylinder(Vec3::new(20.0, 15.0, 25.0), -Vec3::Z, 5.0, 20.0).unwrap();
|
||||
println!("cyl down: {:?}", boolean(&b, &c, BoolOp::Cut).map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
let s = sphere(Vec3::new(20.0, 15.0, 20.0), 5.0).unwrap();
|
||||
println!("sphere: {:?}", boolean(&b, &s, BoolOp::Cut).map(|o| o.map(|b| measure(&b).unwrap().volume)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_revolve_doc_case() {
|
||||
let r =
|
||||
Region2 { outer: Loop2::polygon(&[Vec2::new(0.0, 0.0), Vec2::new(40.0, 0.0), Vec2::new(40.0, 30.0), Vec2::new(0.0, 30.0)]), holes: vec![] };
|
||||
for ang in [PI / 2.0, -PI / 2.0] {
|
||||
let q = revolve(&Plane::XY, std::slice::from_ref(&r), Vec2::ZERO, Vec2::Y, ang).unwrap().pop().unwrap();
|
||||
let m = measure(&q).unwrap();
|
||||
println!("ang {ang}: vol {} bbox {:?}", m.volume, m.bbox);
|
||||
}
|
||||
let r2 = Region2 { outer: r.outer.reversed(), holes: vec![] };
|
||||
let q = revolve(&Plane::XY, std::slice::from_ref(&r2), Vec2::ZERO, Vec2::Y, PI / 2.0).unwrap().pop().unwrap();
|
||||
println!("reversed: {}", measure(&q).unwrap().volume);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chamfer_top_loop_mitres() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap();
|
||||
@@ -1203,111 +1130,6 @@ fn chamfer_wider_than_sloped_basin_rim_builds() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_chamfer_cut() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap();
|
||||
// Prism along x: triangle in the YZ plane beyond the top-front edge.
|
||||
let plane = Plane { origin: Vec3::new(-5.0, 0.0, 0.0), x: Vec3::Y, y: Vec3::Z };
|
||||
let tri = Loop2::polygon(&[Vec2::new(2.3, 20.3), Vec2::new(-0.3, 17.7), Vec2::new(10.0, 30.0)]);
|
||||
let tri = if tri.signed_area() < 0.0 { tri.reversed() } else { tri };
|
||||
let tool = extrude(&plane, &[Region2 { outer: tri, holes: vec![] }], 0.0, 50.0).unwrap().pop().unwrap();
|
||||
println!("tool vol {}", measure(&tool).unwrap().volume);
|
||||
let r = boolean(&b, &tool, BoolOp::Cut).unwrap().unwrap();
|
||||
let m = measure(&r).unwrap();
|
||||
println!("cut: {} faces {} {:?}", m.volume, m.faces, m.merged);
|
||||
for f in r.faces(0.01).unwrap() {
|
||||
println!("face {} area {:.3} c {:?} n {:?}", f.index, f.area, f.centroid, f.plane_normal);
|
||||
}
|
||||
for tol in [0.1, 0.01, 0.001] {
|
||||
println!("tess {tol}: {}", r.mesh(&crate::MeshTolerance::chord(tol)).unwrap().measure().volume);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_revolved_hole_tool() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(60.0, 40.0, 15.0)).unwrap();
|
||||
// Drill point profile in the XZ plane through x = 50: revolve about the vertical line x = 50.
|
||||
let pl = Plane { origin: Vec3::new(50.0, 20.0, 0.0), x: Vec3::X, y: Vec3::Z };
|
||||
let r = 3.0;
|
||||
let tip = r / 59f64.to_radians().tan();
|
||||
let prof =
|
||||
Region2 { outer: Loop2::polygon(&[Vec2::new(0.0, 16.0), Vec2::new(0.0, 5.0 - tip), Vec2::new(r, 5.0), Vec2::new(r, 16.0)]), holes: vec![] };
|
||||
let tool = revolve(&pl, &[prof], Vec2::ZERO, Vec2::Y, std::f64::consts::TAU).unwrap().pop().unwrap();
|
||||
println!("tool vol {}", measure(&tool).unwrap().volume);
|
||||
let res = boolean(&b, &tool, BoolOp::Cut);
|
||||
println!("cut: {:?}", res.map(|o| o.map(|x| measure(&x).unwrap().volume)));
|
||||
let expect = 36000.0 - std::f64::consts::PI * 9.0 * 10.0 - std::f64::consts::PI * 9.0 * tip / 3.0;
|
||||
println!("expect {expect}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_sphere() {
|
||||
let s = sphere(Vec3::new(1.0, 2.0, 3.0), 10.0).unwrap();
|
||||
let m = measure(&s).unwrap();
|
||||
println!("vol {} area {} faces {} bbox {:?}", m.volume, m.area, m.faces, m.bbox);
|
||||
for f in s.faces(0.05).unwrap() {
|
||||
println!("face {} area {:.3} c {:?}", f.index, f.area, f.centroid);
|
||||
}
|
||||
let b = box_solid(Vec3::new(-25.0, -25.0, -20.0), Vec3::new(25.0, 25.0, 0.0)).unwrap();
|
||||
for (name, c) in [("origin", Vec3::ZERO), ("up", Vec3::new(0.0, 0.0, 3.0)), ("off", Vec3::new(1.3, 2.1, 0.7))] {
|
||||
let sp = sphere(c, 15.0).unwrap();
|
||||
println!("{name} cut {:?}", boolean(&b, &sp, BoolOp::Cut).map(|o| o.map(|x| measure(&x).unwrap().volume)));
|
||||
println!("{name} and {:?}", boolean(&b, &sp, BoolOp::Intersect).map(|o| o.map(|x| measure(&x).unwrap().volume)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_countersink() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(60.0, 40.0, 15.0)).unwrap();
|
||||
for (name, pts) in [
|
||||
("csink", vec![Vec2::new(0.0, 0.6), Vec2::new(6.6, 0.6), Vec2::new(3.0, -3.0), Vec2::new(3.0, -31.0), Vec2::new(0.0, -31.0)]),
|
||||
("csink-thru-top", vec![Vec2::new(0.0, 0.6), Vec2::new(6.6, 0.6), Vec2::new(3.0, -3.0), Vec2::new(3.0, -16.3), Vec2::new(0.0, -16.3)]),
|
||||
(
|
||||
"cbore",
|
||||
vec![Vec2::new(0.0, 0.6), Vec2::new(7.0, 0.6), Vec2::new(7.0, -5.0), Vec2::new(4.0, -5.0), Vec2::new(4.0, -31.0), Vec2::new(0.0, -31.0)],
|
||||
),
|
||||
] {
|
||||
for (pn, pl) in [
|
||||
("xz@top", Plane::new(Vec3::new(35.0, 20.0, 15.0), Vec3::X, Vec3::Z).unwrap()),
|
||||
("yz@top", Plane::new(Vec3::new(35.0, 20.0, 15.0), Vec3::Y, Vec3::Z).unwrap()),
|
||||
("diag", Plane::new(Vec3::new(35.0, 20.0, 15.0), Vec3::new(0.6, 0.8, 0.0), Vec3::Z).unwrap()),
|
||||
] {
|
||||
let tool = revolve(&pl, &[Region2 { outer: Loop2::polygon(&pts), holes: vec![] }], Vec2::ZERO, Vec2::Y, std::f64::consts::TAU)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
println!(
|
||||
"{name} {pn}: tool {} cut {:?}",
|
||||
measure(&tool).unwrap().volume,
|
||||
boolean(&b, &tool, BoolOp::Cut).map(|o| o.map(|x| measure(&x).unwrap().volume))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_cbore_seq() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(60.0, 40.0, 15.0)).unwrap();
|
||||
let pl = Plane::from_normal(Vec3::new(15.0, 20.0, 15.0), Vec3::Z).unwrap();
|
||||
for (s1, s2, r2top) in [(0.0, 0.0, 0.6), (0.613, 1.226, 0.6), (0.3, 0.9, 2.37)] {
|
||||
let t1 = extrude(&pl, &[Region2 { outer: Loop2::circle_from(Vec2::ZERO, 4.0, s1), holes: vec![] }], -31.0, 0.6).unwrap().pop().unwrap();
|
||||
let c1 = boolean(&b, &t1, BoolOp::Cut).unwrap().unwrap();
|
||||
let t2 = extrude(&pl, &[Region2 { outer: Loop2::circle_from(Vec2::ZERO, 7.0, s2), holes: vec![] }], -5.0, r2top).unwrap().pop().unwrap();
|
||||
println!(
|
||||
"seams {s1} {s2}: first {} second {:?}",
|
||||
measure(&c1).unwrap().volume,
|
||||
boolean(&c1, &t2, BoolOp::Cut).map(|o| o.map(|x| measure(&x).unwrap().volume))
|
||||
);
|
||||
let c2 = boolean(&b, &t2, BoolOp::Cut).unwrap().unwrap();
|
||||
println!(" swapped: {:?}", boolean(&c2, &t1, BoolOp::Cut).map(|o| o.map(|x| measure(&x).unwrap().volume)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mesh_bodies_move_measure_and_refuse_solid_ops() {
|
||||
// Unit cube as 12 triangles with repeated corners (welded on construction).
|
||||
@@ -1353,26 +1175,6 @@ fn concave_fillet() {
|
||||
assert_eq!(m.merged.face_types.get("cylinder"), Some(&1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn debug_pocket_corners() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(80.0, 60.0, 20.0)).unwrap();
|
||||
let p = box_solid(Vec3::new(15.0, 15.0, 12.0), Vec3::new(65.0, 45.0, 25.0)).unwrap();
|
||||
let mut cur = boolean(&b, &p, BoolOp::Cut).unwrap().unwrap();
|
||||
for e in [Vec3::new(65.0, 15.0, 16.0), Vec3::new(15.0, 15.0, 16.0), Vec3::new(65.0, 45.0, 16.0), Vec3::new(15.0, 45.0, 16.0)] {
|
||||
match fillet(&cur, &[e], 5.0) {
|
||||
Ok(n) => {
|
||||
println!("ok {e:?} vol {}", measure(&n).unwrap().volume);
|
||||
cur = n;
|
||||
}
|
||||
Err(err) => {
|
||||
println!("fail {e:?}: {err}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pocket_floor_loop_fillet() {
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(80.0, 60.0, 20.0)).unwrap();
|
||||
@@ -1381,18 +1183,23 @@ fn pocket_floor_loop_fillet() {
|
||||
cur = fillet(&cur, &[Vec3::new(65.0, 15.0, 16.0), Vec3::new(15.0, 15.0, 16.0), Vec3::new(65.0, 45.0, 16.0), Vec3::new(15.0, 45.0, 16.0)], 5.0)
|
||||
.unwrap();
|
||||
let v1 = measure(&cur).unwrap().volume;
|
||||
// The 50 x 30 x 8 pocket, less the four concave R5 rounds of its corners filling r²(1 − π/4)
|
||||
// of section along their 8.
|
||||
let want1 = 80.0 * 60.0 * 20.0 - 50.0 * 30.0 * 8.0 + 4.0 * 25.0 * (1.0 - PI / 4.0) * 8.0;
|
||||
assert!(rel(v1, want1) < 1e-6, "{v1} vs {want1}");
|
||||
let floor: Vec<Vec3> = [(40.0, 15.0), (65.0, 30.0), (40.0, 45.0), (15.0, 30.0)].iter().map(|(x, y)| Vec3::new(*x, *y, 12.0)).collect();
|
||||
let mut pts = floor.clone();
|
||||
let d = 5.0 - 5.0 / 2f64.sqrt();
|
||||
pts.extend([(15.0 + d, 15.0 + d), (65.0 - d, 15.0 + d), (65.0 - d, 45.0 - d), (15.0 + d, 45.0 - d)].iter().map(|(x, y)| Vec3::new(*x, *y, 12.0)));
|
||||
let f = fillet(&cur, &pts, 2.0).unwrap();
|
||||
let m = measure(&f).unwrap();
|
||||
// Added: the fillet profile (r²(1 − π/4)) swept along the floor outline (Pappus for the
|
||||
// corners: the profile's centroid sits 2 − 4·2/(3(4 − π))·… inward; check loosely).
|
||||
let straight = 2.0 * (40.0 + 20.0);
|
||||
let added_lines = (4.0 - PI) * straight;
|
||||
assert!(m.volume > v1 + added_lines && m.volume < v1 + added_lines + 4.0 * 2.0 * PI * 5.0, "{} {}", m.volume, v1);
|
||||
println!("pocket: {:?} vol {}", m.merged, m.volume);
|
||||
// Added: the R2 round's section, a = r²(1 − π/4), along the floor outline's straight 2(40 + 20),
|
||||
// and round its four R5 corners by Pappus: a quarter turn each at the radius of the section's
|
||||
// centroid, which sits r(10 − 3π)/(3(4 − π)) in from the wall, at 5 from the corner's axis.
|
||||
let a = 4.0 * (1.0 - PI / 4.0);
|
||||
let centroid = 5.0 - 2.0 * (10.0 - 3.0 * PI) / (3.0 * (4.0 - PI));
|
||||
let want = v1 + a * 2.0 * (40.0 + 20.0) + 4.0 * a * (PI / 2.0) * centroid;
|
||||
assert!(rel(m.volume, want) < 1e-6, "{} vs {want}", m.volume);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1425,7 +1232,25 @@ fn coplanar_curved_booleans() {
|
||||
assert!(rel(measure(&cut).unwrap().volume, 32000.0 - half * 20.0) < 1e-3);
|
||||
let i = boolean(&a, &c, BoolOp::Intersect).unwrap().unwrap();
|
||||
assert!(rel(measure(&i).unwrap().volume, half * 20.0) < 1e-3);
|
||||
println!("union {:?}", m.merged);
|
||||
// A cylinder of radius 5 through the middle of a 40 x 30 x 20 box, its caps flush with the
|
||||
// box's top or bottom or past them: the cut takes the part inside, π·25 a mm of height, and
|
||||
// the union adds the parts outside. A cylinder inside but for a flush cap adds nothing.
|
||||
let b = box_solid(Vec3::ZERO, Vec3::new(40.0, 30.0, 20.0)).unwrap();
|
||||
let disc = PI * 25.0;
|
||||
for (z0, z1, inside, outside) in [
|
||||
(0.0, 20.0, 20.0, 0.0),
|
||||
(-5.0, 20.0, 20.0, 5.0),
|
||||
(0.0, 25.0, 20.0, 5.0),
|
||||
(-5.0, 25.0, 20.0, 10.0),
|
||||
(5.0, 20.0, 15.0, 0.0),
|
||||
(5.0, 25.0, 15.0, 5.0),
|
||||
] {
|
||||
let c = cylinder(Vec3::new(20.0, 15.0, z0), Vec3::Z, 5.0, z1 - z0).unwrap();
|
||||
let cut = measure(&boolean(&b, &c, BoolOp::Cut).unwrap().unwrap()).unwrap().volume;
|
||||
assert!(rel(cut, 24000.0 - disc * inside) < 1e-6, "cut z {z0}..{z1}: {cut}");
|
||||
let union = measure(&boolean(&b, &c, BoolOp::Union).unwrap().unwrap()).unwrap().volume;
|
||||
assert!(rel(union, 24000.0 + disc * outside) < 1e-6, "union z {z0}..{z1}: {union}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2098,57 +1923,6 @@ fn fillet_partial_mixed_arc_and_line_perimeter_run() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Boolean survey: random boxes, cylinders and spheres combined every way; prints what fails.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn boolean_survey() {
|
||||
let mut seed: u64 = 0x2545_f491_4f6c_dd1d;
|
||||
let mut rnd = || {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 7;
|
||||
seed ^= seed << 17;
|
||||
(seed % 1_000_000) as f64 / 1_000_000.0
|
||||
};
|
||||
let mut shapes: Vec<(String, Body)> = Vec::new();
|
||||
for i in 0..40 {
|
||||
let kind = i % 4;
|
||||
let (x, y, z) = ((rnd() - 0.5) * 20.0, (rnd() - 0.5) * 20.0, (rnd() - 0.5) * 20.0);
|
||||
// Snap some coordinates to a 5 mm grid: coincident faces and tangencies.
|
||||
let snap = |v: f64, s: bool| if s { (v / 5.0).round() * 5.0 } else { v };
|
||||
let s = rnd() < 0.5;
|
||||
let (x, y, z) = (snap(x, s), snap(y, s), snap(z, s));
|
||||
let a = 5.0 + snap(rnd() * 20.0, s);
|
||||
let ax = (rnd() * 3.0) as usize % 3;
|
||||
let b = match kind {
|
||||
0 => box_solid(Vec3::new(x, y, z), Vec3::new(x + a, y + a * 0.8, z + a * 0.6)),
|
||||
1 => cylinder(Vec3::new(x, y, z), [Vec3::X, Vec3::Y, Vec3::Z][ax], a * 0.4, a),
|
||||
2 => sphere(Vec3::new(x, y, z), a * 0.5),
|
||||
_ => box_solid(Vec3::new(x, y, z), Vec3::new(x + a * 0.5, y + a, z + a * 0.3)),
|
||||
};
|
||||
if let Ok(b) = b {
|
||||
shapes.push((format!("{}{i}@({x:.3},{y:.3},{z:.3}) a={a:.3} ax={ax}", ["box", "cyl", "sph", "slab"][kind]), b));
|
||||
}
|
||||
}
|
||||
let (mut ok, mut empty, mut fail) = (0, 0, Vec::new());
|
||||
for i in 0..shapes.len() {
|
||||
for j in i + 1..(i + 4).min(shapes.len()) {
|
||||
for op in [BoolOp::Union, BoolOp::Cut, BoolOp::Intersect] {
|
||||
let (na, a) = &shapes[i];
|
||||
let (nb, b) = &shapes[j];
|
||||
match boolean(a, b, op) {
|
||||
Ok(Some(_)) => ok += 1,
|
||||
Ok(None) => empty += 1,
|
||||
Err(e) => fail.push(format!("{na} {op:?} {nb}: {}", e.to_string().chars().take(140).collect::<String>())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("ok {ok} empty {empty} failed {}", fail.len());
|
||||
for f in &fail {
|
||||
println!(" {f}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn booleans_found_by_the_survey() {
|
||||
// A tool wholly inside: a void (the solid keeps an inner shell).
|
||||
@@ -2338,25 +2112,6 @@ fn a_bend_as_tight_as_the_tube_sweeps_a_valid_solid() {
|
||||
assert!(rel(v, want) < 1e-6, "{v} vs {want}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn boolean_identity_survey() {
|
||||
let n: u64 = std::env::var("N").ok().and_then(|x| x.parse().ok()).unwrap_or(100);
|
||||
let seeds: Vec<u64> = match std::env::var("SEEDS") {
|
||||
Ok(s) => s.split(',').filter_map(|x| x.parse().ok()).collect(),
|
||||
Err(_) => (0..n).collect(),
|
||||
};
|
||||
let mut bad = 0;
|
||||
for seed in seeds {
|
||||
let c = crate::fuzz::boolean_case(seed);
|
||||
if c.outcome != "ok" {
|
||||
bad += 1;
|
||||
println!("{seed}: {} {} | {:?} | {:?}", c.outcome, c.detail, c.a, c.b);
|
||||
}
|
||||
}
|
||||
println!("{bad}/{n} failed");
|
||||
}
|
||||
|
||||
/// A quarter turn of a rectangle with an edge on the axis: no zero-area face along the axis, so
|
||||
/// a cylinder can be cut through the corner (it failed in every boolean attempt before).
|
||||
#[test]
|
||||
|
||||
@@ -190,7 +190,12 @@ pub fn fit_beziers(p: &[Vec2]) -> Vec<[Vec2; 4]> {
|
||||
pub fn fit_beziers_mode(p: &[Vec2], periodic: bool) -> crate::model::Result<Vec<[Vec2; 4]>> {
|
||||
if periodic { crate::periodic_beziers(p) } else { Ok(fit_beziers(p)) }
|
||||
}
|
||||
pub fn spline_point_mode(p: &[Vec2], control: bool, degree: u8, periodic: bool, t: f64) -> Vec2 {
|
||||
/// Point of a spline at `t` in [0, 1]: through its points, over them as a clamped uniform
|
||||
/// B-spline, or with its own knots and weights (`nurbs`).
|
||||
pub fn spline_point_mode(p: &[Vec2], control: bool, degree: u8, periodic: bool, nurbs: Option<&crate::Nurbs>, t: f64) -> Vec2 {
|
||||
if let Some(nurbs) = nurbs {
|
||||
return nurbs.point(p, degree, t).unwrap_or_else(|| p.first().copied().unwrap_or_default());
|
||||
}
|
||||
if !periodic {
|
||||
return spline_point(p, control, degree, t);
|
||||
}
|
||||
@@ -211,7 +216,11 @@ pub fn spline_point_mode(p: &[Vec2], control: bool, degree: u8, periodic: bool,
|
||||
let t = (remaining / lengths[i]).clamp(0.0, 1.0);
|
||||
a * (1.0 - t).powi(3) + b * (3.0 * t * (1.0 - t).powi(2)) + c * (3.0 * t * t * (1.0 - t)) + d * t.powi(3)
|
||||
}
|
||||
pub fn spline_polyline_mode(p: &[Vec2], control: bool, degree: u8, periodic: bool) -> Vec<Vec2> {
|
||||
/// Polyline of a spline, as [`spline_point_mode`] reads it.
|
||||
pub fn spline_polyline_mode(p: &[Vec2], control: bool, degree: u8, periodic: bool, nurbs: Option<&crate::Nurbs>) -> Vec<Vec2> {
|
||||
if let Some(nurbs) = nurbs {
|
||||
return nurbs.polyline(p, degree);
|
||||
}
|
||||
if !periodic {
|
||||
return spline_polyline(p, control, degree);
|
||||
}
|
||||
@@ -307,6 +316,7 @@ pub fn spline_polyline(p: &[Vec2], control: bool, degree: u8) -> Vec<Vec2> {
|
||||
}
|
||||
|
||||
/// Unit tangent of a spline at its start (`at_end == false`) or end, pointing along the curve.
|
||||
/// A control spline's runs along its end leg whatever its knots and (positive) weights.
|
||||
pub fn spline_end_tangent(p: &[Vec2], control: bool, at_end: bool) -> Option<Vec2> {
|
||||
let n = p.len();
|
||||
if n < 2 {
|
||||
|
||||
@@ -439,7 +439,7 @@ impl Sketch {
|
||||
}
|
||||
let output = self.curve_index(&record.output).ok_or_else(|| bad("offset output vanished"))?;
|
||||
match &self.curves[output].kind {
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic }
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic, .. }
|
||||
if *periodic == (record.certificate == 2)
|
||||
&& (record.certificate != 2 || record.closed)
|
||||
&& pts.len() == record.pieces * record.divisions + 1
|
||||
@@ -484,7 +484,7 @@ impl Sketch {
|
||||
p.fixed = true;
|
||||
}
|
||||
}
|
||||
let output = candidate.add_curve(CurveKind::Spline { pts: indices, control: false, degree: 3, periodic: closed }, None)?;
|
||||
let output = candidate.add_curve(CurveKind::Spline { pts: indices, control: false, degree: 3, periodic: closed, nurbs: None }, None)?;
|
||||
candidate.freeform_offsets.push(FreeformOffset {
|
||||
source: source_id,
|
||||
output: candidate.curves[output].id.clone(),
|
||||
@@ -551,7 +551,7 @@ impl Sketch {
|
||||
return Err(bad("offset source topology changed"));
|
||||
}
|
||||
let old_indices = match &candidate.curves[output].kind {
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic }
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic, .. }
|
||||
if *periodic == (record.certificate == 2)
|
||||
&& (record.certificate != 2 || record.closed)
|
||||
&& pts.len() == record.pieces * record.divisions + 1 =>
|
||||
@@ -583,7 +583,8 @@ impl Sketch {
|
||||
p.pos = pos;
|
||||
p.fixed = true;
|
||||
}
|
||||
candidate.curves[output].kind = CurveKind::Spline { pts: indices, control: false, degree: 3, periodic: record.certificate == 2 };
|
||||
candidate.curves[output].kind =
|
||||
CurveKind::Spline { pts: indices, control: false, degree: 3, periodic: record.certificate == 2, nurbs: None };
|
||||
candidate.freeform_offsets[record_index].divisions = divisions;
|
||||
candidate.freeform_offsets[record_index].pieces = pieces;
|
||||
}
|
||||
@@ -632,7 +633,7 @@ mod tests {
|
||||
.into_iter()
|
||||
.map(|(x, y)| sk.add_point(Vec2::new(x, y), None).unwrap())
|
||||
.collect();
|
||||
let source = sk.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic: true }, None).unwrap();
|
||||
let source = sk.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic: true, nurbs: None }, None).unwrap();
|
||||
let original = sk.clone();
|
||||
for (forward, distance) in [(true, 2.0), (false, -2.0)] {
|
||||
let mut sk = original.clone();
|
||||
|
||||
@@ -1080,7 +1080,7 @@ impl Sketch {
|
||||
pts.push(candidate.add_point(*p, None)?);
|
||||
}
|
||||
pts.push(end);
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic: false }
|
||||
CurveKind::Spline { pts, control: false, degree: 3, periodic: false, nurbs: None }
|
||||
}
|
||||
Out::Arc { center, sweep, .. } => {
|
||||
let c = candidate.add_point(*center, None)?;
|
||||
@@ -1111,7 +1111,7 @@ mod tests {
|
||||
fn spline(coords: &[(f64, f64)], periodic: bool) -> (Sketch, usize) {
|
||||
let mut sk = Sketch::new();
|
||||
let pts = coords.iter().map(|(x, y)| sk.add_point(Vec2::new(*x, *y), None).unwrap()).collect();
|
||||
let source = sk.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic }, None).unwrap();
|
||||
let source = sk.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic, nurbs: None }, None).unwrap();
|
||||
(sk, source)
|
||||
}
|
||||
|
||||
@@ -1210,8 +1210,9 @@ mod tests {
|
||||
for (k, b) in beziers.iter().enumerate() {
|
||||
let mid = [1, 2].map(|i| sk.add_point(Vec2::new(b[i].0, b[i].1), None).unwrap());
|
||||
let end = if k + 1 == beziers.len() { first } else { sk.add_point(Vec2::new(b[3].0, b[3].1), None).unwrap() };
|
||||
let c =
|
||||
sk.add_curve(CurveKind::Spline { pts: vec![start, mid[0], mid[1], end], control: true, degree: 3, periodic: false }, None).unwrap();
|
||||
let c = sk
|
||||
.add_curve(CurveKind::Spline { pts: vec![start, mid[0], mid[1], end], control: true, degree: 3, periodic: false, nurbs: None }, None)
|
||||
.unwrap();
|
||||
order.push((c, true));
|
||||
start = end;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ pub mod linalg;
|
||||
mod link;
|
||||
mod loci;
|
||||
mod model;
|
||||
mod nurbs;
|
||||
mod offset;
|
||||
mod offset_topology;
|
||||
mod pattern;
|
||||
@@ -55,6 +56,7 @@ pub use model::{
|
||||
Constraint, ConstraintKind, Curve, CurveKind, MAX_CONSTRAINTS, MAX_COORD, MAX_CURVES, MAX_POINTS, PointExprs, SPoint, Sketch, SketchError,
|
||||
SketchView, TwoCircles,
|
||||
};
|
||||
pub use nurbs::Nurbs;
|
||||
pub use offset::OffsetChain;
|
||||
pub use offset_topology::{OffsetCreated, OffsetRole, OffsetRoleFlags, OffsetRoleKind, OffsetTopology};
|
||||
pub use pattern::{PatternAlignment, PatternInstance, SketchPattern, SketchPatternKind};
|
||||
|
||||
+53
-21
@@ -238,12 +238,14 @@ pub enum LinkGeom {
|
||||
major: Vec2,
|
||||
minor: f64,
|
||||
},
|
||||
/// Spline through (`control == false`) or over (`control`) the points.
|
||||
/// Spline through (`control == false`) or over (`control`) the points; a control spline
|
||||
/// with its own knots and weights where it has them ([`crate::Nurbs`]).
|
||||
Spline {
|
||||
pts: Vec<Vec2>,
|
||||
control: bool,
|
||||
degree: u8,
|
||||
periodic: bool,
|
||||
nurbs: Option<crate::Nurbs>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -257,8 +259,9 @@ impl LinkGeom {
|
||||
LinkGeom::Arc { c, a, b } => ok(c) && ok(a) && ok(b) && c.dist(*a) > 1e-9 && a.dist(*b) > MERGE_TOL,
|
||||
LinkGeom::Conic { a, apex, b, rho } => ok(a) && ok(apex) && ok(b) && a.dist(*b) > MERGE_TOL && *rho > 1e-6 && *rho < 1.0 - 1e-6,
|
||||
LinkGeom::Ellipse { c, major, minor } => ok(c) && ok(major) && c.dist(*major) > 1e-9 && radius_in_range(*minor),
|
||||
LinkGeom::Spline { pts, control, degree, periodic } => {
|
||||
LinkGeom::Spline { pts, control, degree, periodic, nurbs } => {
|
||||
(!*periodic || (!*control && *degree == 3 && crate::periodic_beziers(pts).is_ok()))
|
||||
&& nurbs.as_ref().is_none_or(|k| *control && !*periodic && k.check(pts.len(), *degree).is_ok())
|
||||
&& (2..=crate::curves::MAX_SPLINE_POINTS).contains(&pts.len())
|
||||
&& pts.iter().all(ok)
|
||||
&& (1..=solidcraft_geom::MAX_BEZIER_DEGREE as u8).contains(degree)
|
||||
@@ -275,7 +278,7 @@ struct Layout {
|
||||
curves: Vec<LCurve>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum LCurve {
|
||||
Line(usize, usize),
|
||||
Circle(usize, f64),
|
||||
@@ -283,8 +286,8 @@ enum LCurve {
|
||||
Conic(usize, usize, usize, f64),
|
||||
Ellipse(usize, usize, f64),
|
||||
/// Start, end, first interior point and interior count (interior points are consecutive
|
||||
/// and never shared), control flag, degree.
|
||||
Spline(usize, usize, usize, usize, bool, u8, bool),
|
||||
/// and never shared), control flag, degree, periodic, own knots and weights.
|
||||
Spline(usize, usize, usize, usize, bool, u8, bool, Option<crate::Nurbs>),
|
||||
}
|
||||
|
||||
fn layout(geom: &[LinkGeom]) -> Result<Layout> {
|
||||
@@ -339,14 +342,14 @@ fn layout(geom: &[LinkGeom]) -> Result<Layout> {
|
||||
l.curves.push(LCurve::Ellipse(c, m, minor));
|
||||
}
|
||||
}
|
||||
LinkGeom::Spline { pts, control, degree, periodic } => {
|
||||
LinkGeom::Spline { pts, control, degree, periodic, nurbs } => {
|
||||
let (Some(first), Some(last)) = (pts.first(), pts.last()) else { continue };
|
||||
let s0 = pt(&mut l.pts, *first);
|
||||
let first_in = l.pts.len();
|
||||
let inner = pts.get(1..pts.len() - 1).unwrap_or_default();
|
||||
l.pts.extend(inner.iter().copied());
|
||||
let s1 = pt(&mut l.pts, *last);
|
||||
l.curves.push(LCurve::Spline(s0, s1, first_in, inner.len(), control, degree, periodic));
|
||||
l.curves.push(LCurve::Spline(s0, s1, first_in, inner.len(), control, degree, periodic, nurbs));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,6 +405,16 @@ fn same_shape(a: &LCurve, b: &LCurve) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether two splines' own knots and weights ([`crate::Nurbs`]) are the same within `close`.
|
||||
fn same_nurbs(a: Option<&crate::Nurbs>, b: Option<&crate::Nurbs>, close: impl Fn(f64, f64) -> bool) -> bool {
|
||||
let all = |x: &[f64], y: &[f64]| x.len() == y.len() && x.iter().zip(y).all(|(p, q)| close(*p, *q));
|
||||
match (a, b) {
|
||||
(None, None) => true,
|
||||
(Some(a), Some(b)) => all(&a.knots, &b.knots) && all(&a.weights, &b.weights),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Do two curve sets describe the same geometry, regardless of the order the curves come in or
|
||||
/// the direction a loop was walked? Lines match with either end first; circles by centre and
|
||||
/// radius; arcs by centre and their (start, end) pair; conics by all their points and rho.
|
||||
@@ -422,7 +435,9 @@ fn same_geometry(a: &[(LCurve, Vec<Vec2>)], b: &[(LCurve, Vec<Vec2>)]) -> bool {
|
||||
(LCurve::Arc(..), LCurve::Arc(..)) => all(),
|
||||
(LCurve::Conic(.., ra), LCurve::Conic(.., rb)) => all() && close(*ra, *rb),
|
||||
(LCurve::Ellipse(.., ra), LCurve::Ellipse(.., rb)) => all() && close(*ra, *rb),
|
||||
(LCurve::Spline(.., ca, da, pa), LCurve::Spline(.., cb, db, pb)) => ca == cb && da == db && pa == pb && all(),
|
||||
(LCurve::Spline(.., ca, da, pa, ka), LCurve::Spline(.., cb, db, pb, kb)) => {
|
||||
ca == cb && da == db && pa == pb && same_nurbs(ka.as_ref(), kb.as_ref(), close) && all()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
@@ -666,10 +681,10 @@ impl Sketch {
|
||||
let at = |i: usize| self.points.get(i).map(|p| p.pos);
|
||||
let near = |i: usize, q: Option<Vec2>| lay.pts.get(i).zip(q).is_some_and(|(p, q)| p.dist(q) <= MERGE_TOL);
|
||||
let curve_present = |c: &LCurve| {
|
||||
self.curves.iter().filter(|k| k.link.is_some()).any(|k| match (*c, &k.kind) {
|
||||
(LCurve::Line(a, b), CurveKind::Line { a: p, b: q }) => (near(a, at(*p)) && near(b, at(*q))) || (near(a, at(*q)) && near(b, at(*p))),
|
||||
(LCurve::Circle(c, r), CurveKind::Circle { c: p, r: s }) => near(c, at(*p)) && (r - s).abs() <= MERGE_TOL,
|
||||
(LCurve::Arc(c, a, b), CurveKind::Arc { c: p, a: q, b: e }) => near(c, at(*p)) && near(a, at(*q)) && near(b, at(*e)),
|
||||
self.curves.iter().filter(|k| k.link.is_some()).any(|k| match (c, &k.kind) {
|
||||
(&LCurve::Line(a, b), CurveKind::Line { a: p, b: q }) => (near(a, at(*p)) && near(b, at(*q))) || (near(a, at(*q)) && near(b, at(*p))),
|
||||
(&LCurve::Circle(c, r), CurveKind::Circle { c: p, r: s }) => near(c, at(*p)) && (r - s).abs() <= MERGE_TOL,
|
||||
(&LCurve::Arc(c, a, b), CurveKind::Arc { c: p, a: q, b: e }) => near(c, at(*p)) && near(a, at(*q)) && near(b, at(*e)),
|
||||
_ => false,
|
||||
})
|
||||
};
|
||||
@@ -716,13 +731,13 @@ impl Sketch {
|
||||
LCurve::Arc(c, a, b) => (CurveKind::Arc { c: point(self, c)?, a: point(self, a)?, b: point(self, b)? }, "a"),
|
||||
LCurve::Conic(a, b, x, rho) => (CurveKind::Conic { a: point(self, a)?, b: point(self, b)?, apex: point(self, x)?, rho }, "k"),
|
||||
LCurve::Ellipse(c, m, r) => (CurveKind::Ellipse { c: point(self, c)?, m: point(self, m)?, r }, "e"),
|
||||
LCurve::Spline(a, b, f, n, control, degree, periodic) => {
|
||||
LCurve::Spline(a, b, f, n, control, degree, periodic, ref nurbs) => {
|
||||
let mut pts = vec![point(self, a)?];
|
||||
for i in f..f + n {
|
||||
pts.push(point(self, i)?);
|
||||
}
|
||||
pts.push(point(self, b)?);
|
||||
(CurveKind::Spline { pts, control, degree, periodic }, "s")
|
||||
(CurveKind::Spline { pts, control, degree, periodic, nurbs: nurbs.clone() }, "s")
|
||||
}
|
||||
};
|
||||
let cid = self.fresh(prefix)?;
|
||||
@@ -775,7 +790,7 @@ impl Sketch {
|
||||
Some(CurveKind::Arc { c, a, b }) => Some(LCurve::Arc(local(*c)?, local(*a)?, local(*b)?)),
|
||||
Some(CurveKind::Conic { a, b, apex, rho }) => Some(LCurve::Conic(local(*a)?, local(*b)?, local(*apex)?, *rho)),
|
||||
Some(CurveKind::Ellipse { c, m, r }) => Some(LCurve::Ellipse(local(*c)?, local(*m)?, *r)),
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic }) => {
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic, nurbs }) => {
|
||||
let (a, b) = (local(*pts.first()?)?, local(*pts.last()?)?);
|
||||
let inner: Vec<usize> =
|
||||
pts.get(1..pts.len().saturating_sub(1)).unwrap_or_default().iter().map(|q| local(*q)).collect::<Option<_>>()?;
|
||||
@@ -784,7 +799,7 @@ impl Sketch {
|
||||
if inner.iter().enumerate().any(|(k, x)| *x != f + k) {
|
||||
return None;
|
||||
}
|
||||
Some(LCurve::Spline(a, b, f, inner.len(), *control, *degree, *periodic))
|
||||
Some(LCurve::Spline(a, b, f, inner.len(), *control, *degree, *periodic, nurbs.clone()))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
@@ -840,7 +855,7 @@ impl Sketch {
|
||||
LCurve::Arc(c, a, b) => LCurve::Arc(renum(c), renum(a), renum(b)),
|
||||
LCurve::Conic(a, b, x, r) => LCurve::Conic(renum(a), renum(b), renum(x), r),
|
||||
LCurve::Ellipse(c, m, r) => LCurve::Ellipse(renum(c), renum(m), r),
|
||||
LCurve::Spline(a, b, f, n, ct, d, periodic) => LCurve::Spline(renum(a), renum(b), renum(f), n, ct, d, periodic),
|
||||
LCurve::Spline(a, b, f, n, ct, d, periodic, ref k) => LCurve::Spline(renum(a), renum(b), renum(f), n, ct, d, periodic, k.clone()),
|
||||
})
|
||||
.collect();
|
||||
let same = match &cur {
|
||||
@@ -855,8 +870,15 @@ impl Sketch {
|
||||
(LCurve::Arc(a0, a1, a2), LCurve::Arc(b0, b1, b2)) => a0 == b0 && a1 == b1 && a2 == b2,
|
||||
(LCurve::Conic(a0, a1, a2, _), LCurve::Conic(b0, b1, b2, _)) => a0 == b0 && a1 == b1 && a2 == b2,
|
||||
(LCurve::Ellipse(a0, a1, _), LCurve::Ellipse(b0, b1, _)) => a0 == b0 && a1 == b1,
|
||||
(LCurve::Spline(a0, a1, a2, a3, a4, a5, a6), LCurve::Spline(b0, b1, b2, b3, b4, b5, b6)) => {
|
||||
a0 == b0 && a1 == b1 && (a2 == b2 || *a3 == 0) && a3 == b3 && a4 == b4 && a5 == b5 && a6 == b6
|
||||
(LCurve::Spline(a0, a1, a2, a3, a4, a5, a6, a7), LCurve::Spline(b0, b1, b2, b3, b4, b5, b6, b7)) => {
|
||||
a0 == b0
|
||||
&& a1 == b1
|
||||
&& (a2 == b2 || *a3 == 0)
|
||||
&& a3 == b3
|
||||
&& a4 == b4
|
||||
&& a5 == b5
|
||||
&& a6 == b6
|
||||
&& a7.is_some() == b7.is_some()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
@@ -873,12 +895,14 @@ impl Sketch {
|
||||
let pos = |pi: usize| self.points.get(pi).map(|p| p.pos);
|
||||
let old: Option<Vec<(LCurve, Vec<Vec2>)>> = cur
|
||||
.iter()
|
||||
.map(|c| curve_points(c).into_iter().map(|li| points.get(li).and_then(|pi| pos(*pi))).collect::<Option<Vec<_>>>().map(|ps| (*c, ps)))
|
||||
.map(|c| {
|
||||
curve_points(c).into_iter().map(|li| points.get(li).and_then(|pi| pos(*pi))).collect::<Option<Vec<_>>>().map(|ps| (c.clone(), ps))
|
||||
})
|
||||
.collect();
|
||||
let fresh: Option<Vec<(LCurve, Vec<Vec2>)>> = lay
|
||||
.curves
|
||||
.iter()
|
||||
.map(|c| curve_points(c).into_iter().map(|li| lay.pts.get(li).copied()).collect::<Option<Vec<_>>>().map(|ps| (*c, ps)))
|
||||
.map(|c| curve_points(c).into_iter().map(|li| lay.pts.get(li).copied()).collect::<Option<Vec<_>>>().map(|ps| (c.clone(), ps)))
|
||||
.collect();
|
||||
let lone_old: Vec<Vec2> = points.iter().filter_map(|pi| pos(*pi)).collect();
|
||||
if let (Some(old), Some(fresh)) = (old, fresh)
|
||||
@@ -1028,6 +1052,11 @@ impl Sketch {
|
||||
{
|
||||
*r = *value;
|
||||
}
|
||||
if let (Some(Curve { kind: CurveKind::Spline { nurbs, .. }, .. }), Some(LCurve::Spline(.., value))) =
|
||||
(self.curves.get_mut(*ci), lay.curves.get(li))
|
||||
{
|
||||
nurbs.clone_from(value);
|
||||
}
|
||||
}
|
||||
return Ok(false);
|
||||
}
|
||||
@@ -1056,6 +1085,9 @@ impl Sketch {
|
||||
if let (LCurve::Ellipse(.., r), Some(Curve { kind: CurveKind::Ellipse { r: slot, .. }, .. })) = (c, self.curves.get_mut(*ci)) {
|
||||
*slot = *r;
|
||||
}
|
||||
if let (LCurve::Spline(.., k), Some(Curve { kind: CurveKind::Spline { nurbs, .. }, .. })) = (c, self.curves.get_mut(*ci)) {
|
||||
nurbs.clone_from(k);
|
||||
}
|
||||
}
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -104,6 +104,10 @@ pub enum CurveKind {
|
||||
/// Explicit cyclic C2 fit interpolation; absent retains natural endpoints.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
periodic: bool,
|
||||
/// A control spline's own knots and weights (a projected free-form edge as the exact
|
||||
/// curve it is); none: the clamped uniform B-spline over its points, all weights 1.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
nurbs: Option<crate::Nurbs>,
|
||||
},
|
||||
/// Conic from `a` to `b` shaped by the `apex` point and `rho` in (0, 1) (0.5 parabola,
|
||||
/// less elliptical, more hyperbolic).
|
||||
@@ -1463,8 +1467,9 @@ impl Sketch {
|
||||
}
|
||||
|
||||
/// Exact boundary segments of a free-form curve: ellipses as four conics, conics, fit
|
||||
/// splines and control splines up to `MAX_BEZIER_DEGREE` as Béziers. None for other curves
|
||||
/// (and for higher-degree splines, which stay polylines).
|
||||
/// splines and control splines up to `MAX_BEZIER_DEGREE` as Béziers (one a knot span for a
|
||||
/// spline with its own knots, conics for a rational quadratic one). None for other curves
|
||||
/// (and for higher-degree or other rational splines, which stay polylines).
|
||||
pub fn exact_segs(&self, ci: usize) -> Option<Vec<Seg2>> {
|
||||
let cu = self.curves.get(ci)?;
|
||||
let pt = |i: &usize| self.point(*i);
|
||||
@@ -1491,7 +1496,11 @@ impl Sketch {
|
||||
crate::curves::fit_beziers_mode(&p, *periodic).ok()?.into_iter().map(|[p0, p1, p2, p3]| Seg2::Cubic { p0, p1, p2, p3 }).collect(),
|
||||
)
|
||||
}
|
||||
CurveKind::Spline { pts, control: true, degree, .. } if (*degree as usize) <= solidcraft_geom::MAX_BEZIER_DEGREE => {
|
||||
CurveKind::Spline { pts, control: true, degree, nurbs: Some(nurbs), .. } => {
|
||||
let p: Vec<Vec2> = pts.iter().map(pt).collect::<Option<_>>()?;
|
||||
nurbs.segs(&p, *degree)
|
||||
}
|
||||
CurveKind::Spline { pts, control: true, degree, nurbs: None, .. } if (*degree as usize) <= solidcraft_geom::MAX_BEZIER_DEGREE => {
|
||||
let p: Vec<Vec2> = pts.iter().map(pt).collect::<Option<_>>()?;
|
||||
let k = (*degree as usize).min(p.len().saturating_sub(1)).max(1);
|
||||
Some(crate::curves::bspline_beziers(&p, k).iter().filter_map(|c| solidcraft_geom::bezier(c)).collect())
|
||||
@@ -1521,9 +1530,9 @@ impl Sketch {
|
||||
(Some(c), Some(m)) => crate::curves::ellipse_polyline(c, m, *r),
|
||||
_ => Vec::new(),
|
||||
},
|
||||
CurveKind::Spline { pts, control, degree, periodic } => {
|
||||
CurveKind::Spline { pts, control, degree, periodic, nurbs } => {
|
||||
let p: Option<Vec<Vec2>> = pts.iter().map(pt).collect();
|
||||
p.map(|p| crate::curves::spline_polyline_mode(&p, *control, *degree, *periodic)).unwrap_or_default()
|
||||
p.map(|p| crate::curves::spline_polyline_mode(&p, *control, *degree, *periodic, nurbs.as_ref())).unwrap_or_default()
|
||||
}
|
||||
CurveKind::Conic { a, b, apex, rho } => match (pt(a), pt(apex), pt(b)) {
|
||||
(Some(a), Some(x), Some(b)) => crate::curves::conic_polyline(a, x, b, *rho),
|
||||
@@ -1559,7 +1568,13 @@ impl Sketch {
|
||||
}
|
||||
"e"
|
||||
}
|
||||
CurveKind::Spline { pts, control, degree, periodic } => {
|
||||
CurveKind::Spline { pts, control, degree, periodic, nurbs } => {
|
||||
if let Some(nurbs) = nurbs {
|
||||
if !*control || *periodic {
|
||||
return Err(SketchError::Invalid("only an open control spline has its own knots".into()));
|
||||
}
|
||||
nurbs.check(pts.len(), *degree)?;
|
||||
}
|
||||
if pts.len() < 2 || pts.len() > crate::curves::MAX_SPLINE_POINTS || !(1..=solidcraft_geom::MAX_BEZIER_DEGREE as u8).contains(degree) {
|
||||
return Err(SketchError::Invalid(format!(
|
||||
"a spline needs 2 to 500 points and degree 1 to {}",
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
//! A control spline's own knots and weights ([`Nurbs`]): the exact form of a free-form edge a
|
||||
//! sketch projects, whose knots need not be evenly spaced and whose weights need not be 1. A
|
||||
//! control spline without them is the clamped uniform B-spline over its points.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solidcraft_geom::bspline::{self, HPoint};
|
||||
use solidcraft_geom::{Seg2, Vec2, Vec3};
|
||||
|
||||
use crate::model::{Result, SketchError};
|
||||
|
||||
/// Most knots a spline may have (its points are capped at [`crate::MAX_SPLINE_POINTS`]).
|
||||
const MAX_KNOTS: usize = crate::curves::MAX_SPLINE_POINTS + solidcraft_geom::MAX_BEZIER_DEGREE + 1;
|
||||
/// Most a weight may exceed another by: past it the curve is all but its heaviest points.
|
||||
const MAX_WEIGHT_RATIO: f64 = 1e12;
|
||||
/// Polyline samples per knot span.
|
||||
const SPAN_SAMPLES: usize = 24;
|
||||
|
||||
/// The knot vector and weights of a control spline of `degree` over `n` points: clamped (each
|
||||
/// end knot `degree + 1` times, no interior knot more than `degree` times), `n + degree + 1`
|
||||
/// non-decreasing knots, and one positive weight per point (none: all 1).
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Nurbs {
|
||||
pub knots: Vec<f64>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub weights: Vec<f64>,
|
||||
}
|
||||
|
||||
fn bad<T>(why: &str) -> Result<T> {
|
||||
Err(SketchError::Invalid(format!("spline knots: {why}")))
|
||||
}
|
||||
|
||||
impl Nurbs {
|
||||
/// Whether these knots and weights fit a control spline of `degree` over `n` points.
|
||||
pub fn check(&self, n: usize, degree: u8) -> Result<()> {
|
||||
let d = usize::from(degree);
|
||||
if !(1..=solidcraft_geom::MAX_BEZIER_DEGREE).contains(&d) || n <= d || n > crate::curves::MAX_SPLINE_POINTS {
|
||||
return bad("a knotted spline needs more points than its degree, 1 to 9");
|
||||
}
|
||||
let k = &self.knots;
|
||||
if k.len() != n + d + 1 || k.len() > MAX_KNOTS {
|
||||
return bad("a spline needs its point count plus its degree plus one knots");
|
||||
}
|
||||
if k.iter().any(|x| !x.is_finite()) || k.windows(2).any(|w| w[1] < w[0]) {
|
||||
return bad("knots must be finite and never decrease");
|
||||
}
|
||||
let (lo, hi) = (k[d], k[n]);
|
||||
let span = hi - lo;
|
||||
if !(span > 0.0 && span.is_finite()) || k[..=d].iter().any(|x| *x != lo) || k[n..].iter().any(|x| *x != hi) {
|
||||
return bad("the knots must be clamped at both ends");
|
||||
}
|
||||
let mut run = 0usize;
|
||||
for (i, x) in k.iter().enumerate().take(n).skip(d + 1) {
|
||||
run = if k.get(i - 1) == Some(x) { run + 1 } else { 1 };
|
||||
if *x == lo || *x == hi || run > d {
|
||||
return bad("no knot inside the spline may repeat more than its degree");
|
||||
}
|
||||
}
|
||||
if !self.weights.is_empty() {
|
||||
if self.weights.len() != n || self.weights.iter().any(|w| !(w.is_finite() && *w > 0.0)) {
|
||||
return bad("a rational spline needs one positive weight per point");
|
||||
}
|
||||
let (min, max) = self.weights.iter().fold((f64::INFINITY, 0.0f64), |(a, b), w| (a.min(*w), b.max(*w)));
|
||||
if max / min > MAX_WEIGHT_RATIO {
|
||||
return bad("the weights differ too much");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn weight(&self, i: usize) -> f64 {
|
||||
self.weights.get(i).copied().unwrap_or(1.0)
|
||||
}
|
||||
|
||||
/// The control points `p` with their weights, homogeneous.
|
||||
fn homogeneous(&self, p: &[Vec2]) -> Vec<HPoint> {
|
||||
p.iter().enumerate().map(|(i, q)| HPoint::weighted(Vec3::new(q.x, q.y, 0.0), self.weight(i))).collect()
|
||||
}
|
||||
|
||||
/// The knot domain `[lo, hi]` for `n` points of `degree`.
|
||||
fn domain(&self, n: usize, degree: usize) -> Option<(f64, f64)> {
|
||||
Some((*self.knots.get(degree)?, *self.knots.get(n)?))
|
||||
}
|
||||
|
||||
/// The same curve run the other way: the knots mirrored, the weights reversed (the points
|
||||
/// reverse with them).
|
||||
pub fn reversed(&self) -> Nurbs {
|
||||
let sum = self.knots.first().copied().unwrap_or(0.0) + self.knots.last().copied().unwrap_or(0.0);
|
||||
Nurbs { knots: self.knots.iter().rev().map(|k| sum - k).collect(), weights: self.weights.iter().rev().copied().collect() }
|
||||
}
|
||||
|
||||
/// The point of the spline over `p` (of `degree`) at `t` in [0, 1] across its knot domain.
|
||||
/// `None` when the knots don't fit the points.
|
||||
pub fn point(&self, p: &[Vec2], degree: u8, t: f64) -> Option<Vec2> {
|
||||
self.check(p.len(), degree).ok()?;
|
||||
let d = usize::from(degree);
|
||||
let (lo, hi) = self.domain(p.len(), d)?;
|
||||
self.eval(&self.homogeneous(p), d, lo + (hi - lo) * t.clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// The point at knot parameter `u` of the spline of degree `d` over the homogeneous points
|
||||
/// `h` (de Boor), the knots already checked.
|
||||
fn eval(&self, h: &[HPoint], d: usize, u: f64) -> Option<Vec2> {
|
||||
let k = &self.knots;
|
||||
let n = h.len();
|
||||
// The span holding u: the last knot ≤ u that starts a non-empty span.
|
||||
let mut s = d;
|
||||
while s + 1 < n && k.get(s + 1).is_some_and(|x| *x <= u) {
|
||||
s += 1;
|
||||
}
|
||||
let mut c: Vec<HPoint> = h.get(s - d..=s)?.to_vec();
|
||||
for r in 1..=d {
|
||||
for j in (r..=d).rev() {
|
||||
let i = s + j - d;
|
||||
let (a, b) = (k.get(i).copied()?, k.get(i + d + 1 - r).copied()?);
|
||||
let alpha = if b > a { (u - a) / (b - a) } else { 0.0 };
|
||||
c[j] = c[j - 1] * (1.0 - alpha) + c[j] * alpha;
|
||||
}
|
||||
}
|
||||
let q = c.get(d)?.project()?;
|
||||
Some(Vec2::new(q.x, q.y))
|
||||
}
|
||||
|
||||
/// The Bézier spans of the spline over `p`, homogeneous, in parameter order: every
|
||||
/// interior knot inserted until it repeats `degree` times (Boehm). Exact up to rounding.
|
||||
fn spans(&self, p: &[Vec2], degree: u8) -> Option<Vec<Vec<HPoint>>> {
|
||||
self.check(p.len(), degree).ok()?;
|
||||
let d = usize::from(degree);
|
||||
let (mut k, mut c) = (self.knots.clone(), self.homogeneous(p));
|
||||
let (lo, hi) = self.domain(p.len(), d)?;
|
||||
let mut interior: Vec<f64> = self.knots.iter().copied().filter(|x| *x > lo && *x < hi).collect();
|
||||
interior.dedup();
|
||||
for u in interior {
|
||||
while k.iter().filter(|x| **x == u).count() < d {
|
||||
(k, c) = bspline::insert_knot(d, &k, &c, u).ok()?;
|
||||
}
|
||||
}
|
||||
let mut spans = Vec::new();
|
||||
for i in d..c.len() {
|
||||
if k.get(i)? < k.get(i + 1)? {
|
||||
spans.push(c.get(i - d..=i)?.to_vec());
|
||||
}
|
||||
}
|
||||
Some(spans)
|
||||
}
|
||||
|
||||
/// The spline over `p` as its exact [`Seg2`] pieces, one a knot span: Béziers, or conics
|
||||
/// for a rational quadratic. `None` for other rational splines, which have no such pieces.
|
||||
pub fn segs(&self, p: &[Vec2], degree: u8) -> Option<Vec<Seg2>> {
|
||||
let spans = self.spans(p, degree)?;
|
||||
let rational = self.weights.windows(2).any(|w| w[0] != w[1]);
|
||||
let flat = |q: &HPoint| q.project().map(|v| Vec2::new(v.x, v.y));
|
||||
spans
|
||||
.iter()
|
||||
.map(|span| {
|
||||
let pts: Vec<Vec2> = span.iter().map(flat).collect::<Option<_>>()?;
|
||||
match (rational, pts.as_slice()) {
|
||||
(false, _) => solidcraft_geom::bezier(&pts),
|
||||
(true, [a, apex, b]) => {
|
||||
let w = span.get(1)?.w / (span.first()?.w * span.get(2)?.w).sqrt();
|
||||
(w.is_finite() && w > 0.0).then_some(Seg2::Conic { a: *a, apex: *apex, b: *b, w })
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The spline over `p`, sampled evenly within each knot span.
|
||||
pub fn polyline(&self, p: &[Vec2], degree: u8) -> Vec<Vec2> {
|
||||
let d = usize::from(degree);
|
||||
let Some((lo, hi)) = self.check(p.len(), degree).ok().and_then(|()| self.domain(p.len(), d)) else { return Vec::new() };
|
||||
let mut breaks: Vec<f64> = self.knots.iter().copied().filter(|x| *x >= lo && *x <= hi).collect();
|
||||
breaks.dedup();
|
||||
let h = self.homogeneous(p);
|
||||
let mut out = Vec::with_capacity(breaks.len() * SPAN_SAMPLES + 1);
|
||||
for w in breaks.windows(2) {
|
||||
for i in 0..SPAN_SAMPLES {
|
||||
out.extend(self.eval(&h, d, w[0] + (w[1] - w[0]) * i as f64 / SPAN_SAMPLES as f64));
|
||||
}
|
||||
}
|
||||
out.extend(self.eval(&h, d, hi));
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Sketch {
|
||||
/// Every spline's own knots and weights fit it: on an open control spline, the right count,
|
||||
/// clamped, with positive weights (a loaded design is checked before it is used).
|
||||
pub fn validate_spline_knots(&self) -> Result<()> {
|
||||
for curve in &self.curves {
|
||||
if let crate::CurveKind::Spline { pts, control, degree, periodic, nurbs: Some(nurbs) } = &curve.kind {
|
||||
if !*control || *periodic {
|
||||
return bad("only an open control spline has its own knots");
|
||||
}
|
||||
nurbs.check(pts.len(), *degree)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ impl Sketch {
|
||||
pub fn validate_periodic_splines(&self) -> Result<()> {
|
||||
let mut work = 0usize;
|
||||
for curve in &self.curves {
|
||||
if let crate::CurveKind::Spline { pts, control, degree, periodic: true } = &curve.kind {
|
||||
if let crate::CurveKind::Spline { pts, control, degree, periodic: true, .. } = &curve.kind {
|
||||
work = work.saturating_add(pts.len());
|
||||
if *control || *degree != 3 || work > 1_000_000 || pts.len() > MAX_SPLINE_POINTS {
|
||||
return Err(bad());
|
||||
@@ -136,7 +136,7 @@ mod tests {
|
||||
(legacy[0][1] - legacy[0][0]).normalized().unwrap().dist((legacy.last().unwrap()[3] - legacy.last().unwrap()[2]).normalized().unwrap())
|
||||
> 0.01
|
||||
);
|
||||
let global = |t| crate::spline_point_mode(&p, false, 3, true, t);
|
||||
let global = |t| crate::spline_point_mode(&p, false, 3, true, None, t);
|
||||
let h = 1e-5;
|
||||
assert!(((global(h) - global(0.0)) / h - (global(1.0) - global(1.0 - h)) / h).len() < 0.002);
|
||||
}
|
||||
@@ -160,8 +160,9 @@ mod tests {
|
||||
let c = sk.add_point(Vec2::new(-4.0, 0.0), None).unwrap();
|
||||
let d = sk.add_point(Vec2::new(-3.0, -2.0), None).unwrap();
|
||||
let last = sk.add_point(Vec2::ZERO, None).unwrap();
|
||||
sk.add_curve(crate::CurveKind::Spline { pts: vec![first, a, b, seam], control: false, degree: 3, periodic: true }, None).unwrap();
|
||||
sk.add_curve(crate::CurveKind::Spline { pts: vec![seam, c, d, last], control: false, degree: 3, periodic: true }, None).unwrap();
|
||||
sk.add_curve(crate::CurveKind::Spline { pts: vec![first, a, b, seam], control: false, degree: 3, periodic: true, nurbs: None }, None)
|
||||
.unwrap();
|
||||
sk.add_curve(crate::CurveKind::Spline { pts: vec![seam, c, d, last], control: false, degree: 3, periodic: true, nurbs: None }, None).unwrap();
|
||||
sk.points[first].pos = Vec2::new(0.2, 0.1);
|
||||
assert!(crate::solve_with(&mut sk, &crate::Hold { points: vec![first], radii: vec![] }, None, crate::Analysis::Full, None).ok());
|
||||
assert_eq!(sk.point(first), sk.point(seam));
|
||||
@@ -186,7 +187,7 @@ mod tests {
|
||||
let p = vec![Vec2::ZERO, Vec2::new(4.0, 0.0), Vec2::new(3.0, 2.0), Vec2::new(-1.0, 1.0), Vec2::ZERO];
|
||||
let mut sk = Sketch::new();
|
||||
let source = crate::LinkSource::SketchCurve { sketch: 99, curve: "source".into() };
|
||||
let geometry = crate::LinkGeom::Spline { pts: p.clone(), control: false, degree: 3, periodic: true };
|
||||
let geometry = crate::LinkGeom::Spline { pts: p.clone(), control: false, degree: 3, periodic: true, nurbs: None };
|
||||
let id = sk.add_link(crate::LinkKind::Project, source, &[geometry]).unwrap();
|
||||
let curve = sk.link_curves(&id)[0];
|
||||
assert!(matches!(sk.curves[curve].kind, crate::CurveKind::Spline { periodic: true, .. }));
|
||||
@@ -197,7 +198,8 @@ mod tests {
|
||||
let mut singular = Sketch::new();
|
||||
let points =
|
||||
[Vec2::ZERO, Vec2::X, Vec2::ZERO, Vec2::new(0.0, 1.0), Vec2::ZERO].into_iter().map(|p| singular.add_point(p, None).unwrap()).collect();
|
||||
let curve = singular.add_curve(crate::CurveKind::Spline { pts: points, control: false, degree: 3, periodic: true }, None).unwrap();
|
||||
let curve =
|
||||
singular.add_curve(crate::CurveKind::Spline { pts: points, control: false, degree: 3, periodic: true, nurbs: None }, None).unwrap();
|
||||
let before = singular.clone();
|
||||
assert!(singular.add_freeform_offset(curve, true, 0.1).is_err());
|
||||
assert_eq!(singular, before);
|
||||
|
||||
@@ -258,9 +258,9 @@ impl State<'_> {
|
||||
};
|
||||
crate::curves::ellipse_polyline(self.p(*ci), self.p(*m), r)
|
||||
}
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic }) => {
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic, nurbs }) => {
|
||||
let p = self.spline_points(pts, *periodic);
|
||||
crate::curves::spline_polyline_mode(&p, *control, *degree, *periodic)
|
||||
crate::curves::spline_polyline_mode(&p, *control, *degree, *periodic, nurbs.as_ref())
|
||||
}
|
||||
Some(CurveKind::Conic { a, b, apex, rho }) => crate::curves::conic_polyline(self.p(*a), self.p(*apex), self.p(*b), *rho),
|
||||
_ => Vec::new(),
|
||||
@@ -293,12 +293,14 @@ impl State<'_> {
|
||||
let y = delta.cross(u) / (a * r);
|
||||
return (x.hypot(y) - 1.0) * a.min(r);
|
||||
}
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic }) => {
|
||||
Some(CurveKind::Spline { pts, control, degree, periodic, nurbs }) => {
|
||||
let p = self.spline_points(pts, *periodic);
|
||||
if p.len() < 2 {
|
||||
return q.dist(p.first().copied().unwrap_or_default());
|
||||
}
|
||||
if *control {
|
||||
if let Some(nurbs) = nurbs {
|
||||
nurbs.segs(&p, *degree).unwrap_or_default()
|
||||
} else if *control {
|
||||
let k = (*degree as usize).min(solidcraft_geom::MAX_BEZIER_DEGREE).min(p.len().saturating_sub(1)).max(1);
|
||||
crate::curves::bspline_beziers(&p, k).iter().filter_map(|span| solidcraft_geom::bezier(span)).collect()
|
||||
} else {
|
||||
@@ -393,10 +395,10 @@ impl State<'_> {
|
||||
let (cc, r) = self.round(c);
|
||||
(cc - self.p(p)) / (r * r).max(1e-24)
|
||||
}
|
||||
CurveKind::Spline { pts, control, degree, periodic } => {
|
||||
CurveKind::Spline { pts, control, degree, periodic, nurbs } => {
|
||||
let q = self.spline_points(pts, *periodic);
|
||||
let at_end = pts.last() == Some(&p) && pts.first() != Some(&p);
|
||||
crate::curves::end_curvature(&|t| crate::curves::spline_point_mode(&q, *control, *degree, *periodic, t), at_end)
|
||||
crate::curves::end_curvature(&|t| crate::curves::spline_point_mode(&q, *control, *degree, *periodic, nurbs.as_ref(), t), at_end)
|
||||
}
|
||||
CurveKind::Conic { a, b, apex, rho } => {
|
||||
let (pa, pb, px) = (self.p(*a), self.p(*b), self.p(*apex));
|
||||
@@ -2938,7 +2940,7 @@ fn solve_inner(
|
||||
}
|
||||
}
|
||||
for curve in &sk.curves {
|
||||
if let CurveKind::Spline { pts, control, degree, periodic: true } = &curve.kind {
|
||||
if let CurveKind::Spline { pts, control, degree, periodic: true, .. } = &curve.kind {
|
||||
let points = pts.iter().map(|i| positions.get(*i).copied()).collect::<Option<Vec<_>>>();
|
||||
if *control || *degree != 3 || points.as_ref().is_none_or(|p| crate::periodic::validate_periodic_points(p).is_err()) {
|
||||
valid = false;
|
||||
|
||||
@@ -657,7 +657,7 @@ fn near_overlaps_that_are_not_one_path_keep_their_regions() {
|
||||
.iter()
|
||||
.map(|p| sk.add_point(*p, None).unwrap())
|
||||
.collect();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: true, degree: 3, periodic: false }, None).unwrap();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: true, degree: 3, periodic: false, nurbs: None }, None).unwrap();
|
||||
sk.add_line_pts(ids[3], ids[0], None).unwrap();
|
||||
let ps = find_profiles(&sk);
|
||||
assert_eq!(ps.len(), 1, "{:?}", ps.iter().map(|p| p.area).collect::<Vec<_>>());
|
||||
@@ -953,7 +953,7 @@ fn exact_profiles_for_high_degree_and_cut_free_form_curves() {
|
||||
.iter()
|
||||
.map(|p| sk.add_point(*p, None).unwrap())
|
||||
.collect();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: true, degree: 5, periodic: false }, None).unwrap();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: true, degree: 5, periodic: false, nurbs: None }, None).unwrap();
|
||||
sk.add_line_pts(ids[5], ids[0], None).unwrap();
|
||||
let pr = find_profiles(&sk);
|
||||
assert_eq!(pr.len(), 1);
|
||||
@@ -962,7 +962,7 @@ fn exact_profiles_for_high_degree_and_cut_free_form_curves() {
|
||||
// A fit spline arch over a base line, cut by a vertical line at x = 10.
|
||||
let mut sk = Sketch::default();
|
||||
let ids: Vec<usize> = [v(0.0, 0.0), v(6.0, 9.0), v(14.0, 9.0), v(20.0, 0.0)].iter().map(|p| sk.add_point(*p, None).unwrap()).collect();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: false, degree: 3, periodic: false }, None).unwrap();
|
||||
sk.add_curve(CurveKind::Spline { pts: ids.clone(), control: false, degree: 3, periodic: false, nurbs: None }, None).unwrap();
|
||||
sk.add_line_pts(ids[3], ids[0], None).unwrap();
|
||||
let (a, b) = (sk.add_point(v(10.0, -5.0), None).unwrap(), sk.add_point(v(10.0, 20.0), None).unwrap());
|
||||
sk.add_line_pts(a, b, None).unwrap();
|
||||
@@ -1033,7 +1033,7 @@ fn a_degree_nine_control_spline_stays_exact_and_closes_a_profile_exactly() {
|
||||
let bump =
|
||||
[v(0.0, 0.0), v(1.5, 4.0), v(3.0, 7.0), v(5.0, 9.5), v(7.5, 11.0), v(12.5, 11.0), v(15.0, 9.5), v(17.0, 7.0), v(18.5, 4.0), v(20.0, 0.0)];
|
||||
let pts: Vec<usize> = bump.iter().map(|q| sk.add_point(*q, None).unwrap()).collect();
|
||||
let s = sk.add_curve(CurveKind::Spline { pts: pts.clone(), control: true, degree: 9, periodic: false }, None).unwrap();
|
||||
let s = sk.add_curve(CurveKind::Spline { pts: pts.clone(), control: true, degree: 9, periodic: false, nurbs: None }, None).unwrap();
|
||||
let pieces = sk.exact_pieces(s);
|
||||
assert_eq!(pieces.len(), 1, "{pieces:?}");
|
||||
let Seg2::Bezier { n, p } = pieces[0] else { panic!("{:?}", pieces[0]) };
|
||||
@@ -1068,7 +1068,7 @@ fn a_degree_nine_control_spline_stays_exact_and_closes_a_profile_exactly() {
|
||||
// A degree above the cap is still refused.
|
||||
let mut high: Vec<usize> = pts.clone();
|
||||
high.push(sk.add_point(v(21.0, -2.0), None).unwrap());
|
||||
assert!(sk.add_curve(CurveKind::Spline { pts: high, control: true, degree: 10, periodic: false }, None).is_err());
|
||||
assert!(sk.add_curve(CurveKind::Spline { pts: high, control: true, degree: 10, periodic: false, nurbs: None }, None).is_err());
|
||||
}
|
||||
|
||||
/// #755: a line drawn through a junction of a loop, but 2e-5 off it, still splits the loop. The
|
||||
@@ -1295,3 +1295,67 @@ fn bounds_reach_the_extremes_of_circles_and_arcs() {
|
||||
let (lo, hi) = sk.bounds().unwrap();
|
||||
assert!(lo.dist(v(0.0, 0.0)) < 1e-9 && hi.dist(v(10.0, 10.0)) < 1e-9, "{lo:?} {hi:?}");
|
||||
}
|
||||
|
||||
/// A control spline with its own knots and weights (a projected free-form edge): its exact pieces
|
||||
/// are its knot spans, a rational quadratic's are conics, its points follow its knots, it reads
|
||||
/// back from a saved design the same, and knots that don't fit it are refused.
|
||||
#[test]
|
||||
fn a_spline_with_its_own_knots_is_its_spans_exactly() {
|
||||
let mut sk = Sketch::new();
|
||||
// Two cubic Béziers end to end (the joint knot three times), the second twice as long in
|
||||
// parameter: (0,0) (1,2) (2,2) (3,0) then (3,0) (4,-2) (5,-2) (6,0).
|
||||
let ctrl = [v(0.0, 0.0), v(1.0, 2.0), v(2.0, 2.0), v(3.0, 0.0), v(4.0, -2.0), v(5.0, -2.0), v(6.0, 0.0)];
|
||||
let nurbs = Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() };
|
||||
let pts: Vec<usize> = ctrl.iter().map(|q| sk.add_point(*q, None).unwrap()).collect();
|
||||
let kind = CurveKind::Spline { pts: pts.clone(), control: true, degree: 3, periodic: false, nurbs: Some(nurbs.clone()) };
|
||||
let s = sk.add_curve(kind.clone(), None).unwrap();
|
||||
let pieces = sk.exact_pieces(s);
|
||||
assert_eq!(pieces.len(), 2, "{pieces:?}");
|
||||
let Seg2::Cubic { p0, p1, p2, p3 } = pieces[1] else { panic!("{:?}", pieces[1]) };
|
||||
for (got, want) in [(p0, ctrl[3]), (p1, ctrl[4]), (p2, ctrl[5]), (p3, ctrl[6])] {
|
||||
assert!(got.dist(want) < 1e-12, "{got:?} {want:?}");
|
||||
}
|
||||
// t runs over the knots: a third of the way is the joint, where the uniform spline over the
|
||||
// same points would not be.
|
||||
assert!(nurbs.point(&ctrl, 3, 1.0 / 3.0).unwrap().dist(ctrl[3]) < 1e-12);
|
||||
assert!(crate::curves::spline_point(&ctrl, true, 3, 1.0 / 3.0).dist(ctrl[3]) > 1e-3);
|
||||
let back = nurbs.reversed();
|
||||
let rev: Vec<Vec2> = ctrl.iter().rev().copied().collect();
|
||||
for k in 0..=12 {
|
||||
let t = k as f64 / 12.0;
|
||||
assert!(nurbs.point(&ctrl, 3, t).unwrap().dist(back.point(&rev, 3, 1.0 - t).unwrap()) < 1e-12, "t={t}");
|
||||
}
|
||||
let poly = sk.polyline(s);
|
||||
assert!(poly.first().unwrap().dist(ctrl[0]) < 1e-12 && poly.last().unwrap().dist(ctrl[6]) < 1e-12);
|
||||
// Saved and read back: the same curve.
|
||||
let json = serde_json::to_string(&kind).unwrap();
|
||||
assert_eq!(serde_json::from_str::<CurveKind>(&json).unwrap(), kind);
|
||||
// A quarter circle of radius 2 as a rational quadratic: one conic, its middle point on the circle.
|
||||
let w = std::f64::consts::FRAC_1_SQRT_2;
|
||||
let quarter = Nurbs { knots: vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0], weights: vec![1.0, w, 1.0] };
|
||||
let arc = [v(2.0, 0.0), v(2.0, 2.0), v(0.0, 2.0)];
|
||||
let [Seg2::Conic { w: cw, .. }] = quarter.segs(&arc, 2).unwrap()[..] else { panic!("conic") };
|
||||
assert!((cw - w).abs() < 1e-12);
|
||||
assert!((quarter.point(&arc, 2, 0.5).unwrap().len() - 2.0).abs() < 1e-12);
|
||||
// Knots that don't fit: the wrong count, not clamped, decreasing, not finite, an interior knot
|
||||
// past the degree, a weight that isn't positive; and knots on a fit spline.
|
||||
let bad = [
|
||||
Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0], weights: Vec::new() },
|
||||
Nurbs { knots: vec![0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() },
|
||||
Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, 2.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() },
|
||||
Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, f64::NAN, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() },
|
||||
Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() },
|
||||
Nurbs { knots: nurbs.knots.clone(), weights: vec![1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0] },
|
||||
];
|
||||
for (i, k) in bad.iter().enumerate() {
|
||||
assert!(k.check(ctrl.len(), 3).is_err(), "{i}");
|
||||
assert!(
|
||||
sk.add_curve(CurveKind::Spline { pts: pts.clone(), control: true, degree: 3, periodic: false, nurbs: Some(k.clone()) }, None).is_err(),
|
||||
"{i}"
|
||||
);
|
||||
assert!(k.point(&ctrl, 3, 0.5).is_none() && k.segs(&ctrl, 3).is_none() && k.polyline(&ctrl, 3).is_empty(), "{i}");
|
||||
}
|
||||
let fourfold = Nurbs { knots: vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0], weights: Vec::new() };
|
||||
assert!(fourfold.check(8, 3).is_err());
|
||||
assert!(sk.add_curve(CurveKind::Spline { pts, control: false, degree: 3, periodic: false, nurbs: Some(nurbs) }, None).is_err());
|
||||
}
|
||||
@@ -53,7 +53,7 @@ impl Outline {
|
||||
self.line(to);
|
||||
return;
|
||||
}
|
||||
self.out.push(LinkGeom::Spline { pts: vec![a, c1, c2, b], control: true, degree: 3, periodic: false });
|
||||
self.out.push(LinkGeom::Spline { pts: vec![a, c1, c2, b], control: true, degree: 3, periodic: false, nurbs: None });
|
||||
self.cur = to;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ fn outline_sketch(boundary: &[Seg2]) -> Result<Sketch> {
|
||||
}
|
||||
Seg2::Cubic { p0, p1, p2, p3 } => {
|
||||
let pts = [p0, p1, p2, p3].iter().map(|p| sk.add_point(*p, None)).collect::<Result<Vec<_>>>()?;
|
||||
sk.add_curve(CurveKind::Spline { pts, control: true, degree: 3, periodic: false }, None)?;
|
||||
sk.add_curve(CurveKind::Spline { pts, control: true, degree: 3, periodic: false, nurbs: None }, None)?;
|
||||
}
|
||||
_ => return Err(bad("not supported yet: this kind of wall curve")),
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ fn curve_centres_and_spline_interior_points_are_used_and_invalid_incidence_is_sa
|
||||
let last = point(&mut sk, 21., 21.);
|
||||
let mut spline = sk.curves[a].clone();
|
||||
spline.id = "interior_spline".into();
|
||||
spline.kind = CurveKind::Spline { pts: vec![first, interior, last], control: false, degree: 3, periodic: false };
|
||||
spline.kind = CurveKind::Spline { pts: vec![first, interior, last], control: false, degree: 3, periodic: false, nurbs: None };
|
||||
sk.curves.push(spline);
|
||||
for p in [centre, interior] {
|
||||
for c in [a, b] {
|
||||
@@ -91,7 +91,7 @@ fn oversized_reference_input_is_refused_without_scanning_or_mutating_it() {
|
||||
let mut sk = Sketch::new();
|
||||
let a = sk.add_line(Vec2::new(0., 1.), Vec2::new(2., 1.), None, None, None).unwrap();
|
||||
let before = sk.points.clone();
|
||||
sk.curves[a].kind = CurveKind::Spline { pts: vec![usize::MAX; 1_000_001], control: false, degree: 3, periodic: false };
|
||||
sk.curves[a].kind = CurveKind::Spline { pts: vec![usize::MAX; 1_000_001], control: false, degree: 3, periodic: false, nurbs: None };
|
||||
assert!(sk.virtual_corners().is_empty());
|
||||
assert_eq!(sk.points, before);
|
||||
assert_eq!(sk.curves[a].kind.point_ids().len(), 1_000_001);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Rust target, SHA-256 of smlib-<target>.tar.gz in the release prebuilt-<SMLIB_REV> of
|
||||
# tangency-labs/smlib. Written by scripts/fetch-smlib.sh --pin; never edited by hand.
|
||||
aarch64-apple-darwin d88d464dc6bee7f571a3dd489f3d3d5378c70c70ab43c8076b8f8d051c0c2413
|
||||
aarch64-pc-windows-msvc 492fb4d4f89d3330f520f8284123d8bea97a44340583e74d3a3f360197f683d6
|
||||
aarch64-unknown-linux-gnu 03f9ed4de21e32301e08d54d916b06a0520c99b2c990bf445e0f624b134dcd49
|
||||
i686-pc-windows-msvc f7bb4c871b82d2a33e0a173abe446351b00d06ae877e4f0a9681b561c686d320
|
||||
wasm32-unknown-unknown b9a556940efd1ac774c630a4634e170f0d66e004021d3af43598c72bf640f2d0
|
||||
x86_64-apple-darwin cd96282ce6f6a3660c266b0b9a9ef15015b2af3328e88baca699906f50a4d5c9
|
||||
x86_64-pc-windows-msvc fd9f752fe5398eccc21c4b1fd4a48f31cf0bcad2c1408e514308a6e5ec39ef06
|
||||
x86_64-unknown-linux-gnu a778927cd0f163cfededb2c3e34e43c04612dd8f0a1770e36f2de8eabaa7cd77
|
||||
aarch64-apple-darwin 3a782c2d9f89878fcb19c0ea9dfc29853204a6f6af37576722ed6334b06552c0
|
||||
aarch64-pc-windows-msvc f7a5cbe28c65a8d9dd88e22939ac3c12d5b54431ad16f1b0a1f6aa5882de2b9d
|
||||
aarch64-unknown-linux-gnu bb1166f65589ce2c385550708992d0798e010d6689952ae07232aeec438e5879
|
||||
i686-pc-windows-msvc cadf6d7c35b3e20345e064d4369c777d62561afac5cf5b7be52da6dd6f9aa785
|
||||
wasm32-unknown-unknown 250573fd99e9b109ae9f8ac16ecd4a5e55dfcd13c060763c89167bc2ee4bd4b8
|
||||
x86_64-apple-darwin 13cf77518ccbd9a3095e0d2eaabb7844c94079aa4ef88ef10fe5a2bf1eb18438
|
||||
x86_64-pc-windows-msvc 44b729d524b85de5b0aba2f24cdb6a9e449d644ef3ea4129dabbf5338b835018
|
||||
x86_64-unknown-linux-gnu 7fe1a151932370b6ab4dee1e3fad30f62e4b9d2a1ac7bd1ca423061a15276a09
|
||||
@@ -1 +1 @@
|
||||
2fc375f4836c25cc87a4b2ee9082a2419f78939a
|
||||
26cc45185b7ee6faba5b684f83d7bc2c53c1a559
|
||||
@@ -260,7 +260,7 @@ pub(crate) fn fixes() -> UpstreamFixes {
|
||||
}
|
||||
|
||||
/// Opt-in fixes left off because the C++ fork (`SMLIB_REV`) does not behave as they do, so turning
|
||||
/// them on would part this backend from the C++ one. Each was read in the fork's source at 2fc375f.
|
||||
/// them on would part this backend from the C++ one. Each was read in the fork's source at 26cc451.
|
||||
///
|
||||
/// Upstream's defect is still there: `precise_properties_trim_base_v` (WR-563: `SmODEAreaIFEO` starts
|
||||
/// at the domain's lowest v), `fillet_blend_curve_revolved_on_arc` (WR-581: `CalcTorusFilletGeom` takes
|
||||
@@ -310,7 +310,7 @@ pub(crate) fn fixes() -> UpstreamFixes {
|
||||
/// `geometric_g2_continuity`: no fork commit; the C++ still has the defect at SmGeomUtility.cpp:5822
|
||||
/// (crashes/2992: 183 faces against 831).
|
||||
///
|
||||
/// Upstream's defect is still in the fork's source at `SMLIB_REV` 2fc375f:
|
||||
/// Upstream's defect is still in the fork's source at `SMLIB_REV` 26cc451:
|
||||
/// `fillet_corner_variable_radius_rail_on_opposite_fillet` (WR-645: `MakeVariableRadiusFillet` has
|
||||
/// only the concave corner's rail-rail test before resetting the edges, no test of the rail against
|
||||
/// the opposite fillet), `sphere_from_arcs_common_centre` (WR-103: `CreateSphereFromArcs` compares
|
||||
|
||||
@@ -976,6 +976,7 @@ pub(crate) fn preview_curve(
|
||||
control: t.cmd != "sketch.spline.fit_point",
|
||||
degree: if t.cmd == "sketch.spline.control_point_5" { 5 } else { 3 },
|
||||
periodic,
|
||||
nurbs: None,
|
||||
},
|
||||
None,
|
||||
)
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
# for junit and junit-gpu-1..4), run `cargo xtask known-failing --junit <dir>`, then drop each
|
||||
# FIXED line and add each REGRESSION line with its cause, from the test's failure message.
|
||||
# Baseline: develop 38fd4a4f6 (CI run 41157648345, x86_64 Linux), after the SMLib eaa998a pin.
|
||||
solidcraft-cli::action_matrix::action_matrix_sample 7 baseline actions fail on SMLib: 4 shells (status 1001 x3; Bad Loop Orient on issue-616-lid-ribs), 2 chamfers (status 1001 on up-down-join; not a closed solid on modern-plastic), 1 fillet (SmSurfOfRevolution Test #7 on oblique_cut_of_cylinder)
|
||||
solidcraft-cli::action_matrix::action_matrix_sample 3 baseline actions fail on SMLib: 2 shells (Bad Loop Orient on issue-616-lid-ribs; status 1001 on filleted-shelled-box, shelled again open at an inner wall), 1 fillet (SmSurfOfRevolution Test #7 on oblique_cut_of_cylinder)
|
||||
solidcraft-cli::naming_corpus::corpus_designs_name_alike_every_build_and_fail_where_a_reference_is_gone oracle/83-boundary-loop-thicken does not load: step 8, SMLib thicken status 1001
|
||||
solidcraft-engine::tests::fillet_fit_taper_closes_to_a_point SMLib fillet status 1001 on the taper fit (radius 16 closing to 0)
|
||||
solidcraft-engine::tests::robustness::shell_after_a_cut_whose_end_touches_an_arc_side SMLib shell status 1001 (a heavy test: pushes and nightly only)
|
||||
solidcraft-kernel::blend::corner_tests::a_round_ending_in_an_earlier_round_matches_both_together SMLib fillet status 1001 on the round that ends in the earlier one
|
||||
solidcraft-kernel::blend::corner_tests::corner_blends_hold_at_any_scale at 0.01x the arc case's rounds remove 72.783 (scaled back) against 72.713 at 1x (9.6e-4 off, 1e-4 allowed)
|
||||
solidcraft-kernel::blend_corner::tests::issue2422_vertical_after_separate_bottom_rounds SMLib's check refuses the fillet: edge and vertex tolerance 0.97 against the body's 0.01 (#2422)
|
||||
solidcraft-kernel::corner_g2::tests::a_long_setback_keeps_the_g2_patch_inside_the_box at set backs 11 to 15 the G2 corner patch bulges 2.6e-6 to 1.33e-3 past the box (the explicit corner is in progress)
|
||||
solidcraft-kernel::corner_g2::tests::the_box_corner_g2_patch_is_a_closed_solid_curvature_continuous_to_its_neighbours the fitted G2 corner patch bulges 1.7e-5 past the box, which SMLib's exact tight box now sees (the explicit G2 corner builds it inside)
|
||||
solidcraft-kernel::step_in::tests::non_antipodal_seam_sphere_imports_as_a_whole_ball the import refuses the ball: its face's loop, a meridian slit from the pole run out and back, encloses no (u, v) area, so the whole sphere less a slit is not read as the sphere
|
||||
solidcraft-kernel::tests::fillet_tabbed_plate_outer_loop_and_partial_selection_after_hole the arc and tab rounds together remove 9.20067 against 9.20420 (3.8e-4 off, 1e-5 allowed)
|
||||
@@ -126,6 +126,7 @@ the frozen truck-geometry PRs, a `kernel-paused` PR), for the report's coverage
|
||||
| `body_count`, `faces`, `edges`, `vertices` | Exact counts, where the geometry fixes them. Faces and edges count whole analytic surfaces and curves once (a full cylinder side is one face). |
|
||||
| `volume_mm3`, `area_mm2`, `center_of_mass`, `bbox` | As in `tests/oracle`: totals over every body, relative tolerance 1e-3 for volume and area, 1e-3 of the box diagonal for positions. |
|
||||
| `faces`, `edges`, `vertices`, `shells`, `body_count` as `[min, max]` | An inclusive range, where the geometry only bounds a count (a modelled thread's faces). |
|
||||
| `volume_mm3`, `area_mm2` as `[min, max]` | An inclusive range, where analysis only bounds the measure: a cut removes at most its tool's volume, a join adds at most the tool's. `method` derives both ends. |
|
||||
| `continuity` | `{order, edges}`: every seam `edges` names reaches `order` (`g0` … `g4`), as Continuity Analysis (`inspect.continuity`) measures it: from the faces' exact surfaces, at its default 33 stations a seam and its default tolerances (1 µm, 1°, 0.01 / mm, 0.001 / mm², 0.0001 / mm³), never loosened per case. A failure names the worst seam (lowest order; of those, the one furthest past the next order's tolerance), its faces, the order it reaches and that next order's worst value. `edges`: `blend` (default), every seam of a face a fillet or chamfer made (a round, a chamfer face or a corner patch) with the faces either side of the edge it replaced, and every seam of a corner patch with the rounds it joins: what the blend is built to meet (not where a round runs into an end face, nor where two rounds meet without a patch: that seam is the input's, tangent only where the rounded edges were); `corner`, those of them on a corner patch (a blend made from several replaced edges); or a list of points `[[x,y,z], …]`, the edges nearest them, as Continuity Analysis picks them. `exact: true`: every seam reaches `order` and not the next (a case built to an order proves the measurement reads that order, no more and no less). A constant round meets its faces G1 (curvature jumps by 1 / r), a `curvature` round G2, a chamfer G0; a `corner: g2` patch is built G2 to the rounds and faces round it. |
|
||||
| `continuity` (older form) | `{near, within_mm, clear_mm, curvature_jump_per_mm}`: over every tangent seam lying wholly within `within_mm` of `near` (a corner's patch and its neighbours), the curvature jump across it (the faces' normal curvatures square to the seam, from their exact surfaces, at 65 stations a seam) is at most `curvature_jump_per_mm` at every station at least `clear_mm` along the seam from a vertex where two of those seams turn (where a neighbour's own G1 seam ends, which no surface is G2 to both sides of). A rolling ball's corner jumps 1 / r everywhere. |
|
||||
| `surface_types` | The set of kinds the faces' surfaces are, over every body, as the records hold them: `plane`, `cylinder`, `cone`, `sphere`, `torus`, `bspline` (a B-spline or NURBS surface) or `revolution` (a revolved curve). Exact: none missing, none extra. |
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"sources": [],
|
||||
"what": "a knife follower on an eccentric disc cam, the cam turned 180 degrees",
|
||||
"source": "analytic",
|
||||
"method": "an eccentric disc cam (radius 10, centre 5 off its shaft on z through the origin) with a knife follower on a slider along +x through the shaft, touching at x = 15; the knife's distance at cam turn \u03c6 is s(\u03c6) = e cos \u03c6 + \u221a(R\u00b2 - e\u00b2 sin\u00b2 \u03c6) (e 5, R 10): rise s(0) - s(180) = 15 - 5 = 10; at 180 the knife is at s = 5, 10 mm in: the tappet's centre (20,0,2.5) -> (10,0,2.5)",
|
||||
"body_count": 3,
|
||||
"volume_mm3": 5770.796,
|
||||
"results": [
|
||||
{
|
||||
"step": 13,
|
||||
"json": {
|
||||
"lift": {
|
||||
"rise": 10.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"step": 15,
|
||||
"json": {
|
||||
"total": {
|
||||
"center_of_mass": [
|
||||
10.0,
|
||||
0.0,
|
||||
2.5
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 20,
|
||||
"width": 20,
|
||||
"height": 10,
|
||||
"corner": [
|
||||
-10,
|
||||
-10,
|
||||
-10
|
||||
],
|
||||
"operation": "new",
|
||||
"body_name": "BaseBox"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.cylinder",
|
||||
"params": {
|
||||
"radius": 10,
|
||||
"height": 5,
|
||||
"base": [
|
||||
5,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"axis": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"operation": "new",
|
||||
"body_name": "Disc"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 10,
|
||||
"width": 4,
|
||||
"height": 5,
|
||||
"corner": [
|
||||
15,
|
||||
-2,
|
||||
0
|
||||
],
|
||||
"operation": "new",
|
||||
"body_name": "Tappet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.create",
|
||||
"params": {
|
||||
"name": "Base",
|
||||
"parent": "root",
|
||||
"activate": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.move_bodies",
|
||||
"params": {
|
||||
"bodies": [
|
||||
"BaseBox"
|
||||
],
|
||||
"component": "Base"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.create",
|
||||
"params": {
|
||||
"name": "Cam",
|
||||
"parent": "root",
|
||||
"activate": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.move_bodies",
|
||||
"params": {
|
||||
"bodies": [
|
||||
"Disc"
|
||||
],
|
||||
"component": "Cam"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.create",
|
||||
"params": {
|
||||
"name": "Follower",
|
||||
"parent": "root",
|
||||
"activate": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "component.move_bodies",
|
||||
"params": {
|
||||
"bodies": [
|
||||
"Tappet"
|
||||
],
|
||||
"component": "Follower"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "occurrence.ground",
|
||||
"params": {
|
||||
"occurrence": "Base:1",
|
||||
"grounded": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "joint.create",
|
||||
"params": {
|
||||
"type": "revolute",
|
||||
"name": "Shaft",
|
||||
"flip": true,
|
||||
"a": {
|
||||
"occurrence": "Base",
|
||||
"point": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"z": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
},
|
||||
"b": {
|
||||
"occurrence": "Cam",
|
||||
"point": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"z": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
},
|
||||
"quiet": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "joint.create",
|
||||
"params": {
|
||||
"type": "slider",
|
||||
"name": "Lift",
|
||||
"flip": true,
|
||||
"a": {
|
||||
"occurrence": "Base",
|
||||
"point": [
|
||||
15,
|
||||
0,
|
||||
2.5
|
||||
],
|
||||
"z": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
]
|
||||
},
|
||||
"b": {
|
||||
"occurrence": "Follower",
|
||||
"point": [
|
||||
15,
|
||||
0,
|
||||
2.5
|
||||
],
|
||||
"z": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
]
|
||||
},
|
||||
"quiet": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "joint.cam",
|
||||
"params": {
|
||||
"a": "Shaft",
|
||||
"b": "Lift",
|
||||
"profile": {
|
||||
"edges": [
|
||||
[
|
||||
15,
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"occurrence": "Cam"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "joint.drive",
|
||||
"params": {
|
||||
"joint": "Shaft",
|
||||
"quiet": true,
|
||||
"value": 180
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "occurrence.properties",
|
||||
"params": {
|
||||
"occurrence": "Follower:1"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#168"
|
||||
"tangency-labs/solidcraft#168",
|
||||
"tangency-labs/solidcraft#3841"
|
||||
],
|
||||
"what": "a rim on a coin's top face that meets the coin along one circle only (no shared area, no shared volume): it must not be joined into it",
|
||||
"source": "analytic",
|
||||
|
||||
@@ -3,7 +3,20 @@
|
||||
"tangency-labs/solidcraft#3243"
|
||||
],
|
||||
"what": "a join of a cylindrical rim (r 15.27..16.65, to z=5) and a rounded tooth trimmed to the same two cylinders that overlaps it by 0.01 mm in Z",
|
||||
"source": "invariants",
|
||||
"method": "the tooth (z 4.99..7.7) and the rim (z 1.76..5) overlap in z 4.99..5 with positive volume, so the join succeeds and gives one closed solid; the result is larger than the rim alone. No closed form is derived for the tooth, so only the outcome, validity and the body count are graded",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "rim: pi*16.65^2*5 - pi*15.27^2*(5 - 1.76) = 1981.190. Tooth: the profile (flanks from x = +-3 at z 4.99 to x = +-0.1706 at z 7.6327, tip arc through (0, 7.7): centre z 7.45012, radius 0.24988) extruded along +y from y 14.9624 (inside r 15.27 for every |x| <= 3, as sqrt(15.27^2 - 9) = 14.9724) to y 16.65 (outside r 16.65), so trimming to the two cylinders leaves exactly {15.27 <= r <= 16.65} over the profile: V = int over the profile of sqrt(16.65^2 - x^2) - sqrt(15.27^2 - x^2) dx dz = 11.6193 (Simpson, converged to 1e-6). The part of it below z 5 (z 4.99..5) lies inside the rim: 0.0831. Join: 1981.190 + 11.619 - 0.083 = 1992.726 (a join that dropped the tooth gives 1981.19, outside the tolerance). Box: the rim's r 16.65 disc, z 0 to the tooth tip 7.7",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 1992.726,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-16.65,
|
||||
-16.65,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
16.65,
|
||||
16.65,
|
||||
7.7
|
||||
]
|
||||
}
|
||||
}
|
||||
+19
-3
@@ -4,7 +4,23 @@
|
||||
"tangency-labs/solidcraft#3613"
|
||||
],
|
||||
"what": "cut of a box by a swept G2 corner-removal tool along a projected edge chain (left-rear corner; the symmetric front-left chain works)",
|
||||
"source": "invariants",
|
||||
"method": "no closed form for the free-form tool: the tool lies on the box's bottom edge and overlaps it, so the cut must succeed with one valid closed solid (the tool is consumed). No volume is graded",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "fillet: the documented curvature section, the quintic Bezier on setback s = 5 (controls p+s t1, p+2s/3 t1, p+s/3 t1, p+s/3 t2, p+2s/3 t2, p+s t2), cuts 113/21 * 25/36 = 3.73677 mm^2 off each vertical edge (Green on the Bezier): Vf = 8000 - 4*10*3.73677 = 7850.529. Tool section: the G2 blend between two lines is the degree 5 Hermite Bezier of the lines' own derivatives, controls (0.8,0) (0.8,0.04) (0.8,0.08) (0.08,0.8) (0.04,0.8) (0,0.8); the part of the profile in the material quadrant has area a = 0.360667 and first moment about the wall S = 0.102152. Swept along the corner curve (length 8.21299, total turn pi/2, curvature at most 0.269, so 1 - k*0.8 > 0 and the tube does not fold), it removes a*L - S*pi/2 = 2.8015; along l3, a straight bottom edge next to that corner (10 long on the left, 30 on the rear: the chain's naming fixes which, analysis does not), a*10 = 3.6067 or a*30 = 10.820. V lies between 7850.529 - 13.622 = 7836.907 and 7850.529 - 6.408 = 7844.121, widened by 1e-4 relative for the measurement: a cut that did nothing (7850.53) or a fillet not made falls outside. Box: the 40 x 20 x 10 box's (the fillets and the cut leave every extreme face)",
|
||||
"body_count": 1,
|
||||
"volume_mm3": [
|
||||
7836.1,
|
||||
7844.9
|
||||
],
|
||||
"bbox": {
|
||||
"min": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
40.0,
|
||||
20.0,
|
||||
10.0
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,22 @@
|
||||
"tangency-labs/solidcraft#3425"
|
||||
],
|
||||
"what": "emboss on a cylinder with the face pick on the half of the wall opposite the sketch",
|
||||
"source": "invariants",
|
||||
"method": "the cylinder wall is one logical face, so a pick anywhere on it (between the caps) must be accepted: the emboss succeeds with one valid closed solid. No volume is graded (the badge's shape on a curved wall is not fixed by the issue)",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the cylinder wall is one logical face, so a pick anywhere on it (between the caps) must be accepted. Emboss on a cylinder wraps the sketch's arc length round the wall from the sketch plane's line of tangency (y = 10) and raises it radially: the 4 x 5 badge spans 4 / 10 = 0.4 rad about +y, z 5..10, from r 10 to r 11. Volume: pi*10^2*20 + (0.4/2)*(11^2 - 10^2)*5 = 2000 pi + 21 = 6304.185. Area: 600 pi, less the wall under the badge 0.4*10*5 = 20, plus its cap 0.4*11*5 = 22, two radial side walls 1*5 each and two end walls (0.4/2)*(11^2 - 10^2) = 4.2 each: 600 pi + 20.4 = 1905.356. Faces: the wall (with the badge's hole), two caps, the badge's cap and its four walls = 8. Box: the cylinder's, with y to 11 (the badge's cap at its middle; it spans x = +-11 sin 0.2 = +-2.19)",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 6304.185,
|
||||
"area_mm2": 1905.356,
|
||||
"faces": 8,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-10.0,
|
||||
-10.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
10.0,
|
||||
11.0,
|
||||
20.0
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#3841",
|
||||
"tangency-labs/solidcraft#168"
|
||||
],
|
||||
"what": "Join of a ring (r10..15) onto a coin (r10) that touch only along a circle: no fusion that moves the ring",
|
||||
"source": "invariants",
|
||||
"outcome": "solid_or_refused",
|
||||
"method": "the bodies share one circular edge and no area, so a join has no single manifold solid to give: the right answer is a clean refusal, or the two bodies left as they are (body_count 2). Fusing them means the kernel moved or rotated the ring",
|
||||
"body_count": 2
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": {
|
||||
"origin": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"x_dir": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.circle.center",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"radius": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"distance": 3,
|
||||
"operation": "new",
|
||||
"body_name": "Coin"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": {
|
||||
"origin": [
|
||||
0,
|
||||
0,
|
||||
3
|
||||
],
|
||||
"x_dir": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.circle.center",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"radius": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.circle.center",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"radius": 15
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"profiles": [
|
||||
{
|
||||
"point": [
|
||||
12,
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"distance": 3,
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"Coin"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#4095"
|
||||
],
|
||||
"what": "a slab cut whose +x face stands 6.60e-05 mm (0.60 x the coincidence tolerance 1.10e-04) off a through-bore's wall (R=15), beside the bore",
|
||||
"source": "analytic",
|
||||
"method": "plate 90x60x20 minus the bore pi R^2*20 minus the notch (the slab 6x16 from z=12 up through the top z=20: 6*16*8 = 768), which the bore beside it does not change. V = 90*60*20 - pi*15^2*20 - 768. The bug removed about 5% too much with no warning",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 93094.8331
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"corner": [
|
||||
-45.0,
|
||||
-30.0,
|
||||
0
|
||||
],
|
||||
"length": 90,
|
||||
"width": 60,
|
||||
"height": 20,
|
||||
"body_name": "Plate"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.cylinder",
|
||||
"params": {
|
||||
"radius": 15,
|
||||
"height": 22,
|
||||
"base": [
|
||||
0,
|
||||
0,
|
||||
-1
|
||||
],
|
||||
"operation": "cut",
|
||||
"targets": [
|
||||
"Plate"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"corner": [
|
||||
-21.000066,
|
||||
-8,
|
||||
12
|
||||
],
|
||||
"length": 6,
|
||||
"width": 16,
|
||||
"height": 14,
|
||||
"operation": "cut",
|
||||
"targets": [
|
||||
"Plate"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,7 +4,21 @@
|
||||
"tangency-labs/solidcraft#3636"
|
||||
],
|
||||
"what": "a coil (diameter 151, pitch 10, 80 high, 5 mm round section) whose section runs through a diameter-152 cylinder's wall, joined to it: truck ground for 125-296 s, then 'boolean Union: no result'",
|
||||
"source": "invariants",
|
||||
"method": "the coil's section crosses the wall along its whole length, so the union is one connected solid: one valid closed body. The helical sweep's part outside r 76 has no closed-form volume (the triage's script)",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the coil is a screw sweep of its axial section, a 5 mm circle centred at r 75.5 (section_position center), 80 / 10 = 8 turns from z 10, so the wire spans r 73..78, z 7.5..92.5: inside r 76 it lies in the cylinder (r 76, z 0..100), and what the join adds is the screw sweep of the section's segment beyond r 76 (chord 0.5 from the centre). Segment: A = 2.5^2 acos(0.2) - 0.5 sqrt(6) = 7.33425, int r dA = 75.5 A + (2/3) 6^(3/2) = 563.5335; a screw motion sweeps 2 pi * turns * int r dA: 16 pi * 563.5335 = 28326.28. V = pi 76^2 100 + 28326.28 = 1842910.2 (the cylinder alone, 1814583.9, is far outside the tolerance). Area: the cylinder's 2 pi 76^2 + 2 pi 76 100, less the band the wire covers on r 76 (2 sqrt(6) * 2 pi 76 * 8 = 18714.97), plus the screw sweep of the wire's outer arc (16 pi int R sqrt(r^2 + (10/2pi)^2 sin^2 phi) dphi over |phi| < acos(0.2), r = 75.5 + 2.5 cos phi: 26603.45) and the two end segments (2 A): 91947.04. Box: r 78 in x and y (8 whole turns reach every direction), z 0..100",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 1842910.2,
|
||||
"area_mm2": 91947.04,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-78.0,
|
||||
-78.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
78.0,
|
||||
78.0,
|
||||
100.0
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,20 @@
|
||||
"tangency-labs/solidcraft#4881"
|
||||
],
|
||||
"what": "a join of two pleated skins (lofts between 24-pleat star outlines, less the same loft moved in 1.1 mm) that cross along a ring near their bottoms: truck panicked ('tolerance must be no less than 1e-6') or gave no result",
|
||||
"source": "invariants",
|
||||
"method": "the narrowing cone skin and the flaring lip skin cross at z = -0.3, so their union is one connected solid: one valid closed body, no panic. The reporter's own script (pleated_union.py, 24 pleats)",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the narrowing cone skin and the flaring lip skin cross at z = -0.3, so their union is one connected solid: one valid closed body, no panic. The reporter's own script (pleated_union.py, 24 pleats). Every outline has its 48 vertices on the same rays (every 7.5 deg), and a ruled loft takes vertex to vertex, so at each z every loft is the star polygon with radii linear in z on those rays (a convex combination of two points on a ray stays on it), and each inner loft lies inside its outer one at every z (the radii are smaller on every ray). Skin volumes: the section area is quadratic in z (wedge areas r_i r_i+1 sin(7.5 deg) / 2), so Simpson is exact: cone 39321.32 (z -1..88.3), lip 5571.95 (z -1..6). Their overlap, by integrating over z -1..6 and each wedge's angle the radial intersection of the two skins' intervals (1/2 (r1^2 - r0^2) dtheta, converged to 0.3): 449.76. Join: 39321.32 + 5571.95 - 449.76 = 44443.5 (the two skins' plain sum, 44893.3, and either skin alone fall outside the tolerance). Box: the lip's top outline (r 120 on the axes) and the skins' z -1..88.3",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 44443.5,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-120.0,
|
||||
-120.0,
|
||||
-1.0
|
||||
],
|
||||
"max": [
|
||||
120.0,
|
||||
120.0,
|
||||
88.3
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@
|
||||
"tangency-labs/solidcraft#4484"
|
||||
],
|
||||
"what": "a symmetric through-all cut of a window across a thickened (2 mm) surface revolve of a control-point spline (100 deg about X): truck ran ~20 s to 'boolean Cut: no result' (or never finished)",
|
||||
"source": "invariants",
|
||||
"method": "the window (x -2..6, z 6..20, through all y) crosses the shell where it is near the XZ plane and leaves it joined round the rest of its 100 deg, so the result is one valid closed body. The spline shell has no closed-form volume",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the window (x -2..6, z 6..20, through all y) crosses the shell where it is near the XZ plane and leaves it joined round the rest of its 100 deg, so the result is one valid closed body. The revolve's normal lies in each meridian plane, so the 2 mm thicken is the revolution, through 100 deg, of the band between the cubic spline (clamped, knots 0 0 0 0 .5 1 1 1 1; r 8..11.63, curvature at most 0.128, so a 2 mm offset never folds) and its offset; the window removes, at each point (x, r) of the band with -2 <= x <= 6, the angles where r cos phi >= 6 (acos(6/r) of them; r cos phi <= 20 everywhere). V = int over the band of r (100 deg - [x in -2..6] acos(6/r)) dA, by quadrature: 852.04 thickened outwards (uncut 1053.63), 660.02 inwards (uncut 807.73). Which side the revolve's normal faces is the kernel's convention, so V is graded in [660.02, 852.04], widened 1e-3: a cut that did nothing on the outer side, or lost half the body, falls outside. Faces: the two offset walls, the two end caps, the plane at 100 deg, the XZ plane's two pieces either side of the window, and the window's planes x = -2, x = 6 and z = 6: 10 Faces are not graded: whether a spline of several spans is one wall or one face per span is an open decision.",
|
||||
"body_count": 1,
|
||||
"volume_mm3": [
|
||||
659.3,
|
||||
852.9
|
||||
]
|
||||
}
|
||||
@@ -3,7 +3,23 @@
|
||||
"tangency-labs/solidcraft#831"
|
||||
],
|
||||
"what": "tapered extrude of a text glyph (Bezier outline): refused with a misleading 'mixing lines and arcs' error",
|
||||
"source": "invariants",
|
||||
"method": "the letter S, 1 mm tall with -10 deg draft, is one valid closed solid (the glyph is one connected region); no number is derived because the glyph outline is the font's. Its volume is positive and below the plain extrusion's",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the letter S, 1 mm tall with -10 deg draft, is one valid closed solid (the glyph is one connected region). Its outline is the embedded font's (Liberation Sans 'S', one contour of 46 points, quadratic segments), scaled by the capital height: 10 / 1409 font units. From the outline (Green on the exact quadratic segments): area A = 32.1459, perimeter P = 55.7935, four convex corners of 91.6, 87.2, 96.1 and 84.5 deg at the stroke ends. A -10 deg taper moves the outline in by d = t tan 10 deg at height t, so A(d) = A - P d + C d^2 with C = 1/2 (smooth turning) + sum tan(corner/2) = 4.0065 (mitred corners), and V = A - P tan10/2 + C tan10^2/3 = 27.268. The moved outline is documented within 10 um of the true offset, so V lies within 0.01 * P = 0.56 of that: [26.71, 27.83] (the untapered 32.15 and an outward taper, 37.1, fall outside). Box: the glyph's own extents at z 0, x 0.6600..9.0277, y -0.1419..10.1490, z 0..1",
|
||||
"body_count": 1,
|
||||
"volume_mm3": [
|
||||
26.71,
|
||||
27.83
|
||||
],
|
||||
"bbox": {
|
||||
"min": [
|
||||
0.66,
|
||||
-0.1419,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
9.0277,
|
||||
10.149,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,3 @@
|
||||
# rig gate (.github/workflows/kernel-rig.yml) fails on a case that fails and is not listed here,
|
||||
# and on a listed case that passes: a fix removes its line in the same pull request.
|
||||
# Baseline: develop 5ada4fc8a with SMLib 90aabff (the run on 60b1c6a, aarch64 Linux).
|
||||
3604-cut-with-g2-swept-tool-along-projected-edge step 12 (solid.sweep): the path curves are not connected end to end
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"sources": [],
|
||||
"what": "where a box edge crosses a plane square to it",
|
||||
"source": "analytic",
|
||||
"method": "box 40 x 30 x 20 with a corner at the origin (x 0..40, y 0..30, z 0..20): the edge y 0, z 0 along X meets x = 12 at (12,0,0)",
|
||||
"construction": {
|
||||
"P": {
|
||||
"point": [
|
||||
12,
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 40,
|
||||
"width": 30,
|
||||
"height": 20,
|
||||
"body_name": "Box"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "construct.point.edge_plane",
|
||||
"params": {
|
||||
"edge": {
|
||||
"edge": [
|
||||
20,
|
||||
0,
|
||||
0
|
||||
]
|
||||
},
|
||||
"plane": {
|
||||
"plane": {
|
||||
"origin": [
|
||||
12,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"normal": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "P"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,7 +4,20 @@
|
||||
"tangency-labs/solidcraft#2243"
|
||||
],
|
||||
"what": "a small enclosure (rounded box, inner cut, corner gusset with a screw hole, two standoffs, USB cut-out) whose STEP export never finished (the export meshes its own file back)",
|
||||
"source": "invariants",
|
||||
"method": "the script builds one connected part: the export must finish, and the part is one valid closed solid",
|
||||
"body_count": 1
|
||||
}
|
||||
"source": "analytic",
|
||||
"method": "the script builds one connected part: the export must finish, and the part is one valid closed solid. Body sketch: the rounded rectangle 0..78 x 0..77 (outer_width = 74 + 2 * 2, outer_depth = 73 + 2 * 2), corners r 3, area 78*77 - (4 - pi)*9 = 5998.274, extruded 37.5: 224935.278. Cavity box (2,2,2.5) 74 x 73, open at the top: - 74*73*35 = 189070. Gusset (68,67,2.5) 8 x 8 x 35 in the cavity's back corner: + 2240. Screw hole r 1.25 at (72,71) from z 29.5, inside the gusset: - pi 1.25^2 8 = 39.270. Two standoffs r 2.5, 3 high at (30.11, 69.04) and (58.05, 69.04) on the floor, clear of the walls and the gusset: + 2 * 58.905. USB cut-out (21.33..31.33, -1..3, 5..11) through the 2 mm front wall: - 10*2*6 = 120. V = 38063.827. Box: the outline's 0..78 x 0..77, z 0..37.5",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 38063.827337,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
78,
|
||||
77,
|
||||
37.5
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,20 @@
|
||||
"tangency-labs/solidcraft#1985"
|
||||
],
|
||||
"what": "a flanged enclosure with two standoffs and no screw hole whose STEP export also never finished",
|
||||
"source": "invariants",
|
||||
"method": "one connected part: the export finishes and the part is one valid closed solid",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "one connected part: the export finishes and the part is one valid closed solid. Body sketch: the rounded rectangle 0..80 x 0..79, corners r 3, area 80*79 - (4 - pi)*9 = 6312.274, extruded 32.5. Flange: the rounded rectangle -10..90 x 0..79, corners r 3, area 7892.274, 2.5 thick, holding the body's footprint (its own corners lie outside the body's), so the two give 7892.274*2.5 + 6312.274*30. Cavity box (3,3,2.5) 74 x 73, open at the top: - 74*73*30 = 162060. Gusset (69,68,2.5) 8 x 8 x 30: + 1920. Two standoffs r 2.5, 3 high at (31.11, 70.04) and (59.05, 70.04): + 2 * 58.905. V = 49076.73. Box: the flange's -10..90 x 0..79, z 0..32.5",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 49076.73,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-10.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
90.0,
|
||||
79.0,
|
||||
32.5
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,21 @@
|
||||
"tangency-labs/solidcraft#2357"
|
||||
],
|
||||
"what": "one join of a ring of 90 straight cylinder segments, each overlapping its neighbour at a 4 degree joint: a caught truck panic, then a refusal after 21 minutes",
|
||||
"source": "invariants",
|
||||
"method": "the segments (diameter 5, 7.6 long, centred on radius 100, every 4 degrees) overlap their neighbours (the 4 degree chord at radius 100 is 6.98 < 7.6), so they join into one closed ring: one body with one shell, valid. The joint overlaps have no simple closed form, so no volume is graded. The rig's timeout bounds the time (the issue expects time to grow about linearly with the segment count)",
|
||||
"source": "analytic",
|
||||
"method": "the segments (diameter 5, 7.6 long, centred on radius 100, every 4 degrees) overlap their neighbours (the 4 degree chord at radius 100 is 6.98 < 7.6), so they join into one closed ring: one body with one shell, valid. Segments two apart (13.95 between centres, each within 4.55 of its centre) never meet, so V = 90 (pi 2.5^2 7.6 - W) with W the overlap of two neighbours: their axes cross 3.492 from each midpoint at 4 degrees, and W = int over the plane z = 0 of 2 min(sqrt(6.25 - dA^2), sqrt(6.25 - dB^2)) where both points lie within the segments' lengths (dA, dB the distances to the axes): 12.0915 (grid 800^2 and 1600^2 agree to 1e-4). V = 90 (149.2257 - 12.0915) = 12342.07 (the plain sum, 13430.3, is outside the tolerance). Box: each segment reaches c.e + 3.8 |a.e| + 2.5 sqrt(1 - (a.e)^2) along e; the furthest are those at 2 degrees off the x axis (x +-102.570) and 4 degrees off the y axis (y +-102.515); z +-2.5",
|
||||
"body_count": 1,
|
||||
"shells": 1
|
||||
"shells": 1,
|
||||
"volume_mm3": 12342.07,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-102.57,
|
||||
-102.515,
|
||||
-2.5
|
||||
],
|
||||
"max": [
|
||||
102.57,
|
||||
102.515,
|
||||
2.5
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,20 @@
|
||||
"tangency-labs/solidcraft#4092"
|
||||
],
|
||||
"what": "join extrude of a rounded pad over a lofted body with ring and ribs: repeated truck intersection_curve panics, then 'boolean Union: no result'",
|
||||
"source": "invariants",
|
||||
"method": "the pad (X -8..8, Y 18..25, Z 36..59) overlaps the body, ribs and ring, so the join is one connected solid; the join must succeed with one valid closed solid and no panic",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the pad (X -8..8, Y 18..25, Z 36..59) overlaps the body, ribs and ring, so the join is one connected solid; the join must succeed with one valid closed solid and no panic. Body: neck pi 18^2 21; the two-section loft is ruled, the circle r 18 paired with the 30 x 20 ellipse by their common angle parameter (the ellipse an affine image of the circle), so each section is an ellipse (18 + 12 l) x (18 + 2 l): 17 pi int (18 + 12 l)(18 + 2 l) dl = 7786 pi (pairing by normals instead, the largest any pairing gives, adds 17 pi * 1.5 = 80, inside the tolerance); the ellipse chamber pi*30*20*22 (z 38..60) and the flange 70 x 50 r 6 (area 3500 - (4 - pi)*36 = 3469.097, z 60..64, holding the chamber): 101181.25. The handle disc (r 12 about (y 30, z 47), x -5..5), the two ribs (the rounded profile, x -8..-4 and 4..8) and the pad (x -8..8, z 36..59 rounded r 3, y 18..25) add, by integrating over x -8..8, z 35..59 the length in y of the union of every part's y-interval less the body's own (grids 400^2..1600^2 agree to 2.4): 5347.9. V = 106529.2. Box: the flange's x +-35, y -25 to the disc's 42, z 0..64",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 106529.2,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-35.0,
|
||||
-25.0,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
35.0,
|
||||
42.0,
|
||||
64.0
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#4092"
|
||||
],
|
||||
"what": "the same without the top flange: the join fails with 'boolean Union: no result'",
|
||||
"source": "invariants",
|
||||
"method": "the pad (X -8..8, Y 18..25, Z 36..59) overlaps the body, ribs and ring, so the join is one connected solid; the join must succeed with one valid closed solid and no panic",
|
||||
"body_count": 1
|
||||
}
|
||||
@@ -1,508 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "file.new",
|
||||
"params": {
|
||||
"name": "Native_loft_pad_union_repro"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "document.units",
|
||||
"params": {
|
||||
"units": "mm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.cylinder",
|
||||
"params": {
|
||||
"diameter": "36 mm",
|
||||
"height": "21 mm",
|
||||
"base": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"operation": "new",
|
||||
"name": "01_Neck_outer_D36_H21",
|
||||
"body_name": "NATIVE_CAP_BODY"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "02_Outer_transition_round",
|
||||
"plane": "XY",
|
||||
"offset": "21 mm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.circle.center",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"diameter": 36
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "03_Outer_transition_ellipse",
|
||||
"plane": "XY",
|
||||
"offset": "38 mm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.ellipse",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"major": [
|
||||
30.0,
|
||||
0
|
||||
],
|
||||
"minor_radius": 20.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "02_Outer_transition_round"
|
||||
},
|
||||
{
|
||||
"sketch": "03_Outer_transition_ellipse"
|
||||
}
|
||||
],
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "04_Outer_round_to_oval_transition"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "05_Upper_chamber_60x40",
|
||||
"plane": "XY",
|
||||
"offset": "38 mm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.ellipse",
|
||||
"params": {
|
||||
"center": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"major": [
|
||||
30.0,
|
||||
0
|
||||
],
|
||||
"minor_radius": 20.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"sketch": "05_Upper_chamber_60x40",
|
||||
"distance": 26,
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "06_Upper_chamber_blank"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "Handle_outer_D24",
|
||||
"plane": {
|
||||
"origin": [
|
||||
-5,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"x_dir": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.circle.center",
|
||||
"params": {
|
||||
"center": [
|
||||
30,
|
||||
47
|
||||
],
|
||||
"diameter": 24
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"sketch": "Handle_outer_D24",
|
||||
"distance": 10,
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "Handle_outer_D24_thickness10"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "Handle_lower_rib_X-8",
|
||||
"plane": {
|
||||
"origin": [
|
||||
-8,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"x_dir": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
18.0,
|
||||
37.5
|
||||
],
|
||||
"end": [
|
||||
19.5,
|
||||
36.0
|
||||
],
|
||||
"through": [
|
||||
18.439339828220177,
|
||||
36.43933982822018
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
19.5,
|
||||
36.0
|
||||
],
|
||||
[
|
||||
24.4516191451179,
|
||||
36.0
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
24.4516191451179,
|
||||
36.0
|
||||
],
|
||||
"end": [
|
||||
25.20742568340403,
|
||||
38.79566835134765
|
||||
],
|
||||
"through": [
|
||||
25.89963546529897,
|
||||
37.10853003117829
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
25.20742568340403,
|
||||
38.79566835134765
|
||||
],
|
||||
[
|
||||
20.25580653828613,
|
||||
41.68411285266642
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
20.25580653828613,
|
||||
41.68411285266642
|
||||
],
|
||||
"end": [
|
||||
18.0,
|
||||
40.38844450131877
|
||||
],
|
||||
"through": [
|
||||
18.75290891031588,
|
||||
41.68915773017231
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
18.0,
|
||||
40.38844450131877
|
||||
],
|
||||
[
|
||||
18.0,
|
||||
37.5
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"sketch": "Handle_lower_rib_X-8",
|
||||
"distance": 4,
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "Handle_lower_rib_X-8_R1p5_thickness4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "Handle_lower_rib_X4",
|
||||
"plane": {
|
||||
"origin": [
|
||||
4,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"x_dir": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
18.0,
|
||||
37.5
|
||||
],
|
||||
"end": [
|
||||
19.5,
|
||||
36.0
|
||||
],
|
||||
"through": [
|
||||
18.439339828220177,
|
||||
36.43933982822018
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
19.5,
|
||||
36.0
|
||||
],
|
||||
[
|
||||
24.4516191451179,
|
||||
36.0
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
24.4516191451179,
|
||||
36.0
|
||||
],
|
||||
"end": [
|
||||
25.20742568340403,
|
||||
38.79566835134765
|
||||
],
|
||||
"through": [
|
||||
25.89963546529897,
|
||||
37.10853003117829
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
25.20742568340403,
|
||||
38.79566835134765
|
||||
],
|
||||
[
|
||||
20.25580653828613,
|
||||
41.68411285266642
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.arc.three_point",
|
||||
"params": {
|
||||
"start": [
|
||||
20.25580653828613,
|
||||
41.68411285266642
|
||||
],
|
||||
"end": [
|
||||
18.0,
|
||||
40.38844450131877
|
||||
],
|
||||
"through": [
|
||||
18.75290891031588,
|
||||
41.68915773017231
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.line",
|
||||
"params": {
|
||||
"points": [
|
||||
[
|
||||
18.0,
|
||||
40.38844450131877
|
||||
],
|
||||
[
|
||||
18.0,
|
||||
37.5
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"sketch": "Handle_lower_rib_X4",
|
||||
"distance": 4,
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "Handle_lower_rib_X4_R1p5_thickness4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"name": "Handle_root_pad_R3",
|
||||
"plane": {
|
||||
"origin": [
|
||||
0,
|
||||
18,
|
||||
0
|
||||
],
|
||||
"x_dir": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"y_dir": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.rounded",
|
||||
"params": {
|
||||
"p0": [
|
||||
-8,
|
||||
36
|
||||
],
|
||||
"p1": [
|
||||
8,
|
||||
59
|
||||
],
|
||||
"radius": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.extrude",
|
||||
"params": {
|
||||
"sketch": "Handle_root_pad_R3",
|
||||
"distance": 7,
|
||||
"direction": "negative",
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"NATIVE_CAP_BODY"
|
||||
],
|
||||
"name": "Native_root_pad_R3"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,7 +3,20 @@
|
||||
"tangency-labs/solidcraft#4542"
|
||||
],
|
||||
"what": "a fluted cup wall (a 72-point periodic fit spline round r 31.5..32.5 outside, a circle r 25 inside) extruded 90 mm as a join onto the top face of a revolved base disc of r 32: the app hung in the boolean",
|
||||
"source": "invariants",
|
||||
"method": "the wall's ring stands on the base's top face (z = 7), overlapping it between r 25 and the disc's rim and overhanging it where the flutes pass r 32, so the join is one connected solid: one valid closed body. The spline's area is not closed-form, so the volume is not graded",
|
||||
"body_count": 1
|
||||
"source": "analytic",
|
||||
"method": "the wall's ring stands on the base's top face (z = 7), overlapping it between r 25 and the disc's rim and overhanging it where the flutes pass r 32, so the join is one connected solid: one valid closed body. The two only share the face z = 7, so V is their sum. Base: Pappus on the profile (0,0)-(25,0), the arc through (29.5,1.5) to (32,7) (centre (25.25, 6.75), r 6.75463), (32,7)-(0,7): area 214.2728, V = 2 pi int x dA = 20655.013. Wall: the sketch's periodic fit spline is the C2 cyclic cubic through the 72 points with chord-length spans (closed back to the first point), its area by Green on its 72 Bezier pieces 3217.3851 (star-shaped, r 31.5002..32.5002); less the r 25 circle: 1253.8897, times 90 = 112850.069. V = 133505.08 (either part alone, or a wall sunk into the base, falls outside the tolerance). Box: the spline's extremes x, y +-32.5 (it reaches 32.5 on the axes and no further), z 0..97",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 133505.08,
|
||||
"bbox": {
|
||||
"min": [
|
||||
-32.5,
|
||||
-32.5,
|
||||
0.0
|
||||
],
|
||||
"max": [
|
||||
32.5,
|
||||
32.5,
|
||||
97.0
|
||||
]
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 0.5 mm front rim of a sloped basin's top chamfered 4: its leg on the top runs off the rim over the slab's front face (a cliff), so it builds as if the top went on and is cut by the front face, which it lowers to z = 28.524233 where it crosses it",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. The chamfer's triangle in (y, z): the edge (0.5, 30), its leg on the top to (-3.5, 30), past the front face y = 0, and d down the wall to (0.5 + d (20-0.5)/L, 30 - 20 d/L), L = sqrt((20-0.5)^2 + 400), built as if the top went on and cut by the front face (the owner's ruling of 2026-10-30 (d7): a chamfer that reaches or runs past a rim builds): the triangle clipped to y >= 0, the quadrilateral (0.5, 30), (0, 30), (0, 28.524233), (3.292401, 27.135999). At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed (shoelace for the area and its first moment) 184.526613. V = 144082.140054",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144082.14005363008,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
}
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.chamfer",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
]
|
||||
],
|
||||
"distance": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 0.5 mm front rim of a sloped basin's top chamfered 0.5, as wide as the rim: its leg on the top ends on the slab's front edge, using the rim's top up, and it builds",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. The chamfer's triangle in (y, z): the edge (0.5, 30), its leg on the top to (0, 30), the slab's front edge, and d down the wall to (0.5 + d (20-0.5)/L, 30 - 20 d/L), L = sqrt((20-0.5)^2 + 400) (the owner's ruling of 2026-10-30 (d7): a chamfer that reaches or runs past a rim builds). At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed (shoelace for the area and its first moment) 5.359321. V = 144261.307346",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144261.307345957,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
}
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.chamfer",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
]
|
||||
],
|
||||
"distance": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 0.5 mm front rim of a sloped basin's top chamfered 0.25, half the rim's width: it fits",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. The chamfer's triangle in (y, z): the edge (0.5, 30), its leg on the top to (0.25, 30) and d down the wall to (0.5 + d (20-0.5)/L, 30 - 20 d/L), L = sqrt((20-0.5)^2 + 400). At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed (shoelace for the area and its first moment) 1.341165. V = 144265.325501",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144265.32550144705,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
}
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.chamfer",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
]
|
||||
],
|
||||
"distance": 0.25
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 1 mm front rim of a sloped basin's top chamfered 3: its leg on the top runs off the rim over the slab's front face (a cliff), so it builds as if the top went on and is cut by the front face, which it lowers to z = 29.141377 where it crosses it",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 1)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144533.333333. The chamfer's triangle in (y, z): the edge (1, 30), its leg on the top to (-2, 30), past the front face y = 0, and d down the wall to (1 + d (20-1)/L, 30 - 20 d/L), L = sqrt((20-1)^2 + 400), built as if the top went on and cut by the front face (the owner's ruling of 2026-10-30 (d7): a chamfer that reaches or runs past a rim builds): the triangle clipped to y >= 0, the quadrilateral (1, 30), (0, 30), (0, 29.141377), (3.066248, 27.825002). At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed (shoelace for the area and its first moment) 142.112912. V = 144391.220421",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144391.22042136008,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
}
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
1
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.chamfer",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
1,
|
||||
30
|
||||
]
|
||||
],
|
||||
"distance": 3
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 0.5 mm front rim of a sloped basin's top rounded R0.25: it fits on the rim",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. The wall leans (20-0.5) out over 20 down: the faces meet at 134.2748 deg, so the round's contacts lie r cot(t/2) = 0.105412 from the edge, on the top at y = 0.394588 and down the wall, its centre under the top contact at z = 30 - r. At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed 0.084803. V = 144266.581864",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144266.58186392413,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
},
|
||||
"continuity": {
|
||||
"order": "g1"
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.fillet",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
]
|
||||
],
|
||||
"radius": 0.25
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "all four of the top rim edges of a sloped basin with a 0.5 mm front rim rounded R4, mitred at the rim's corners: past the thin rim the front round runs over the slab's front face and is cut from the slab",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. Each blend's section at height z spans from its wall to its arc (or chamfer line), the front one not past y = 0, the slab's face; its edge runs between its neighbours' walls (the sloped end walls extended), so it takes Int width(z) length(z) dz. At a re-entrant corner of two picked edges the blends meet in a mitre (the owner's ruling of 2026-10-30): each runs on past the corner and the quadrant beyond both walls loses what both take, Int width_1(z) width_2(z) dz. Removed 182.348561. V = 144084.318105",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144084.31810540144,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
},
|
||||
"continuity": {
|
||||
"order": "g1"
|
||||
}
|
||||
}
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.fillet",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
],
|
||||
[
|
||||
80,
|
||||
27,
|
||||
30
|
||||
],
|
||||
[
|
||||
50,
|
||||
50,
|
||||
30
|
||||
],
|
||||
[
|
||||
20,
|
||||
27,
|
||||
30
|
||||
]
|
||||
],
|
||||
"radius": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1080"
|
||||
],
|
||||
"what": "the 0.5 mm front rim of a sloped basin's top rounded R4: the round runs over the rim's top past the slab's front face (a cliff) and is cut from the slab",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 0.5)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 144266.666667. The wall leans (20-0.5) out over 20 down: the faces meet at 134.2748 deg, so the round's contacts lie r cot(t/2) = 1.686591 from the edge, on the top at y = -1.186591 and down the wall, its centre under the top contact at z = 30 - r. The round is built as if the top went on past y = 0 and cut from the slab (a round past a face on its tangent side builds: the owner's ruling of 2026-10-30), so its section counts only at y >= 0. At height z the blend runs between the sloped end walls x = 20 + (30-z)/2 and 80 - (30-z)/2 extended, which cut it: its length there is 30 + z, so it takes Int Int (30 + z) dy dz over its section (y, z). Removed 17.395317. V = 144249.271350",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 144249.27134953788,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
},
|
||||
"continuity": {
|
||||
"order": "g1"
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
0.5
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.fillet",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
0.5,
|
||||
30
|
||||
]
|
||||
],
|
||||
"radius": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#1207"
|
||||
],
|
||||
"what": "the bar's top edge and the partial base arc of a boss standing out over the bar's side, rounded r1 together: the corner patch where they meet must join the bar's round at least G1 (today a 13.1° crease)",
|
||||
"source": "analytic",
|
||||
"method": "bar 100x30x10 (y -15..15) joined with a diameter 40 boss 20 tall at the origin, standing out over both sides (V0 = 49756.1794, as 1207-fillet-concave-arc-at-boss). The bar's front top edge (y=-15, z=10) and the boss's base arc over the bar (its two edges, split at the cylinder's seam: the tangent chain) rounded r1 together meet at (13.229, -15, 10), where the third edge, the boss's line on the front face, is concave and runs down. Away from that corner the body is V0 plus the arc round's spandrel strip ending on y=+-15 (integral over rho of [r - sqrt(r^2-(20+r-rho)^2)] rho 2 asin(15/rho) = 7.2537, Simpson) less the front round's spandrel out to the boss wall (integral over y of [r - sqrt(r^2-(y+15-r)^2)] (100 - sqrt(400-y^2)) = 18.5684); the corner patch lies within the cube of side 2r about the vertex, so V is graded as V0 + add - removed with (2r)^3 as its tolerance",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 49744.864673399745,
|
||||
"tolerance": {
|
||||
"rel": 0.00016082062043035108
|
||||
},
|
||||
"continuity": {
|
||||
"order": "g1"
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 30,
|
||||
"height": 10,
|
||||
"corner": [
|
||||
0,
|
||||
-15,
|
||||
0
|
||||
],
|
||||
"body_name": "Arm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.cylinder",
|
||||
"params": {
|
||||
"diameter": 40,
|
||||
"height": 20,
|
||||
"base": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"operation": "join",
|
||||
"targets": [
|
||||
"Arm"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.fillet",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
60,
|
||||
-15,
|
||||
10
|
||||
],
|
||||
[
|
||||
16,
|
||||
12,
|
||||
10
|
||||
]
|
||||
],
|
||||
"radius": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2,10 +2,9 @@
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#2893"
|
||||
],
|
||||
"what": "a cylinder r5 tilted 26.6 deg from Z cut flat at z = 10, its elliptical rim chamfered 1 and 2: built, or refused as not supported, never a wrong solid",
|
||||
"what": "a cylinder r5 tilted 26.6 deg from Z cut flat at z = 10, its elliptical rim chamfered 1 and 2: one closed valid solid",
|
||||
"source": "invariants",
|
||||
"method": "the axis (1, 0, 2)/sqrt5 through (0, 0, -10) meets z = 10 at (10, 0, 10); the rim is the ellipse there with semi-axes 5 (along y) and 5 sqrt5/2 (along x); (10, 5, 10) is on it. An unequal chamfer of an ellipse has no closed-form volume: one closed valid solid, or a refusal that names the rim as not supported yet (never an SMLib status).",
|
||||
"outcome": "solid_or_refused",
|
||||
"refusal": "not supported yet",
|
||||
"method": "the axis (1, 0, 2)/sqrt5 through (0, 0, -10) meets z = 10 at (10, 0, 10); the rim is the ellipse there with semi-axes 5 (along y) and 5 sqrt5/2 (along x); (10, 5, 10) is on it. An unequal chamfer of an ellipse has no closed-form volume: one closed valid solid (the owner, 2026-10-31: it builds).",
|
||||
"outcome": "solid",
|
||||
"body_count": 1
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#5835"
|
||||
],
|
||||
"what": "all four of the top rim edges of a sloped basin whose walls slope unequally, its front rim 4 mm wide, chamfered 2: the chamfers meet in mitres at the rim's corners",
|
||||
"source": "analytic",
|
||||
"method": "slab 100 x 60 x 30 less the loft from the rectangle (20, 4)-(80, 50) at z = 30 to (30, 20)-(70, 40) at z = 10 (planar walls, a prismatoid: 20/6 (A_top + A_bottom + 4 A_mid)): V0 = 146133.333333. Each blend's section at height z spans from its wall to its arc (or chamfer line), inside its rim; its edge runs between its neighbours' walls (the sloped end walls extended), so it takes Int width(z) length(z) dz. At a re-entrant corner of two picked edges the blends meet in a mitre (the owner's ruling of 2026-10-30): each runs on past the corner and the quadrant beyond both walls loses what both take, Int width_1(z) width_2(z) dz. Removed 370.156402. V = 145763.176931",
|
||||
"body_count": 1,
|
||||
"volume_mm3": 145763.17693088384,
|
||||
"bbox": {
|
||||
"min": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max": [
|
||||
100,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"tolerance": {
|
||||
"rel": 1e-06
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
{
|
||||
"commands": [
|
||||
{
|
||||
"command": "solid.box",
|
||||
"params": {
|
||||
"length": 100,
|
||||
"width": 60,
|
||||
"height": 30,
|
||||
"body_name": "Slab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 30,
|
||||
"name": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
20,
|
||||
4
|
||||
],
|
||||
"p1": [
|
||||
80,
|
||||
50
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "sketch.create",
|
||||
"params": {
|
||||
"plane": "XY",
|
||||
"offset": 10,
|
||||
"name": "Bottom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.rectangle.two_point",
|
||||
"params": {
|
||||
"p0": [
|
||||
30,
|
||||
20
|
||||
],
|
||||
"p1": [
|
||||
70,
|
||||
40
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "sketch.finish",
|
||||
"params": {}
|
||||
},
|
||||
{
|
||||
"command": "solid.loft",
|
||||
"params": {
|
||||
"sections": [
|
||||
{
|
||||
"sketch": "Top"
|
||||
},
|
||||
{
|
||||
"sketch": "Bottom"
|
||||
}
|
||||
],
|
||||
"operation": "cut"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "solid.chamfer",
|
||||
"params": {
|
||||
"edges": [
|
||||
[
|
||||
50,
|
||||
4,
|
||||
30
|
||||
],
|
||||
[
|
||||
80,
|
||||
27,
|
||||
30
|
||||
],
|
||||
[
|
||||
50,
|
||||
50,
|
||||
30
|
||||
],
|
||||
[
|
||||
20,
|
||||
27,
|
||||
30
|
||||
]
|
||||
],
|
||||
"distance": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"sources": [
|
||||
"tangency-labs/solidcraft#851",
|
||||
"tangency-labs/solidcraft#854"
|
||||
],
|
||||
"what": "on #851's knife-edge part (tessellation/1263): the arc's top edge chamfered 2",
|
||||
"source": "invariants",
|
||||
"method": "a 2 mm chamfer fits on these edges (the arc's chamfer is a cone cut by the back face where the arc runs into it); one closed valid solid whose display mesh closes is the right answer",
|
||||
"body_count": 1,
|
||||
"watertight": true
|
||||
}
|
||||
Loaded 100 of 163 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user