inspect.clearance: measure the 0.2 mm gap on trimmed faces (#2283) (#2337)

* claim: #2283

* inspect.clearance: a point straight past an edge's end no longer passes as on the face (#2283)

A witness point on a face's surface is kept only if it lies on the face
itself; near the face's boundary the nearest edge decides which side it is
on. A point straight past the end of an edge (on the line through it) was
meant to be left to the other edge meeting there, but "straight" was an
absolute 1e-9 of the body size. With a slightly tilted axis (1.5e-6 rad, as
a STEP round trip leaves it) a point 0.2 mm past the end of a knuckle's seam
edge is 4.5e-6 mm off that line, so its side came down to rounding and the
point on the knuckle's extended cylinder, level with the frame band's rim,
was taken as contact (0.000) at some angles.

Straight along is now relative to the distance from the edge (1e-3 of it),
so the rim edge meeting there decides. Regression test: a hinge knuckle
turned 30-80 degrees between two bands reads 0.2 mm at every angle, with
both witness points on the bodies (41 degrees read 0.0 before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Loohi
2026-10-19 23:56:34 +00:00
committed by GitHub
parent af436493a2
commit f97a84c100
2 changed files with 47 additions and 2 deletions
+40
View File
@@ -252,6 +252,46 @@ fn a_small_gap_past_a_corner_is_not_contact() {
}
}
/// #2283: a knuckle (Ø6, z 3.7 to 8.3, with a 150 mm arm) turning between two frame bands (Ø6,
/// z -1.5 to 3.5 and 8.5 to 13.5) on a shared axis is 0.2 mm from them at every angle. Its axis
/// tilted 1.5e-6 rad (as a STEP round trip leaves it), the band's rim lies on the knuckle's
/// cylinder extended past its end, and a point there was taken for a point of the knuckle at
/// some angles: contact (0) at a point off the body.
#[test]
fn a_hinge_gap_is_measured_on_the_trimmed_faces_at_every_angle() {
let mut s = Session::default();
let part = |s: &mut Session, cmd: &str, mut p: Value, name: &str, join: bool| {
p["body_name"] = json!(name);
p["operation"] = json!(if join { "join" } else { "new" });
if join {
p["targets"] = json!([name]);
}
run(s, cmd, p);
};
part(&mut s, "solid.cylinder", json!({"radius": 3, "height": 5, "base": [0, 0, -1.5]}), "Frame", false);
part(&mut s, "solid.cylinder", json!({"radius": 3, "height": 5, "base": [0, 0, 8.5]}), "Frame", true);
for z in [-1.5, 8.5] {
part(&mut s, "solid.box", json!({"length": 137.5, "width": 4, "height": 5, "corner": [-140, -2, z]}), "Frame", true);
}
part(&mut s, "solid.box", json!({"length": 5, "width": 4, "height": 15, "corner": [-145, -2, -1.5]}), "Frame", true);
part(&mut s, "solid.cylinder", json!({"radius": 3, "height": 4.6, "base": [0, 0, 3.7]}), "Temple", false);
part(&mut s, "solid.box", json!({"length": 150, "width": 2, "height": 4.6, "corner": [0, -1, 3.7]}), "Temple", true);
run(&mut s, "solid.move", json!({"bodies": ["Temple"], "axis": [1, 0, 0], "angle": "1.5e-6 rad"}));
run(&mut s, "solid.move", json!({"bodies": ["Temple"], "axis": [0, 0, 1], "angle": "29 deg"}));
for deg in 30..=80 {
run(&mut s, "solid.move", json!({"bodies": ["Temple"], "axis": [0, 0, 1], "angle": "1 deg"}));
let r = run(&mut s, "inspect.clearance", json!({"bodies": ["Temple"], "against": ["Frame"], "clearance": 0.5, "nearest": 1}));
let near = &r["near"][0];
assert!((f(&near["distance_mm"]) - 0.2).abs() < 1e-4, "{deg}°: {r}");
assert!((f(&r["nearest"]["Temple"][0]["distance_mm"]) - 0.2).abs() < 1e-4, "{deg}°: {r}");
// The witness points lie on the bodies: the frame's at a band end, the knuckle's at one
// of its ends.
let (from, to) = (f(&near["from"][2]), f(&near["to"][2]));
assert!([3.5, 8.5].iter().any(|z| (from - z).abs() < 1e-4), "{deg}°: the frame's point {from} is at a band end: {r}");
assert!([3.7, 8.3].iter().any(|z| (to - z).abs() < 1e-4), "{deg}°: the knuckle's point {to} is at a knuckle end: {r}");
}
}
/// A second call measures only the pairs with a body that changed or moved since the first.
#[test]
fn pairs_whose_bodies_did_not_change_or_move_are_not_measured_again() {
+7 -2
View File
@@ -50,6 +50,9 @@ pub struct DistanceShape<'a> {
const MAX_FACE_PAIRS: usize = 24;
/// Most projection rounds for one pair of features.
const MAX_ROUNDS: usize = 400;
/// A point less than this fraction of its distance from an edge off the line through it is
/// straight along the edge (see [`DistanceShape::on_face`]).
const ALONG: f64 = 1e-3;
impl<'a> DistanceShape<'a> {
/// `mesh` is `body`'s mesh, within `chord` (mm) of its faces.
@@ -149,9 +152,11 @@ impl<'a> DistanceShape<'a> {
continue;
}
// `p` straight along the edge (past its end, on the line through it) says nothing
// about which side it is on: another edge meeting there decides.
// about which side it is on: another edge meeting there decides. Straight along is
// relative to how far `p` is: past the end, what is left across the edge is the
// edge's own tilt and rounding, and its side is chance (#2283).
let off = across(p);
if off.len() <= tiny {
if off.len() <= tiny.max(ALONG * at.dist(p)) {
continue;
}
decided = true;