From 9e7acbfaae7749a10517393578f333f43c69299a Mon Sep 17 00:00:00 2001 From: Paul Fremantle Date: Tue, 6 Oct 2026 15:25:28 +0000 Subject: [PATCH 1/2] Suppress planned bore locations covered by authored axis witnesses --- src/draftwright/model/compiled.py | 43 +++++++++++++++++++++++++++ tests/test_authored_pmi_precedence.py | 39 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/draftwright/model/compiled.py b/src/draftwright/model/compiled.py index 4e26ce57..af6ce122 100644 --- a/src/draftwright/model/compiled.py +++ b/src/draftwright/model/compiled.py @@ -1613,6 +1613,48 @@ def _compile_locations(model: PartModel) -> tuple[list[ApprovedDimension], list[ return approved, omissions +def _authored_bore_axis_location_matches( + source: AuthoredDimension, location: ApprovedDimension +) -> bool: + """Match an X/Y hole location to a witness on the same physical bore axis. + + STEP often locates an axis at an interior Z station, while recognition locates + its mouth. The other in-plane coordinate and the bore's depth still have to + agree; a pattern centre is not a hole and must not cover its own location. + """ + feature = location.id.feature if location.id is not None else None + span = location.span + stations = _authored_linear_stations(source) + if ( + not isinstance(feature, HoleFeature) + or feature.frame.axis != "z" + or feature.depth is None + or span is None + or stations is None + or location.discriminator != "xyz"[stations[0]] + or location.discriminator not in ("x", "y") + or abs(source.value - location.value) > 1e-6 + ): + return False + index = stations[0] + target = span[1] + if not any( + all(abs(member[i] - target[i]) <= 0.01 for i in range(3)) + for member in feature.members or (feature.frame.origin,) + ): + return False + return any( + abs(point[index] - target[index]) <= 0.01 + and abs(other[index] - span[0][index]) <= 0.01 + and abs(point[1 - index] - target[1 - index]) <= 0.01 + and target[2] - feature.depth - 0.01 <= point[2] <= target[2] + 0.01 + for point, other in ( + (source.ref_pts[0], source.ref_pts[1]), + (source.ref_pts[1], source.ref_pts[0]), + ) + ) + + def _compile_off_axis_hole_locations( model: PartModel, ) -> tuple[list[ApprovedDimension], list[Omission]]: @@ -2093,6 +2135,7 @@ def compile_dimensions( or _authored_location_matches( source, location.span, location.discriminator, location.value ) + or _authored_bore_axis_location_matches(source, location) ) ] if len(matching) == 1: diff --git a/tests/test_authored_pmi_precedence.py b/tests/test_authored_pmi_precedence.py index 774947e8..e1ca35cf 100644 --- a/tests/test_authored_pmi_precedence.py +++ b/tests/test_authored_pmi_precedence.py @@ -722,6 +722,45 @@ def test_authored_hole_x_location_covers_only_the_x_component(): ) +def test_authored_bore_axis_station_covers_only_its_physical_hole_location(): + bbox = (Pos(0, 0, 6) * Box(80, 90, 12)).bounding_box() + deep = HoleFeature(Frame((10, 5, 12), "z"), 4, depth=12, through=True) + shallow = HoleFeature(Frame((10, 5, 12), "z"), 6, depth=4, through=False) + source = AuthoredDimension( + Frame((-7.5, 5, 6), "x"), + "linear", + 35, + "35", + "X", + ref_pts=((-25, 5, 6), (10, 5, 6)), + source_id="dimension:bore-x", + ) + model = PartModel( + bbox, + "z", + [deep, shallow, source], + datums=[Datum("datum_xy", "point", (-25, -40, 0))], + ) + plan = compile_dimensions(model) + assert [(d.id.feature, d.discriminator) for d in plan.locations] == [ + (deep, "y"), + (shallow, "x"), + (shallow, "y"), + ] + assert any( + omission.feature is deep + and omission.parameter_id.endswith(".x") + and "dimension:bore-x" in omission.reason + for omission in plan.diagnostics + ) + wrong_bore = compile_dimensions( + replace( + model, features=[deep, shallow, replace(source, ref_pts=((-25, 6, 6), (10, 6, 6)))] + ) + ) + assert len([d for d in wrong_bore.locations if d.discriminator == "x"]) == 2 + + def test_pattern_member_provenance_is_per_measurement(): hole = HoleFeature(Frame((0, 0, 0), "z"), 4, depth=None, through=True) pattern = PatternFeature( From 040ebc295f14be31e479cf3cc66005431a281672 Mon Sep 17 00:00:00 2001 From: Paul Fremantle Date: Tue, 6 Oct 2026 15:33:05 +0000 Subject: [PATCH 2/2] Cover guarded bore-axis precedence cases --- tests/test_authored_pmi_precedence.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_authored_pmi_precedence.py b/tests/test_authored_pmi_precedence.py index e1ca35cf..52ad1956 100644 --- a/tests/test_authored_pmi_precedence.py +++ b/tests/test_authored_pmi_precedence.py @@ -10,7 +10,7 @@ from draftwright import build_drawing from draftwright.builder import detect_part_model from draftwright.linting.coverage import _authored_axial_witness_on_profile -from draftwright.model.compiled import compile_dimensions +from draftwright.model.compiled import _authored_bore_axis_location_matches, compile_dimensions from draftwright.model.ir import ( AuthoredDimension, CylindricalReference, @@ -759,6 +759,13 @@ def test_authored_bore_axis_station_covers_only_its_physical_hole_location(): ) ) assert len([d for d in wrong_bore.locations if d.discriminator == "x"]) == 2 + shallow_x = next( + d for d in plan.locations if d.id.feature is shallow and d.discriminator == "x" + ) + assert not _authored_bore_axis_location_matches(source, replace(shallow_x, discriminator="z")) + assert not _authored_bore_axis_location_matches( + source, replace(shallow_x, span=((-25, 5, 12), (20, 5, 12))) + ) def test_pattern_member_provenance_is_per_measurement():