Wave 442/509: kernel: a seam held as two edges is one join, drawn whole in the shaded view (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. -e46359ff0jyviko: Kernel rig: the patch cases the fill now builds come off the known-failing lists -7c9e5ec69jyviko: kernel: a seam held as two edges is one join, drawn whole in the shaded view -12496c2c1jyviko: Tests: a round flange stays an exact circle through unfold, refold and DXF, with a cut near its rim -7fe880a7bjyviko: SMLib: pin f8fd83e (tangency-labs/smlib#66) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
1 parent
74405f5da0
commit
3f0139b4d9
7 files changed
+120
-31
No files matched your search
@@ -2324,36 +2324,38 @@ fn cut_across_a_concave_notch_uses_crossings_not_just_contained_corners() {
|
||||
assert!((volume(&mut s) - 10500.0).abs() < 1e-6);
|
||||
}
|
||||
|
||||
/// A round flange stays an exact circle through unfold, refold and DXF (never a polyline), and a
|
||||
/// cut close to its rim stays a hole in the flat pattern.
|
||||
#[test]
|
||||
fn tiny_cut_inside_exact_circle_survives_unfold_refold_and_dxf() {
|
||||
fn a_round_flange_stays_a_circle_and_keeps_a_cut_near_its_rim_through_unfold_refold_and_dxf() {
|
||||
for initially_flat in [false, true] {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Disc"}));
|
||||
run(&mut s, "sketch.circle.center", json!({"center": [0,0], "radius": 10}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "sheet.flange", json!({"sketch": "Disc"}));
|
||||
let circle = s.model.state().sheets[0].base.outer.clone();
|
||||
let displayed = circle.polyline(1e-3);
|
||||
// A square 0.2 µm across, centred 0.4 µm inside the circle on the bisector of the
|
||||
// display polyline's first chord (its middle 0.98 µm inside): outside the polyline, inside
|
||||
// the exact circle, each of its walls and its gap to the rim wider than SMLib's 0.1 µm
|
||||
// modelling tolerance.
|
||||
let (half, at) = (0.0001, (displayed[0] + displayed[1]).normalized().unwrap() * 9.9996);
|
||||
assert!(!circle.contains(at));
|
||||
if initially_flat {
|
||||
run(&mut s, "sheet.unfold", json!({}));
|
||||
}
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "TinyCut"}));
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [at.x-half,at.y-half], "p1": [at.x+half,at.y+half]}));
|
||||
// A 1 mm square whose outer side is 0.5 mm inside the rim.
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Cut"}));
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [8.5,-0.5], "p1": [9.5,0.5]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "solid.extrude", json!({"sketch": "TinyCut", "through_all": true, "operation": "cut", "direction": "symmetric"}));
|
||||
run(&mut s, "solid.extrude", json!({"sketch": "Cut", "through_all": true, "operation": "cut", "direction": "symmetric"}));
|
||||
for stage in ["sheet.unfold", "sheet.refold"] {
|
||||
let regions = s.model.state().sheets[0].flat_regions().unwrap();
|
||||
let rim = ®ions[0].outer.segs;
|
||||
assert!(
|
||||
!rim.is_empty() && rim.iter().all(|seg| matches!(seg, solidcraft_geom::Seg2::Arc { radius, .. } if (*radius - 10.0).abs() < 1e-12)),
|
||||
"{rim:?}"
|
||||
);
|
||||
assert_eq!(regions[0].holes.len(), 1);
|
||||
assert!((regions[0].holes[0].signed_area().abs() - 4e-8).abs() < 1e-13);
|
||||
assert!((regions[0].holes[0].signed_area().abs() - 1.0).abs() < 1e-12);
|
||||
assert_eq!(s.model.state().bodies.len(), 1);
|
||||
let dxf = run(&mut s, "sheet.export_dxf", json!({}))["dxf"].as_str().unwrap().to_string();
|
||||
assert_eq!(solidcraft_io::read_dxf(&dxf).unwrap().len(), 5);
|
||||
let drawn = solidcraft_io::read_dxf(&dxf).unwrap();
|
||||
assert!(drawn.iter().any(|g| matches!(g, solidcraft_io::Geom2::Circle(_, r) if (*r - 10.0).abs() < 1e-12)), "{drawn:?}");
|
||||
assert_eq!(drawn.len(), 5, "the circle and the square's four sides: {drawn:?}");
|
||||
if stage == "sheet.unfold" && initially_flat {
|
||||
run(&mut s, "sheet.refold", json!({}));
|
||||
}
|
||||
|
||||
@@ -241,6 +241,8 @@ fn classify(body: &Body, mesh: &Mesh, mut work: usize) -> (Vec<bool>, Vec<bool>)
|
||||
let faces = face_evals(&rec);
|
||||
let mut smooth = vec![false; mesh.edges.len()];
|
||||
let mut sharp = vec![false; mesh.edges.len()];
|
||||
// Edges of one join: the measured edges between the same faces that continue each other.
|
||||
let mut joins: Vec<usize> = Vec::new();
|
||||
// The mesh's edges are the record's, in its order.
|
||||
for (current, line) in mesh.edges.iter().enumerate().take(rec.edges.len()) {
|
||||
let Some(split_work) = line.len().checked_add(1).and_then(|n| n.checked_mul(split_points)) else { break };
|
||||
@@ -251,6 +253,7 @@ fn classify(body: &Body, mesh: &Mesh, mut work: usize) -> (Vec<bool>, Vec<bool>)
|
||||
} else if !same_faces(&rec, mesh, current) {
|
||||
None
|
||||
} else {
|
||||
joins.push(current);
|
||||
let length: f64 = line.windows(2).map(|w| if let [a, b] = w { a.dist(*b) } else { 0. }).sum();
|
||||
let Join { smooth: tangent, crease } =
|
||||
if length > 0. && length.is_finite() { join(&rec, &faces, current, length, &mut work) } else { Join::default() };
|
||||
@@ -266,9 +269,76 @@ fn classify(body: &Body, mesh: &Mesh, mut work: usize) -> (Vec<bool>, Vec<bool>)
|
||||
break;
|
||||
}
|
||||
}
|
||||
whole_joins(&rec, &joins, &mut smooth, work);
|
||||
(smooth, sharp)
|
||||
}
|
||||
|
||||
/// One verdict for each join, however the B-rep splits it: the edges in `measured` between the
|
||||
/// same faces that continue each other at a shared vertex (their curves' tangents there within
|
||||
/// [`ANGLE`] of one line) are one join, smooth only where every one of its edges is. A seam
|
||||
/// SMLib holds as two edges, G2 along one and only near G2 along the other (a G2 corner patch's
|
||||
/// side next to the face it ends on), is drawn whole, never to a vertex in the middle of the
|
||||
/// line. `work` bounds the pairs compared; past it the edges keep their own verdicts.
|
||||
fn whole_joins(record: &Brep, measured: &[usize], smooth: &mut [bool], mut work: usize) {
|
||||
// Per vertex, each measured edge ending there: its faces and its tangent leaving the vertex.
|
||||
let mut ends: std::collections::HashMap<u32, Vec<(usize, Vec<u32>, Vec3)>> = std::collections::HashMap::new();
|
||||
for &e in measured {
|
||||
let Some(edge) = record.edges.get(e) else { continue };
|
||||
let Some(curve) = CurveEval::new(edge.parameters()).ok() else { continue };
|
||||
let mut faces: Vec<u32> = edge.uses.iter().map(|u| u.face).collect();
|
||||
faces.sort_unstable();
|
||||
faces.dedup();
|
||||
let [t0, t1] = edge.interval;
|
||||
for (vertex, t, sign) in [(edge.vertices[0], t0, 1.), (edge.vertices[1], t1, -1.)] {
|
||||
if let Some(d) = curve.derivs(t).and_then(|d| (d.1 * sign).normalized()) {
|
||||
ends.entry(vertex).or_default().push((e, faces.clone(), d));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut parent: Vec<usize> = (0..smooth.len()).collect();
|
||||
fn root(parent: &mut [usize], mut i: usize) -> usize {
|
||||
while let Some(&p) = parent.get(i) {
|
||||
if p == i {
|
||||
break;
|
||||
}
|
||||
let up = parent.get(p).copied().unwrap_or(p);
|
||||
if let Some(slot) = parent.get_mut(i) {
|
||||
*slot = up;
|
||||
}
|
||||
i = up;
|
||||
}
|
||||
i
|
||||
}
|
||||
let cos = ANGLE.cos();
|
||||
'vertices: for at in ends.values() {
|
||||
for (i, (a, fa, da)) in at.iter().enumerate() {
|
||||
for (b, fb, db) in at.iter().skip(i + 1) {
|
||||
let Some(left) = work.checked_sub(1) else { break 'vertices };
|
||||
work = left;
|
||||
// Leaving the vertex in opposite directions: one continues the other.
|
||||
if a != b && fa == fb && da.dot(*db) <= -cos {
|
||||
let (ra, rb) = (root(&mut parent, *a), root(&mut parent, *b));
|
||||
if let Some(slot) = parent.get_mut(ra) {
|
||||
*slot = rb;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut whole: std::collections::HashMap<usize, bool> = std::collections::HashMap::new();
|
||||
for &e in measured {
|
||||
let r = root(&mut parent, e);
|
||||
let own = smooth.get(e).copied().unwrap_or(false);
|
||||
whole.entry(r).and_modify(|s| *s &= own).or_insert(own);
|
||||
}
|
||||
for &e in measured {
|
||||
let r = root(&mut parent, e);
|
||||
if let (Some(slot), Some(&all)) = (smooth.get_mut(e), whole.get(&r)) {
|
||||
*slot = all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
@@ -359,6 +429,31 @@ mod tests {
|
||||
assert!(classify(&body, &mesh, 0).0.iter().all(|f| !*f));
|
||||
}
|
||||
|
||||
/// A G2 corner patch's sides are G2 to their rounds except near the faces they end on, and
|
||||
/// SMLib holds each side as two edges: the side is one join, drawn whole, not up to the
|
||||
/// vertex in its middle where the G2 half begins (the 20 mm box's r3 corner).
|
||||
#[test]
|
||||
fn a_seam_split_in_two_edges_is_drawn_whole() {
|
||||
let body = crate::box_solid(Vec3::ZERO, Vec3::new(20., 20., 20.)).unwrap();
|
||||
let picks = [Vec3::new(20., 20., 10.), Vec3::new(20., 10., 20.), Vec3::new(10., 20., 20.)];
|
||||
let g2 = crate::fillet_g2_corners(&body, &picks, 3., &[]).unwrap();
|
||||
let mesh = g2.mesh(&crate::MeshTolerance::chord(0.02)).unwrap();
|
||||
let rec = crate::native::brep_record(&g2).unwrap();
|
||||
let patch = rec
|
||||
.faces
|
||||
.iter()
|
||||
.position(|f| !matches!(f.surface, Surface::Plane { .. } | Surface::PlaneThrough { .. } | Surface::Cylinder { .. }))
|
||||
.unwrap() as u32;
|
||||
let rounds: Vec<u32> = (0..rec.faces.len() as u32).filter(|f| matches!(rec.faces[*f as usize].surface, Surface::Cylinder { .. })).collect();
|
||||
assert_eq!(rounds.len(), 3);
|
||||
for round in rounds {
|
||||
let side: Vec<usize> =
|
||||
(0..mesh.edges.len()).filter(|e| mesh.edge_faces[*e].contains(&patch) && mesh.edge_faces[*e].contains(&round)).collect();
|
||||
assert_eq!(side.len(), 2, "SMLib splits the side in two: {side:?}");
|
||||
assert!(side.iter().all(|e| mesh.shaded_edge_visible(*e)), "the side to round {round} is drawn whole: {side:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// An extruded circle of eight cubics whose first cubic leaves its start turned by `degrees`:
|
||||
/// the wall join there is a crease of that angle.
|
||||
fn creased(degrees: f64) -> (Body, Mesh, usize) {
|
||||
|
||||
@@ -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 449768fb27dddbc2613bba876e96a762fd4dc36f8ce43e498679a98c3a9c03f1
|
||||
aarch64-pc-windows-msvc 1ce7c9e59d390c855c8d73688340fb747ae6e00fe969065ba646980735abc447
|
||||
aarch64-unknown-linux-gnu 014ba0b4734de8fb8665b58394624a68dced523b09a804f2258a3808cfcda7b2
|
||||
i686-pc-windows-msvc 38ff5885eaba1f0681eb2be777b16fdfdb986ca66c0496c4f4235ec3dc045e84
|
||||
wasm32-unknown-unknown 7227d3b5f208122d39dfab0b9573efc4037d0ea9fd0bfec6f91dba27a9434fe0
|
||||
x86_64-apple-darwin cde31baadd1a807f6a58b3ab17815a939940e2bf82ee032c3a526ecf6d0a41d4
|
||||
x86_64-pc-windows-msvc c0d02f0e0e59c977fd134d872e049d7eb3e027be4ea9c888418fea0cbabd675c
|
||||
x86_64-unknown-linux-gnu edc4a1e08d3263bafbcd44dbd243a7815ca4d535dc308a89b1844126c0bea613
|
||||
aarch64-apple-darwin a0fe19504aee96d2e5de3ac9e4ef7215d649ebb420373a7cc93d62eca3761e2f
|
||||
aarch64-pc-windows-msvc ad359c3996e4255086b193722a987286c1d094556eb053df80fd1538c5f9340d
|
||||
aarch64-unknown-linux-gnu 4d0ac76e060de13a67ab60de6b207598bfc79d68b649875caaedbab4cac63d5a
|
||||
i686-pc-windows-msvc 1218c4f9fa94f769fe8c45ee29d166d1aecd27cb57486de8883c7fba699f6812
|
||||
wasm32-unknown-unknown d61597525a3e1c6910890f9848cb85bb5934b2bcdfd8e6551246d90f8b5f94b8
|
||||
x86_64-apple-darwin 395f629a4e88132ae69874ff55898f493df75b4d8627a6a663f92ca6b633eb58
|
||||
x86_64-pc-windows-msvc 89876ff51ced8dd0513f3837ea1c12965ff957fec3d10051321da31014d24619
|
||||
x86_64-unknown-linux-gnu b4bd2990bd100f9a00a24b77f743208f4395adb8725924bcf939fd04a873ef10
|
||||
@@ -1 +1 @@
|
||||
985faaeed0311d5eaf5e6f091f62ac55c382597c
|
||||
f8fd83e2fd5a70cf036fffbfaff0e7bc88e0563a
|
||||
@@ -2,5 +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: not seeded yet; seeded from a develop run after the SMLib pin bump.
|
||||
cov-patch-g1-caps-an-opened-tube-end not supported yet: the general fill refuses the cap (it folds)
|
||||
cov-patch-g2-caps-an-opened-tube-end not supported yet: the general fill refuses the cap (it folds)
|
||||
@@ -46,7 +46,5 @@ every-hole-top-rim-r12-past-plate-bottom SMLib status 1001: a convex round past
|
||||
every-pocket-floor-and-rim-edges-r2 a corner patch where two rim rounds meet at each concave pocket corner (23 faces, not 19) instead of the mitre the rounds make running into each other
|
||||
every-pocket-rim-edges-r2 a corner patch where two rim rounds meet at each concave pocket corner (19 faces, not 15) instead of the mitre the rounds make running into each other
|
||||
every-pocket-rim-edges-r5-as-deep-as-pocket a corner patch where two rim rounds meet at each concave pocket corner (15 faces, not 11) instead of the mitre the rounds make running into each other
|
||||
report-fillet-concave-arc-bar-top-into-cylinder-solver-residues SMLib status 1001: SmFilletNx1Corner cannot make the topology at the arc's end (fillet error 3, corner type 8)
|
||||
report-fillet-corner-after-round-running-into-cylinder-solver-residues SMLib's check refuses the round: its corner's surface of revolution is close to singular at its boundary (SmSurface test 5)
|
||||
report-fillet-curvature-three-edges-at-bar-corner SMLib's check refuses the open setback sheet of curvature rounds: a 2D B-spline curve cusp (SmBSplineCurve test 13)
|
||||
report-fillet-edge-tangent-at-one-end-into-cylinder SMLib refuses the round as larger than the faces beside its edges allow (SMLIB_ERR_NO_ROOM): it fades to nothing at the edge's tangent end, on the wall SMLib now gets back as its cylinder
|
||||
@@ -3,7 +3,3 @@
|
||||
# that fails and is not listed fails it, and so does a listed case that passes: a fix removes its
|
||||
# line in the same pull request.
|
||||
# Baseline: rig-cases-surfaces 45f69c0e5 with SMLib 60b1c6a, aarch64 Linux.
|
||||
cov-patch-g0-fills-a-240-deg-window-in-a-cylinder not supported yet: the general fill refuses the window (it folds)
|
||||
cov-patch-g0-fills-a-saddle-window-in-a-torus not supported yet: the general fill refuses the window (it folds)
|
||||
cov-patch-g1-fills-a-240-deg-window-in-a-cylinder not supported yet: the general fill refuses the window (it folds)
|
||||
cov-patch-g1-fills-a-saddle-window-in-a-torus not supported yet: the general fill refuses the window (it folds)
|
||||
Reference in new issue
Block a user