Skip to content

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

Wave 238/509: geom: a face's box reaches its boundary's extremes, not its samples' (and 3 more)

jyviko2425f8b453e3
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index d161d401fe..b602b55c06 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -697,7 +697,7 @@ fn fillet_fitted(
fit: crate::FilletFit,
) -> std::result::Result<(kernel::Body, Option<Vec<f64>>), kernel::KernelError> {
match kernel::fillet(body, edges, r) {
- Err(kernel::KernelError::TooLarge(why)) if fit == crate::FilletFit::Reduce => match kernel::fillet_max_each(body, edges, r) {
+ Err(kernel::KernelError::TooLarge(why)) if fit == crate::FilletFit::Reduce => match kernel::fillet_max_each(body, edges, r)? {
// Built at the radius asked for after all (the groups apart): nothing reduced.
Some((used, b)) => Ok((b, used.iter().any(|u| *u < r).then_some(used))),
None => Err(kernel::KernelError::TooLarge(why)),
diff --git a/crates/geom/src/brep/form.rs b/crates/geom/src/brep/form.rs
index 1356137f94..ea616c877e 100644
--- a/crates/geom/src/brep/form.rs
+++ b/crates/geom/src/brep/form.rs
@@ -317,6 +317,32 @@ pub fn edge<'a>(
/// Points per edge along a loop taken for a face's extent.
const EXTENT_POINTS: usize = 32;
+/// The largest value of `f` on `[a, b]`, where it rises to one peak and falls (golden section, to
+/// rounding; the ends count).
+fn golden_max(f: &dyn Fn(f64) -> f64, a: f64, b: f64) -> f64 {
+ const R: f64 = 0.618_033_988_749_894_8;
+ let (mut a, mut b) = (a, b);
+ let best = f(a).max(f(b));
+ let (mut c, mut d) = (b - R * (b - a), a + R * (b - a));
+ let (mut fc, mut fd) = (f(c), f(d));
+ while b - a > 1e-15 * (1.0 + a.abs().max(b.abs())) {
+ if fc >= fd {
+ b = d;
+ d = c;
+ fd = fc;
+ c = b - R * (b - a);
+ fc = f(c);
+ } else {
+ a = c;
+ c = d;
+ fc = fd;
+ d = a + R * (b - a);
+ fd = f(d);
+ }
+ }
+ best.max(fc).max(fd)
+}
+
/// The parameter box of a face on `label` over its boundary: each loop's points (`loops`, in
/// order along each loop) projected onto the label, a periodic parameter unwrapped from one point
/// to the next, and each loop after the first a whole number of periods along where that keeps
@@ -334,17 +360,23 @@ pub fn extent(label: &Surface, loops: &[Vec<(&Curve, [f64; 2], bool)>]) -> Optio
let mut prev: Option<[f64; 2]> = None;
for (c, [t0, t1], forward) in l {
let curve = super::eval::CurveEval::new(c).ok()?;
- for k in 0..=EXTENT_POINTS {
- let f = k as f64 / EXTENT_POINTS as f64;
- let t = if *forward { t0 * (1.0 - f) + t1 * f } else { t1 * (1.0 - f) + t0 * f };
- let mut q = eval.project(curve.point(t)?, prev, f64::INFINITY)?;
- if let Some(p) = prev {
+ // The point at `t` on the label, a periodic parameter unwrapped next to `near`.
+ let at = |t: f64, near: Option<[f64; 2]>| -> Option<[f64; 2]> {
+ let mut q = eval.project(curve.point(t)?, near, f64::INFINITY)?;
+ if let Some(p) = near {
for d in 0..2 {
if let Some(Some(per)) = period.get(d) {
q[d] += ((p[d] - q[d]) / per).round() * per;
}
}
}
+ Some(q)
+ };
+ let mut samples: Vec<(f64, [f64; 2], [bool; 2])> = Vec::with_capacity(EXTENT_POINTS + 1);
+ for k in 0..=EXTENT_POINTS {
+ let f = k as f64 / EXTENT_POINTS as f64;
+ let t = if *forward { t0 * (1.0 - f) + t1 * f } else { t1 * (1.0 - f) + t0 * f };
+ let q = at(t, prev)?;
// At a pole the collapsed parameter is anything: it bounds nothing.
let pole = eval.pole(q);
for d in 0..2 {
@@ -356,6 +388,36 @@ pub fn extent(label: &Surface, loops: &[Vec<(&Curve, [f64; 2], bool)>]) -> Optio
if !pole.iter().any(|p| *p) {
prev = Some(q);
}
+ samples.push((t, q, pole));
+ }
+ // A sample is a point of the boundary, not its extreme: each sample higher (or lower)
+ // than its neighbours brackets an extreme of the edge, which is found there.
+ for k in 0..samples.len() {
+ let (_, q, pole) = samples[k];
+ let (a, b) = (samples[k.saturating_sub(1)].0, samples[(k + 1).min(samples.len() - 1)].0);
+ for d in 0..2 {
+ // Next to a pole the parameter it collapses is no function of the point: a
+ // meridian's angle there is rounding, not an extreme.
+ let near_pole = |j: Option<usize>| j.and_then(|j| samples.get(j)).is_some_and(|s| s.2[d]);
+ if pole[d] || near_pole(k.checked_sub(1)) || near_pole(Some(k + 1)) {
+ continue;
+ }
+ let side = |j: usize| samples.get(j).map(|s| s.1[d]);
+ let (before, after) = (if k > 0 { side(k - 1) } else { None }, side(k + 1));
+ for sign in [1.0, -1.0] {
+ // Not lower than either neighbour and higher than one (a level run, a
+ // seam's constant angle, has no extreme between its samples).
+ let higher = |x: Option<f64>| x.is_none_or(|x| sign * q[d] >= sign * x);
+ let above = |x: Option<f64>| x.is_some_and(|x| sign * q[d] > sign * x);
+ if !(higher(before) && higher(after) && (above(before) || above(after))) {
+ continue;
+ }
+ let f = |t: f64| at(t, Some(q)).map_or(f64::NEG_INFINITY, |p| sign * p[d]);
+ let x = sign * golden_max(&f, a.min(b), a.max(b));
+ l_lo[d] = l_lo[d].min(x);
+ l_hi[d] = l_hi[d].max(x);
+ }
+ }
}
}
for d in 0..2 {
diff --git a/crates/geom/src/brep/tests.rs b/crates/geom/src/brep/tests.rs
index bd913a50c6..cf03070c07 100644
--- a/crates/geom/src/brep/tests.rs
+++ b/crates/geom/src/brep/tests.rs
@@ -829,3 +829,17 @@ fn a_hole_beside_the_seam_lies_in_its_face_turn() {
assert!(hole_u > u[0] && hole_u + (a1 - a0) < u[1], "the hole in the turn: {u:?}");
assert!(v[0].abs() < 1e-9 && (v[1] - h).abs() < 1e-9, "{v:?}");
}
+
+/// A face's box reaches its boundary's extremes, not its samples' nearest ones: an ellipse cut
+/// from a cylinder of radius 20 by a plane at 45 degrees rises 20 above its centre, at an angle
+/// between the points the box is sampled at. Short of it, the face's NURBS form stopped below the
+/// edge (#4598: the bore of a re-imported rod ended 2.3e-4 short of where it meets the rod).
+#[test]
+fn a_face_box_reaches_its_boundary_extremes() {
+ let r = 20.0f64;
+ let cylinder = Surface::Cylinder { frame: Frame { origin: [0.; 3], x_axis: [1., 0., 0.], y_axis: [0., 1., 0.] }, radius: r };
+ let c = std::f64::consts::FRAC_1_SQRT_2;
+ let cut = Curve::Ellipse { frame: Frame { origin: [0., 0., 30.], x_axis: [c, 0., c], y_axis: [0., 1., 0.] }, radii: [r * 2f64.sqrt(), r] };
+ let [_, v] = form::extent(&cylinder, &[vec![(&cut, [0.1, 0.1 + TAU], true)]]).expect("an extent");
+ assert!((v[0] - 10.0).abs() < 1e-9 && (v[1] - 50.0).abs() < 1e-9, "{v:?}");
+}
diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs
index fcf7969ae0..67ff61f998 100644
--- a/crates/kernel/src/blend.rs
+++ b/crates/kernel/src/blend.rs
@@ -230,15 +230,17 @@ fn radius_step(radius: f64) -> f64 {
}
/// The largest radius below `radius` (to three significant digits) at which the fillet of
-/// these edges works, with its result; `None` when none does. Each candidate is a real fillet
+/// these edges works, with its result; `Ok(None)` when none does. Each candidate is a real fillet
/// of the edges, so the radius returned is one that was built; the search runs up to 16 of
-/// them, so it is for an explicit request, not every refusal.
-pub fn fillet_max(body: &Body, edges: &[Vec3], radius: f64) -> Option<(f64, Body)> {
+/// them, so it is for an explicit request, not every refusal. Only a refusal as too large
+/// ([`KernelError::TooLarge`]) narrows the search: any other failure of a candidate is the
+/// search's error, since a smaller radius would not be the largest that fits.
+pub fn fillet_max(body: &Body, edges: &[Vec3], radius: f64) -> Result<Option<(f64, Body)>> {
if !(radius.is_finite() && radius > 1e-6) {
- return None;
+ return Ok(None);
}
let q = radius_step(radius);
- // Radii n·q for n in [0, hi): hi fails (it is the request, or above it), lo works.
+ // Radii n·q for n in [0, hi): hi is too large (it is the request, or above it), lo works.
let mut hi = (radius / q).ceil() as u64;
let mut lo = 0u64;
let mut best: Option<Body> = None;
@@ -253,22 +255,24 @@ pub fn fillet_max(body: &Body, edges: &[Vec3], radius: f64) -> Option<(f64, Body
lo = mid;
best = Some(b);
}
- Err(_) => hi = mid,
+ Err(KernelError::TooLarge(_)) => hi = mid,
+ Err(e) => return Err(e),
}
}
- best.map(|b| (lo as f64 * q, b))
+ Ok(best.map(|b| (lo as f64 * q, b)))
}
/// [`fillet_max`] for each group of the edges that may limit each other's radius (sharing a
/// face or a vertex, directly or through other edges in the group), so a round that fits isn't
-/// reduced for a tight edge elsewhere. The radius per edge (in `edges`' order) and the result;
-/// one radius for all (as [`fillet_max`]) when a group is refused for another reason than its
-/// size, the groups don't build together, or there are too many to search (each search is up
-/// to 16 fillets, and this runs in the live preview).
-pub fn fillet_max_each(body: &Body, edges: &[Vec3], radius: f64) -> Option<(Vec<f64>, Body)> {
+/// reduced for a tight edge elsewhere. The radius per edge (in `edges`' order) and the result,
+/// `Ok(None)` when no radius fits. One radius for all (as [`fillet_max`]) when the groups,
+/// each reduced to fit, are too large together, or there are too many to search (each search is
+/// up to 16 fillets, and this runs in the live preview). Any failure other than a refusal as too
+/// large is the error.
+pub fn fillet_max_each(body: &Body, edges: &[Vec3], radius: f64) -> Result<Option<(Vec<f64>, Body)>> {
const MAX_GROUPS: usize = 8;
const MAX_SEARCHES: usize = 2;
- let one = || fillet_max(body, edges, radius).map(|(r, b)| (vec![r; edges.len()], b));
+ let one = || -> Result<Option<(Vec<f64>, Body)>> { Ok(fillet_max(body, edges, radius)?.map(|(r, b)| (vec![r; edges.len()], b))) };
let Some(groups) = interacting_groups(body, edges).filter(|g| g.len() > 1 && g.len() <= MAX_GROUPS) else { return one() };
let mut radii = vec![radius; edges.len()];
let mut searches = 0;
@@ -278,12 +282,13 @@ pub fn fillet_max_each(body: &Body, edges: &[Vec3], radius: f64) -> Option<(Vec<
Ok(_) => continue,
Err(KernelError::TooLarge(_)) if searches < MAX_SEARCHES => {
searches += 1;
- match fillet_max(body, &pts, radius) {
+ match fillet_max(body, &pts, radius)? {
Some((r, _)) => r,
None => return one(),
}
}
- Err(_) => return one(),
+ Err(KernelError::TooLarge(_)) => return one(),
+ Err(e) => return Err(e),
};
for i in g {
if let Some(x) = radii.get_mut(*i) {
@@ -292,8 +297,9 @@ pub fn fillet_max_each(body: &Body, edges: &[Vec3], radius: f64) -> Option<(Vec<
}
}
match fillet_each(body, edges, &radii) {
- Ok(b) => Some((radii, b)),
- Err(_) => one(),
+ Ok(b) => Ok(Some((radii, b))),
+ Err(KernelError::TooLarge(_)) => one(),
+ Err(e) => Err(e),
}
}
diff --git a/crates/kernel/src/iges_in/tests.rs b/crates/kernel/src/iges_in/tests.rs
index 4abed67300..9a120751ef 100644
--- a/crates/kernel/src/iges_in/tests.rs
+++ b/crates/kernel/src/iges_in/tests.rs
@@ -361,6 +361,54 @@ fn surfaces_in_separate_groups_remain_separate_parts() {
}
}
+/// The box of [`trimmed_surfaces_sew_into_a_solid`] with its edge (0, 0, 0)–(0, 20, 0) stopping
+/// 0.01 mm short of its corner in both faces that use it, its next pieces starting at the
+/// corner. The pieces of a trim curve run on from one another, so the edge ends at the corner the
+/// other three edges there agree on, exactly: a closed box SMLib finds valid. The edge was left
+/// short with the gap on the vertex's tolerance, 2000 times the file's resolution (#3845).
+#[test]
+fn trim_pieces_that_miss_their_corner_are_closed_onto_it() {
+ let c =
+ |i: usize| -> [f64; 3] { [if i & 1 != 0 { 10.0 } else { 0.0 }, if i & 2 != 0 { 20.0 } else { 0.0 }, if i & 4 != 0 { 30.0 } else { 0.0 }] };
+ let short = [0.0, 19.99, 0.0];
+ let quads = [[0, 2, 3, 1], [4, 5, 7, 6], [0, 1, 5, 4], [2, 6, 7, 3], [0, 4, 6, 2], [1, 3, 7, 5]];
+ let mut ents: Vec<(i64, i64, String)> = Vec::new();
+ let fmt = |p: [f64; 3]| format!("{:?},{:?},{:?}", p[0], p[1], p[2]);
+ for q in quads {
+ let (a, b, cc, d) = (c(q[0]), c(q[1]), c(q[2]), c(q[3]));
+ let surf = format!("1,1,1,1,0,0,1,0,0,0.,0.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,{},{},{},{},0.,1.,0.,1.", fmt(a), fmt(b), fmt(d), fmt(cc));
+ ents.push((128, 0, surf));
+ let s_de = 2 * ents.len() - 1;
+ let mut lines = Vec::new();
+ for (p0, p1) in [(a, b), (b, cc), (cc, d), (d, a)] {
+ // The short edge: its end at (0, 20, 0) is 0.01 short.
+ let (p0, p1) = match (p0, p1) {
+ ([0.0, 0.0, 0.0], [0.0, 20.0, 0.0]) => (p0, short),
+ ([0.0, 20.0, 0.0], [0.0, 0.0, 0.0]) => (short, p1),
+ x => x,
+ };
+ ents.push((110, 0, format!("{},{}", fmt(p0), fmt(p1))));
+ lines.push(2 * ents.len() - 1);
+ }
+ ents.push((102, 0, format!("4,{}", lines.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","))));
+ let comp = 2 * ents.len() - 1;
+ ents.push((142, 0, format!("0,{s_de},0,{comp},2")));
+ let cos = 2 * ents.len() - 1;
+ ents.push((144, 0, format!("{s_de},1,0,{cos}")));
+ }
+ let imp = iges_import(&iges_file(&ents)).unwrap();
+ assert!(imp.warnings.is_empty(), "{:?}", imp.warnings);
+ assert!(imp.bodies[0].closed);
+ let body = &imp.bodies[0].body;
+ let check = body.smlib().unwrap().check(solidcraft_smlib::CheckLevel::All).unwrap();
+ assert!(check.is_valid(), "{check}");
+ for v in &body.record().vertices {
+ assert!(v.tolerance <= body.record().tolerance, "a vertex {:?} kept a gap in its tolerance {}", v.point, v.tolerance);
+ }
+ let m = measure(body).unwrap();
+ assert!(rel(m.volume, 6000.0) < 1e-6 && rel(m.area, 2200.0) < 1e-6, "{} {}", m.volume, m.area);
+}
+
#[test]
fn a_drill_point_round_trips_through_iges() {
// A blind hole with a cone tip: the tip's face closes at its apex (its seam runs out to the
diff --git a/crates/kernel/src/tests.rs b/crates/kernel/src/tests.rs
index 356246efd7..592c36269d 100644
--- a/crates/kernel/src/tests.rs
+++ b/crates/kernel/src/tests.rs
@@ -357,14 +357,14 @@ fn fillet_max_finds_the_largest_radius_that_works() {
let b = box_solid(Vec3::new(14.0, 0.0, 0.0), Vec3::new(28.0, 6.0, 10.0)).unwrap();
let mids = [Vec3::new(14.0, 0.0, 5.0), Vec3::new(28.0, 0.0, 5.0), Vec3::new(14.0, 6.0, 5.0), Vec3::new(28.0, 6.0, 5.0)];
assert!(too_large(&b, &mids, 3.5));
- let (r, body) = fillet_max(&b, &mids, 3.5).unwrap();
+ let (r, body) = fillet_max(&b, &mids, 3.5).unwrap().unwrap();
assert_eq!(r, 3.0);
assert!(rel(measure(&body).unwrap().volume, 840.0 - (4.0 - PI) * 90.0) < 2e-4);
// A 2 mm disc's top edge: up to 2 (the wall used up).
let disc = cylinder(Vec3::ZERO, Vec3::Z, 13.0, 2.0).unwrap();
let top = [Vec3::new(0.0, 13.0, 2.0), Vec3::new(0.0, -13.0, 2.0)];
assert!(too_large(&disc, &top, 2.5));
- assert_eq!(fillet_max(&disc, &top, 2.5).map(|x| x.0), Some(2.0));
+ assert_eq!(fillet_max(&disc, &top, 2.5).unwrap().map(|x| x.0), Some(2.0));
// Walls of different heights: at the shortest one's height only that wall would be used up,
// which is refused, so the largest radius is just below it (to the search's 3 digits).
let notched = boolean(
@@ -376,10 +376,13 @@ fn fillet_max_finds_the_largest_radius_that_works() {
.unwrap();
let outline = [Vec3::new(20.0, 0.0, 10.0), Vec3::new(40.0, 15.0, 10.0), Vec3::new(20.0, 30.0, 10.0), Vec3::new(0.0, 15.0, 10.0)];
assert!(too_large(&notched, &outline, 8.0));
- let (r, _) = fillet_max(&notched, &outline, 8.0).unwrap();
+ let (r, _) = fillet_max(&notched, &outline, 8.0).unwrap().unwrap();
assert!((r - 6.999).abs() < 1e-9, "{r}");
- // No edge there: no radius.
- assert!(fillet_max(&b, &[Vec3::new(500.0, 0.0, 5.0)], 1.0).is_none());
+ // No edge there: the fillet's own error, not a smaller radius (only a refusal as too large
+ // narrows the search).
+ let e = fillet(&b, &[Vec3::new(500.0, 0.0, 5.0)], 1.0).unwrap_err();
+ assert!(!matches!(e, KernelError::TooLarge(_)), "{e}");
+ assert_eq!(fillet_max(&b, &[Vec3::new(500.0, 0.0, 5.0)], 1.0).unwrap_err().to_string(), e.to_string());
}
/// Edges that share no face get their own largest radius: a 2 mm fin's top edge takes at most
@@ -401,7 +404,7 @@ fn fillet_max_each_reduces_only_where_the_radius_does_not_fit() {
// at its edge less the quarter disc about (17, 26), inside the fin (x >= 19): 2 x 4 less the
// disc's part, in closed form; the corner's round (1 − π/4)·16 along 20.
let both = fillet(&body, &edges, 4.0).unwrap();
- let (radii, b) = fillet_max_each(&body, &edges, 4.0).unwrap();
+ let (radii, b) = fillet_max_each(&body, &edges, 4.0).unwrap().unwrap();
assert_eq!(radii, vec![4.0, 4.0], "{radii:?}");
assert!(b.validity().is_empty(), "{:?}", b.validity());
let disc = |a: f64| 0.5 * (a * (16.0 - a * a).max(0.0).sqrt() + 16.0 * (a / 4.0).asin());
@@ -412,7 +415,7 @@ fn fillet_max_each_reduces_only_where_the_radius_does_not_fit() {
// The post's four edges limit each other: one radius, as `fillet_max`.
let post = box_solid(Vec3::new(14.0, 0.0, 0.0), Vec3::new(28.0, 6.0, 10.0)).unwrap();
let mids = [Vec3::new(14.0, 0.0, 5.0), Vec3::new(28.0, 0.0, 5.0), Vec3::new(14.0, 6.0, 5.0), Vec3::new(28.0, 6.0, 5.0)];
- assert_eq!(fillet_max_each(&post, &mids, 3.5).map(|x| x.0), Some(vec![3.0; 4]));
+ assert_eq!(fillet_max_each(&post, &mids, 3.5).unwrap().map(|x| x.0), Some(vec![3.0; 4]));
}
/// A corner's rounds too large for its faces are refused as too large, so a fit can reduce
@@ -426,7 +429,7 @@ fn corner_rounds_larger_than_their_faces_are_too_large() {
// blend can't find it; the corner build is what says the radius is too large.
let e = fillet(&b, &corner, l).unwrap_err();
assert!(matches!(e, KernelError::TooLarge(_)), "{e}");
- let (r, body) = fillet_max(&b, &corner, l).unwrap();
+ let (r, body) = fillet_max(&b, &corner, l).unwrap().unwrap();
assert!((r - 19.99).abs() < eps, "{r}");
assert!(body.validity().is_empty(), "{:?}", body.validity());
// Three rounds along the edges past the corner cube, and the cube less its sphere octant.
diff --git a/crates/step/src/topology/seams.rs b/crates/step/src/topology/seams.rs
index 6fac3d0bd5..710f5fb7d6 100644
--- a/crates/step/src/topology/seams.rs
+++ b/crates/step/src/topology/seams.rs
@@ -167,6 +167,7 @@ impl Builder<'_, '_> {
if periods.iter().all(Option::is_none) {
continue;
}
+ let found = axis(&surface).or_else(|| spline_axis(&surface, &eval));
let mut up = Vec::new();
let mut down = Vec::new();
for (li, l) in face.loops.iter().enumerate() {
@@ -175,6 +176,12 @@ impl Builder<'_, '_> {
if w[1] != 0 || w[0].abs() > 1 {
return Err(format!("face #{}: {}", face.step, unsupported("a loop winding around a surface more than once or in v")));
}
+ // A loop through a pole turns once round the axis and closes there, where every
+ // angle is one point: a cone's base circle with its seam out to the apex and
+ // back. It has its seam; another one doubled it, a sliver the face crossed.
+ if w[0] != 0 && found.as_ref().is_some_and(|ax| self.through_pole(es, ax)) {
+ continue;
+ }
match w[0] {
1 => up.push(li),
-1 => down.push(li),
@@ -185,7 +192,7 @@ impl Builder<'_, '_> {
continue;
}
let step = face.step;
- let Some(ax) = axis(&surface).or_else(|| spline_axis(&surface, &eval)) else {
+ let Some(ax) = found else {
return Err(format!("face #{step}: {}", unsupported("a face winding around a torus or a spline closed in v without a seam edge")));
};
match (up.as_slice(), down.as_slice()) {
@@ -226,6 +233,15 @@ impl Builder<'_, '_> {
Ok(total.map(|x| x.round() as i64))
}
+ /// A vertex of the loop is on one of the axis's poles (within its tolerance).
+ fn through_pole(&self, es: &[(u32, bool)], ax: &Axis) -> bool {
+ es.iter().any(|&u| {
+ self.start(u).ok().and_then(|v| self.vertices.get(v as usize)).is_some_and(|x| {
+ ax.poles.iter().flatten().any(|p| Vec3::from(x.point).dist(*p) <= self.tol.max(x.tolerance))
+ })
+ })
+ }
+
/// The vertex where use `k` of a loop starts.
fn start(&self, (e, forward): (u32, bool)) -> R<u32> {
let edge = self.edges.get(e as usize).ok_or("edge reference")?;
diff --git a/crates/step/src/topology_tests.rs b/crates/step/src/topology_tests.rs
index 37bebece56..e508edced0 100644
--- a/crates/step/src/topology_tests.rs
+++ b/crates/step/src/topology_tests.rs
@@ -445,6 +445,35 @@ fn a_cone_reaches_its_apex_through_a_vertex_loop() {
faces_away(&s.brep, 0, |p| [0.0, 0.0, p[2].clamp(1.0, 2.0)]);
}
+/// The same cone written with its seam: the base circle, then the seam out to the apex and back.
+/// The loop turns once round the axis and closes at the apex, so it has its seam; reading it as
+/// a loop without one gave the face a second seam, a sliver out and back the face's boundary
+/// crossed (#5193: a turned pin's drill point after a STEP round trip did not tessellate).
+#[test]
+fn a_cone_with_its_seam_to_the_apex_gets_no_other() {
+ let mut w = W::default();
+ let (p, top) = ([5.0, 0.0, 0.0], [0.0, 0.0, 10.0]);
+ let (v, apex) = (w.vertex(p), w.vertex(top));
+ let k = w.circle([0.0; 3], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0], 5.0);
+ let e = w.add(format!("EDGE_CURVE('',#{v},#{v},#{k},.T.)"));
+ let seam = w.line_edge((v, p), (apex, top), true, len3(sub3(top, p)));
+ let a = w.axis([0.0; 3], [0.0, 0.0, -1.0], [1.0, 0.0, 0.0]);
+ let cone = w.add(format!("CONICAL_SURFACE('',#{a},5.,{})", real(0.5f64.atan())));
+ let uses = [w.oe(e, true), w.oe(seam, true), w.oe(seam, false)];
+ let outer = w.bound(&uses, true, true);
+ let side = w.face(&[outer], cone, true);
+ let o = w.oe(e, false);
+ let base_bound = w.bound(&[o], true, true);
+ let plane = w.plane([0.0; 3], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]);
+ let base = w.face(&[base_bound], plane, false);
+ let shell = closed_shell(&mut w, &[side, base]);
+ let solid = w.add(format!("MANIFOLD_SOLID_BREP('cone',#{shell})"));
+ let s = one_solid(&w.file(&[solid]));
+ assert_eq!(counts(&s.brep), [2, 1, 2, 2, 2]);
+ assert!(!s.notes.iter().any(|n| n.contains("seam edges added")), "{:?}", s.notes);
+ faces_away(&s.brep, 0, |p| [0.0, 0.0, p[2].clamp(1.0, 2.0)]);
+}
+
/// A tube (radius 5 outside, 3 inside, from z = 0 to 4) whose cylinders carry no seam edges:
/// each side is bounded by two circles whose vertices sit at different angles.
#[test]