Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add circular planar cap emission to planar materializer
Yuechen Li04cad6c44334
diff --git a/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.csindex 1c32a083..a6e93eff 100644--- a/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs@@ -202,13 +202,74 @@ public sealed class SurfacePatchDescriptorScaffoldTests}[Fact]- public void PlanarSurfaceMaterializer_DoesNotEmitCircularCapYet()+ public void PlanarSurfaceMaterializer_CylinderTopCap_FromSourceSurface_EmitsCircularTopology(){var extraction = SourceSurfaceExtractor.Extract(new CirCylinderNode(3, 8));var top = Assert.Single(extraction.Descriptors.Where(c => c.ParameterPayloadReference == "cap-top"));- var ready = PlanarPatchPayloadBuilder.TryBuildRectanglePayload(top, out var payload, out _);- Assert.False(ready);- Assert.Null(payload);++ var patch = new FacePatchDescriptor(top, [], [], FacePatchOrientationRole.Forward, "outer", []);+ var readiness = new MaterializationReadinessReport(true, EmissionReadiness.EvidenceReadyForEmission, [], [], 1, 1, 1, 0, 0, 0, 0, [], false);+ var result = new PlanarSurfaceMaterializer().Emit(patch, readiness);++ Assert.True(result.Success);+ Assert.NotNull(result.Body);+ Assert.Single(result.Body!.Topology.Faces);+ Assert.Single(result.Body.Topology.Loops);+ Assert.Single(result.Body.Topology.Edges);+ Assert.Single(result.Body.Topology.Vertices);+ var edge = Assert.Single(result.Body.Topology.Edges);+ Assert.Equal(edge.StartVertexId, edge.EndVertexId);+ var edgeBinding = Assert.Single(result.Body.Bindings.EdgeBindings);+ Assert.Equal(0d, edgeBinding.TrimInterval!.Value.Start);+ Assert.Equal(2d * double.Pi, edgeBinding.TrimInterval!.Value.End);+ Assert.True(result.Body.Geometry.TryGetCurve(edgeBinding.CurveGeometryId, out var curve));+ Assert.Equal(CurveGeometryKind.Circle3, curve!.Kind);+ Assert.Contains(result.Diagnostics, d => d.Contains("circular", StringComparison.OrdinalIgnoreCase));+ }++ [Fact]+ public void PlanarSurfaceMaterializer_CylinderBottomCap_FromSourceSurface_EmitsCircularTopology()+ {+ var extraction = SourceSurfaceExtractor.Extract(new CirCylinderNode(3, 8));+ var bottom = Assert.Single(extraction.Descriptors.Where(c => c.ParameterPayloadReference == "cap-bottom"));++ var patch = new FacePatchDescriptor(bottom, [], [], FacePatchOrientationRole.Reversed, "outer", []);+ var readiness = new MaterializationReadinessReport(true, EmissionReadiness.EvidenceReadyForEmission, [], [], 1, 1, 1, 0, 0, 0, 0, [], false);+ var result = new PlanarSurfaceMaterializer().Emit(patch, readiness);++ Assert.True(result.Success);+ Assert.NotNull(result.Body);+ var surfaceBinding = Assert.Single(result.Body!.Bindings.FaceBindings);+ Assert.True(result.Body.Geometry.TryGetSurface(surfaceBinding.SurfaceGeometryId, out var surface));+ Assert.Equal(SurfaceGeometryKind.Plane, surface!.Kind);+ Assert.True(surface.Plane!.Value.Normal.Z < 0d);+ }++ [Fact]+ public void PlanarSurfaceMaterializer_RejectsCircularCap_WhenReadinessDeferred()+ {+ var extraction = SourceSurfaceExtractor.Extract(new CirCylinderNode(3, 8));+ var top = Assert.Single(extraction.Descriptors.Where(c => c.ParameterPayloadReference == "cap-top"));++ var patch = new FacePatchDescriptor(top, [], [], FacePatchOrientationRole.Forward, "outer", []);+ var readiness = new MaterializationReadinessReport(true, EmissionReadiness.Deferred, [EmissionBlockingReason.TopologyPlanning], [], 1, 1, 1, 0, 0, 0, 0, [], false);+ var result = new PlanarSurfaceMaterializer().Emit(patch, readiness);++ Assert.False(result.Success);+ Assert.Null(result.Body);+ Assert.Contains(result.Diagnostics, d => d.Contains("no readiness, no emission", StringComparison.OrdinalIgnoreCase));+ }+++ [Fact]+ public void SourceSurfaceExtractor_DefersShearedCylinderCapCircularGeometry_AndEmitterRejectsMissingCircle()+ {+ var nonUniformScale = Transform3D.CreateScale(new Vector3D(2d, 1d, 1d));+ var extraction = SourceSurfaceExtractor.Extract(new CirTransformNode(new CirCylinderNode(3, 8), nonUniformScale));+ var top = Assert.Single(extraction.Descriptors.Where(c => c.ParameterPayloadReference == "cap-top"));++ Assert.Null(top.BoundedPlanarGeometry);+ Assert.Contains(extraction.Diagnostics, d => d.Code == "cylinder-cap-circular-geometry-deferred");var patch = new FacePatchDescriptor(top, [], [], FacePatchOrientationRole.Forward, "outer", []);var readiness = new MaterializationReadinessReport(true, EmissionReadiness.EvidenceReadyForEmission, [], [], 1, 1, 1, 0, 0, 0, 0, [], false);diff --git a/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs b/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.csindex dd7923ad..abb0f1f6 100644--- a/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs+++ b/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs@@ -182,9 +182,17 @@ internal sealed class PlanarSurfaceMaterializer : ISurfaceFamilyMaterializerreturn new(false, null, SurfacePatchFamily.Planar, false, ["planar-f9-limited-scope: supports only rectangular untrimmed planar patches."]);}+ if (TryBuildCircularEmissionInput(patch.SourceSurface, out var circle, out var circleDiagnostic))+ {+ return EmitCircularBody(circle!.Value);+ }+if (!TryParseRectanglePayload(patch.SourceSurface.ParameterPayloadReference, out var points, out var parseReason)){- return new(false, null, SurfacePatchFamily.Planar, false, [$"planar-f9-payload-invalid: {parseReason}"]);+ return new(false, null, SurfacePatchFamily.Planar, false, [+ $"planar-f9-payload-invalid: {parseReason}",+ $"planar-f10.3-circle-evaluation: {circleDiagnostic}"+ ]);}return EmitRectangleBody(points!);@@ -227,6 +235,77 @@ internal sealed class PlanarSurfaceMaterializer : ISurfaceFamilyMaterializer["topology-emitted: planar rectangular patch emitted as a minimal single-face body."]);}+ private readonly record struct CircularPatchEmissionInput(Point3D Center, Vector3D Normal, double Radius);+++ private static SurfaceMaterializationResult EmitCircularBody(CircularPatchEmissionInput circle)+ {+ var builder = new TopologyBuilder();+ var vertex = builder.AddVertex();+ var edge = builder.AddEdge(vertex, vertex);++ var loopId = builder.AllocateLoopId();+ var coedgeId = builder.AllocateCoedgeId();+ builder.AddCoedge(new Coedge(coedgeId, edge, loopId, coedgeId, coedgeId, IsReversed: false));+ builder.AddLoop(new Loop(loopId, [coedgeId]));++ var face = builder.AddFace([loopId]);+ var shell = builder.AddShell([face]);+ builder.AddBody([shell]);++ var normal = Direction3D.Create(circle.Normal);+ var xAxis = BuildReferenceAxis(normal);++ var geometry = new BrepGeometryStore();+ geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromCircle(new Circle3Curve(circle.Center, normal, circle.Radius, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromPlane(new PlaneSurface(circle.Center, normal, xAxis)));++ var bindings = new BrepBindingModel();+ bindings.AddEdgeBinding(new EdgeGeometryBinding(edge, new CurveGeometryId(1), new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddFaceBinding(new FaceGeometryBinding(face, new SurfaceGeometryId(1)));++ return new(true, new BrepBody(builder.Model, geometry, bindings), SurfacePatchFamily.Planar, true,+ [+ "readiness-gate-accepted: no readiness, no emission rule satisfied for circular planar patch.",+ "circular-geometry-accepted: bounded planar circle center/normal/radius consumed.",+ "topology-emitted: planar circular patch emitted as a minimal single-face body with one circular outer loop."+ ]);+ }++ private static bool TryBuildCircularEmissionInput(SourceSurfaceDescriptor source, out CircularPatchEmissionInput? input, out string diagnostic)+ {+ input = null;+ if (source.BoundedPlanarGeometry is not { } bounded || bounded.Kind != BoundedPlanarPatchGeometryKind.Circle)+ {+ diagnostic = "no-circle-bounded-geometry";+ return false;+ }++ if (bounded.Radius <= 0d || !double.IsFinite(bounded.Radius))+ {+ diagnostic = "invalid-circle-radius";+ return false;+ }++ if (bounded.Normal.Length <= 1e-12d)+ {+ diagnostic = "invalid-circle-normal";+ return false;+ }++ input = new CircularPatchEmissionInput(bounded.Center, bounded.Normal, bounded.Radius);+ diagnostic = "ok";+ return true;+ }++ private static Direction3D BuildReferenceAxis(Direction3D normal)+ {+ var n = normal.ToVector();+ var seed = double.Abs(n.Z) < 0.95d ? new Vector3D(0d, 0d, 1d) : new Vector3D(0d, 1d, 0d);+ var projected = seed - (n * seed.Dot(n));+ return Direction3D.TryCreate(projected, out var axis) ? axis : Direction3D.Create(new Vector3D(1d, 0d, 0d));+ }+private static bool TryParseRectanglePayload(string? payload, out IReadOnlyList<Point3D>? points, out string reason){points = null;diff --git a/docs/cir-f103-circular-planar-cap-emission.md b/docs/cir-f103-circular-planar-cap-emission.mdnew file mode 100644index 00000000..c392715b--- /dev/null+++ b/docs/cir-f103-circular-planar-cap-emission.md@@ -0,0 +1,58 @@+# CIR-F10.3: circular planar cap emission in `PlanarSurfaceMaterializer`++## Scope++Implemented support for **one untrimmed circular planar patch** emitted from planar source descriptors whose bounded geometry is:++- `Kind = Circle`+- finite positive `Radius`+- non-zero `Normal`++This is strictly a single-face patch emission milestone, not full cylinder rematerialization.++## Readiness gate++Circular emission follows the same gate as rectangular emission:++- if readiness is `NotApplicable`, `Deferred`, or `Unsupported` => reject emission+- diagnostic includes `readiness-gate-rejected: no readiness, no emission.`++## Topology convention used++The emitter follows the circular edge convention already used in `BrepPrimitives.CreateCylinder(...)`:++- one self-loop edge (`startVertex == endVertex`)+- one loop containing one coedge+- one planar face bound to that loop+- one shell/body+- one circle curve binding with trim `[0, 2π]`++This keeps circular topology/export semantics aligned with existing kernel primitive practice.++## Diagnostics++On circular success, diagnostics now include explicit evidence for:++- readiness accepted+- circular bounded geometry accepted+- circular loop topology emitted++On failure (e.g., missing bounded circle), the rectangular payload parse path still fails and includes a circular evaluation diagnostic token.++## Rejected / deferred cases++Still intentionally rejected/deferred in CIR-F10.3:++- trimmed circular faces+- annular faces / inner holes / multiple loops+- non-planar surfaces+- full cylinder shell assembly+- cylindrical side emission+- elliptical/sheared cap emission++For sheared/non-uniform transforms, `SourceSurfaceExtractor` continues to defer circular bounded geometry and emits+`cylinder-cap-circular-geometry-deferred`.++## Relationship to future work++This unlocks cap-only circular planar emission from real cylinder source descriptors while preserving SEM-A0 guardrails (no generated topology naming) and without changing STEP exporter behavior.