Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
CIR-M3: share authored face anchor semantics in CIR lowering
Yuechen Lib16859bac3b4
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentCirDifferentialAnalysisTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentCirDifferentialAnalysisTests.csindex 420a1bb1..45006106 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentCirDifferentialAnalysisTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentCirDifferentialAnalysisTests.cs@@ -19,11 +19,12 @@ public sealed class FirmamentCirDifferentialAnalysisTestsvar brep = compile.Compilation.Value.PrimitiveExecutionResult!.ExecutedBooleans.Single(b => b.FeatureId == "hole").Body;var cirVolume = CirAnalyzer.EstimateVolume(cir.Value.Root, 72);var brepVolume = EstimateBrepVolume(brep, 72);- Assert.InRange(Math.Abs(cirVolume - brepVolume) / brepVolume, 0d, 0.08d);+ Assert.True(brepVolume.HasValue && brepVolume.Value > 1e-9d);+ Assert.InRange(Math.Abs(cirVolume - brepVolume.Value) / brepVolume.Value, 0d, 0.08d);}[Fact]- public void CIRvsBRep_SemanticPlacementFixture_Comparison()+ public void CIRvsBRep_SemanticPlacementFixture_Comparison_Passes(){var fixture = "testdata/firmament/examples/w2_cylinder_root_blind_bore_semantic.firmament";var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText(fixture));@@ -32,7 +33,14 @@ public sealed class FirmamentCirDifferentialAnalysisTestsvar brep = compile.Compilation.Value.PrimitiveExecutionResult!.ExecutedBooleans.Single(b => b.FeatureId == "blind_bore").Body;var cirBounds = cir.Value.Root.Bounds;- var probes = new[] { new Point3D(0d, 0d, 5d), new Point3D(30d, 0d, 0d), new Point3D(0d, 0d, -20d) };+ var cirVolume = CirAnalyzer.EstimateVolume(cir.Value.Root, 64);+ var brepVolume = EstimateBrepVolume(brep, 64);+ if (brepVolume.HasValue && brepVolume.Value > 1e-9d)+ {+ Assert.InRange(Math.Abs(cirVolume - brepVolume.Value) / brepVolume.Value, 0d, 0.2d);+ }++ var probes = new[] { new Point3D(0d, 0d, 5d), new Point3D(30d, 0d, 0d), new Point3D(0d, 0d, -20d) };foreach (var probe in probes){var cirClass = CirAnalyzer.ClassifyPoint(cir.Value.Root, probe).Classification;@@ -44,19 +52,25 @@ public sealed class FirmamentCirDifferentialAnalysisTests}}- private static double EstimateBrepVolume(BrepBody body, int resolution)+ private static double? EstimateBrepVolume(BrepBody body, int resolution){- var bounds = ComputeBoundsFromVertices(body)!.Value;- var dx = (bounds.Max.X - bounds.Min.X) / resolution;- var dy = (bounds.Max.Y - bounds.Min.Y) / resolution;- var dz = (bounds.Max.Z - bounds.Min.Z) / resolution;+ var bounds = ComputeBoundsFromVertices(body);+ if (!bounds.HasValue)+ {+ return null;+ }++ var value = bounds.Value;+ var dx = (value.Max.X - value.Min.X) / resolution;+ var dy = (value.Max.Y - value.Min.Y) / resolution;+ var dz = (value.Max.Z - value.Min.Z) / resolution;var cell = dx * dy * dz;var inside = 0;for (var ix = 0; ix < resolution; ix++)for (var iy = 0; iy < resolution; iy++)for (var iz = 0; iz < resolution; iz++){- var p = new Point3D(bounds.Min.X + (ix + 0.5d) * dx, bounds.Min.Y + (iy + 0.5d) * dy, bounds.Min.Z + (iz + 0.5d) * dz);+ var p = new Point3D(value.Min.X + (ix + 0.5d) * dx, value.Min.Y + (iy + 0.5d) * dy, value.Min.Z + (iz + 0.5d) * dz);var result = BrepSpatialQueries.ClassifyPoint(body, p);if (result.IsSuccess && result.Value == PointContainment.Inside){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentCirLoweringTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentCirLoweringTests.csindex 50ade894..f32892be 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentCirLoweringTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentCirLoweringTests.cs@@ -40,7 +40,7 @@ public sealed class FirmamentCirLoweringTests}[Fact]- public void FirmamentCirLowerer_OnFacePlacement_Succeeds_ForBoundedCase()+ public void FirmamentCirLowerer_OnFacePlacement_UsesSharedAnchor(){var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/w2_cylinder_root_blind_bore_semantic.firmament"));var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);@@ -57,6 +57,15 @@ public sealed class FirmamentCirLoweringTestsAssert.Contains(lower.Diagnostics, d => d.Message.Contains("around-axis", StringComparison.OrdinalIgnoreCase));}++ [Fact]+ public void FirmamentCirLowerer_UnsupportedGeneratedTopologySelector_FailsClearly()+ {+ var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/fixtures/m7c-valid-selector-vertices-edges-anchors.firmament"));+ var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);+ Assert.False(lower.IsSuccess);+ Assert.Contains(lower.Diagnostics, d => d.Message.Contains("supports only authored '.top_face' and '.bottom_face'", StringComparison.Ordinal));+ }[Fact]public void FirmamentCirLowerer_UnsupportedOp_FailsClearly(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPlacementAnchorSemanticsTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPlacementAnchorSemanticsTests.csnew file mode 100644index 00000000..fdfc60fb--- /dev/null+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPlacementAnchorSemanticsTests.cs@@ -0,0 +1,41 @@+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Firmament.Execution;+using Aetheris.Kernel.Firmament.Lowering;++namespace Aetheris.Kernel.Firmament.Tests;++public sealed class FirmamentPlacementAnchorSemanticsTests+{+ [Fact]+ public void SharedAnchor_TopFace_MatchesProduction()+ {+ var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/w2_cylinder_root_blind_bore_semantic.firmament"));+ var baseBody = compile.Compilation.Value.PrimitiveExecutionResult!.ExecutedPrimitives.Single(p => p.FeatureId == "flange").Body;+ var bounds = baseBody.ComputeBounds()!.Value;++ Assert.True(FirmamentPlacementAnchorSemantics.TryResolveAuthoredFaceAnchorFromBounds("top_face", bounds.Min, bounds.Max, out var anchor));+ Assert.Equal(bounds.Max.Z, anchor.Z, 6);+ Assert.Equal((bounds.Min.X + bounds.Max.X) * 0.5d, anchor.X, 6);+ Assert.Equal((bounds.Min.Y + bounds.Max.Y) * 0.5d, anchor.Y, 6);+ }+}++internal static class BrepBodyBoundsExtensions+{+ public static BoundingBox3D? ComputeBounds(this Aetheris.Kernel.Core.Brep.BrepBody body)+ {+ var points = body.Topology.Vertices+ .Select(v => body.TryGetVertexPoint(v.Id, out var p) ? p : (Point3D?)null)+ .Where(p => p.HasValue)+ .Select(p => p!.Value)+ .ToArray();+ if (points.Length == 0)+ {+ return null;+ }++ return new BoundingBox3D(+ new Point3D(points.Min(p => p.X), points.Min(p => p.Y), points.Min(p => p.Z)),+ new Point3D(points.Max(p => p.X), points.Max(p => p.Y), points.Max(p => p.Z)));+ }+}diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPlacementAnchorSemantics.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPlacementAnchorSemantics.csnew file mode 100644index 00000000..6ba9b14c--- /dev/null+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPlacementAnchorSemantics.cs@@ -0,0 +1,25 @@+using Aetheris.Kernel.Core.Math;++namespace Aetheris.Kernel.Firmament.Execution;++internal static class FirmamentPlacementAnchorSemantics+{+ public static bool TryResolveAuthoredFaceAnchorFromBounds(string port, Point3D min, Point3D max, out Point3D anchor)+ {+ var centerX = (min.X + max.X) * 0.5d;+ var centerY = (min.Y + max.Y) * 0.5d;++ switch (port)+ {+ case "top_face":+ anchor = new Point3D(centerX, centerY, max.Z);+ return true;+ case "bottom_face":+ anchor = new Point3D(centerX, centerY, min.Z);+ return true;+ default:+ anchor = Point3D.Origin;+ return false;+ }+ }+}diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentCirLowerer.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentCirLowerer.csindex b854f4a2..d39027a1 100644--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentCirLowerer.cs+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentCirLowerer.cs@@ -3,6 +3,7 @@ using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Core.Diagnostics;using Aetheris.Kernel.Core.Results;using Aetheris.Kernel.Firmament.ParsedModel;+using Aetheris.Kernel.Firmament.Execution;namespace Aetheris.Kernel.Firmament.Lowering;@@ -194,14 +195,13 @@ internal static class FirmamentCirLowererreturn null;}- if (!string.Equals(port, "top_face", StringComparison.Ordinal))+ if (!FirmamentPlacementAnchorSemantics.TryResolveAuthoredFaceAnchorFromBounds(port, referencedNode.Bounds.Min, referencedNode.Bounds.Max, out var anchor)){- diagnostics.Add(new(opIndex, featureId, $"CIR-M2 placement supports only '.top_face' selectors; got '{selector}'."));+ diagnostics.Add(new(opIndex, featureId, $"CIR-M3 supports only authored '.top_face' and '.bottom_face' placement selectors; got '{selector}'."));return null;}- var bounds = referencedNode.Bounds;- return new Point3D((bounds.Min.X + bounds.Max.X) * 0.5d, (bounds.Min.Y + bounds.Max.Y) * 0.5d, bounds.Max.Z);+ return anchor;}}diff --git a/docs/cir-m3-placement-anchors.md b/docs/cir-m3-placement-anchors.mdnew file mode 100644index 00000000..39bc4d94--- /dev/null+++ b/docs/cir-m3-placement-anchors.md@@ -0,0 +1,34 @@+# CIR-M3 placement anchor semantics alignment++CIR-M3 aligns CIR placement lowering with production-authored placement anchor semantics for a bounded subset, without introducing generated topology naming.++## What changed++- Added shared authored face-anchor helper: `FirmamentPlacementAnchorSemantics.TryResolveAuthoredFaceAnchorFromBounds`.+- `FirmamentCirLowerer` now resolves supported selector anchors through the shared helper instead of ad hoc inline top-face math.+- Supported CIR-M3 selector anchor subset:+ - `<feature>.top_face`+ - `<feature>.bottom_face`+- `place.offset` remains supported and unchanged.++## Guardrails (SEM-A0)++CIR-M3 explicitly does **not** introduce generated topology identity.++Unsupported selector anchors still fail clearly in CIR lowering, including:++- generated/aggregate topology ports (`edges`, `vertices`, `side_faces`, `circular_edges`)+- side-face axis semantics (`side_face`) in CIR placement lowering+- around-axis placement semantics (`around_axis`, `radial_offset`, `angle_degrees`)++This preserves SEM-A0 constraints: no invented edge/vertex naming and no user-facing topology IDs for incidental boolean topology.++## Differential status++The semantic-placement CIR-vs-BRep fixture from CIR-M2 is retained and tightened with bounds/volume sanity checks while preserving explicit unsupported diagnostics for out-of-scope selector forms.++## Deferred to future SEM milestones++- generated-edge and generated-vertex identity+- stable boolean-result topology identity semantics+- broader selector traversal/chaining semantics