Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement CIR-F9 gated planar surface emission
Yuechen Li704d7a06f29f
diff --git a/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.csindex 57b13591..15edaa6f 100644--- a/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/SurfacePatchDescriptorScaffoldTests.cs@@ -1,5 +1,6 @@using Aetheris.Kernel.Core.Geometry;using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Cir;using Aetheris.Kernel.Firmament.Execution;namespace Aetheris.Kernel.Firmament.Tests;@@ -74,4 +75,59 @@ public sealed class SurfacePatchDescriptorScaffoldTestsAssert.Equal("surface_family_spherical", eval.Selected?.Name);Assert.Contains(eval.Rejections, r => r.CandidateName == "surface_family_planar" && r.Reason.Contains("mismatch", StringComparison.OrdinalIgnoreCase));}++ [Fact]+ public void PlanarSurfaceMaterializer_UntrimmedBoxFace_EmitsPlanarTopology()+ {+ var source = new SourceSurfaceDescriptor(SurfacePatchFamily.Planar, "rect3d:-1,-1,0;1,-1,0;1,1,0;-1,1,0", Transform3D.Identity, "cir:box:face", nameof(CirBoxNode), 0, FacePatchOrientationRole.Forward);+ var patch = new FacePatchDescriptor(source, [], [], 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.Equal(4, result.Body.Topology.Edges.Count());+ Assert.Equal(4, result.Body.Topology.Vertices.Count());+ }++ [Fact]+ public void PlanarSurfaceMaterializer_RejectsDeferredReadiness()+ {+ var source = new SourceSurfaceDescriptor(SurfacePatchFamily.Planar, "rect3d:0,0,0;1,0,0;1,1,0;0,1,0", Transform3D.Identity, "cir:box:face", nameof(CirBoxNode), 0, FacePatchOrientationRole.Forward);+ var patch = new FacePatchDescriptor(source, [], [], 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 PlanarSurfaceMaterializer_RejectsNonPlanarPatch()+ {+ var source = new SourceSurfaceDescriptor(SurfacePatchFamily.Spherical, "sphere", Transform3D.Identity, "cir:sphere", nameof(CirSphereNode), 0, FacePatchOrientationRole.Forward);+ var patch = new FacePatchDescriptor(source, [], [], 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.False(result.Success);+ Assert.Contains(result.Diagnostics, d => d.Contains("only supports planar", StringComparison.OrdinalIgnoreCase));+ }++ [Fact]+ public void PlanarSurfaceMaterializer_RejectsTrimmedCircularPatch()+ {+ var source = new SourceSurfaceDescriptor(SurfacePatchFamily.Planar, "rect3d:0,0,0;1,0,0;1,1,0;0,1,0", Transform3D.Identity, "cir:box:face", nameof(CirBoxNode), 0, FacePatchOrientationRole.Forward);+ var trim = new TrimCurveDescriptor(TrimCurveFamily.Circle, "circle", "outer", 0, new ParameterInterval(0, 2 * double.Pi), TrimCurveCapability.ExactSupported);+ var patch = new FacePatchDescriptor(source, [trim], [], 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.False(result.Success);+ Assert.Contains(result.Diagnostics, d => d.Contains("supports only rectangular untrimmed", StringComparison.OrdinalIgnoreCase));+ }}diff --git a/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs b/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.csindex 189f356d..dafb5933 100644--- a/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs+++ b/Aetheris.Kernel.Firmament/Execution/SurfacePatchDescriptorScaffold.cs@@ -1,6 +1,10 @@using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Geometry.Curves;+using Aetheris.Kernel.Core.Geometry.Surfaces;+using Aetheris.Kernel.Core.Brep;using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Core.Judgment;+using Aetheris.Kernel.Core.Topology;namespace Aetheris.Kernel.Firmament.Execution;@@ -136,8 +140,106 @@ internal sealed class PlanarSurfaceMaterializer : ISurfaceFamilyMaterializerreturn new(true, "admissible", 10d);}++ internal SurfaceMaterializationResult Emit(FacePatchDescriptor patch, MaterializationReadinessReport readiness)+ {+ if (patch.SourceSurface.Family != SurfacePatchFamily.Planar)+ {+ return new(false, null, SurfacePatchFamily.Unsupported, false, ["unsupported-surface-family: PlanarSurfaceMaterializer only supports planar source patches."]);+ }++ if (readiness.OverallReadiness is EmissionReadiness.NotApplicable or EmissionReadiness.Deferred or EmissionReadiness.Unsupported)+ {+ return new(false, null, SurfacePatchFamily.Planar, false, ["readiness-gate-rejected: no readiness, no emission."]);+ }++ if (patch.InnerLoops.Count > 0 || patch.OuterLoop.Count > 0)+ {+ return new(false, null, SurfacePatchFamily.Planar, false, ["planar-f9-limited-scope: supports only rectangular untrimmed planar patches."]);+ }++ if (!TryParseRectanglePayload(patch.SourceSurface.ParameterPayloadReference, out var points, out var parseReason))+ {+ return new(false, null, SurfacePatchFamily.Planar, false, [$"planar-f9-payload-invalid: {parseReason}"]);+ }++ return EmitRectangleBody(points!);+ }++ private static SurfaceMaterializationResult EmitRectangleBody(IReadOnlyList<Point3D> p)+ {+ var builder = new TopologyBuilder();+ var v = new[] { builder.AddVertex(), builder.AddVertex(), builder.AddVertex(), builder.AddVertex() };+ var e = new[] { builder.AddEdge(v[0], v[1]), builder.AddEdge(v[1], v[2]), builder.AddEdge(v[2], v[3]), builder.AddEdge(v[3], v[0]) };+ var loopId = builder.AllocateLoopId();+ var coedgeIds = new[] { builder.AllocateCoedgeId(), builder.AllocateCoedgeId(), builder.AllocateCoedgeId(), builder.AllocateCoedgeId() };+ for (var i = 0; i < 4; i++)+ {+ var next = coedgeIds[(i + 1) % 4];+ var prev = coedgeIds[(i + 3) % 4];+ builder.AddCoedge(new Coedge(coedgeIds[i], e[i], loopId, next, prev, IsReversed: false));+ }++ builder.AddLoop(new Loop(loopId, coedgeIds));+ var face = builder.AddFace([loopId]);+ var shell = builder.AddShell([face]);+ builder.AddBody([shell]);++ var geometry = new BrepGeometryStore();+ geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromLine(new Line3Curve(p[0], Direction3D.Create(p[1] - p[0]))));+ geometry.AddCurve(new CurveGeometryId(2), CurveGeometry.FromLine(new Line3Curve(p[1], Direction3D.Create(p[2] - p[1]))));+ geometry.AddCurve(new CurveGeometryId(3), CurveGeometry.FromLine(new Line3Curve(p[2], Direction3D.Create(p[3] - p[2]))));+ geometry.AddCurve(new CurveGeometryId(4), CurveGeometry.FromLine(new Line3Curve(p[3], Direction3D.Create(p[0] - p[3]))));++ var normal = Direction3D.Create((p[1] - p[0]).Cross(p[3] - p[0]));+ var xAxis = Direction3D.Create(p[1] - p[0]);+ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromPlane(new PlaneSurface(p[0], normal, xAxis)));++ var bindings = new BrepBindingModel();+ for (var i = 0; i < 4; i++) bindings.AddEdgeBinding(new EdgeGeometryBinding(e[i], new CurveGeometryId(i + 1), new ParameterInterval(0d, 1d)));+ bindings.AddFaceBinding(new FaceGeometryBinding(face, new SurfaceGeometryId(1)));++ return new(true, new BrepBody(builder.Model, geometry, bindings), SurfacePatchFamily.Planar, true,+ ["topology-emitted: planar rectangular patch emitted as a minimal single-face body."]);+ }++ private static bool TryParseRectanglePayload(string? payload, out IReadOnlyList<Point3D>? points, out string reason)+ {+ points = null;+ reason = "missing rectangular payload.";+ if (string.IsNullOrWhiteSpace(payload) || !payload.StartsWith("rect3d:", StringComparison.Ordinal)) return false;+ var segments = payload[7..].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);+ if (segments.Length != 4)+ {+ reason = "rect3d payload must contain exactly 4 points.";+ return false;+ }++ var parsed = new List<Point3D>(4);+ foreach (var segment in segments)+ {+ var xyz = segment.Split(',', StringSplitOptions.TrimEntries);+ if (xyz.Length != 3 || !double.TryParse(xyz[0], out var x) || !double.TryParse(xyz[1], out var y) || !double.TryParse(xyz[2], out var z))+ {+ reason = "rect3d point values must be numeric x,y,z triples.";+ return false;+ }+ parsed.Add(new Point3D(x, y, z));+ }++ points = parsed;+ reason = "ok";+ return true;+ }}+internal sealed record SurfaceMaterializationResult(+ bool Success,+ BrepBody? Body,+ SurfacePatchFamily EmittedSurfaceFamily,+ bool TopologyEmissionImplemented,+ IReadOnlyList<string> Diagnostics);+internal sealed class CylindricalSurfaceMaterializer : ISurfaceFamilyMaterializer{public SurfacePatchFamily Family => SurfacePatchFamily.Cylindrical;diff --git a/docs/cir-f9-planar-surface-materializer.md b/docs/cir-f9-planar-surface-materializer.mdnew file mode 100644index 00000000..0ebb3828--- /dev/null+++ b/docs/cir-f9-planar-surface-materializer.md@@ -0,0 +1,53 @@+# CIR-F9: first gated PlanarSurfaceMaterializer BRep emission++## Scope++CIR-F9 introduces the first bounded surface-family emission path from a `FacePatchDescriptor` to concrete BRep topology for a single trivial planar case.++Supported in this milestone:++- `PlanarSurfaceMaterializer.Emit` for **rectangular untrimmed planar patches** encoded by `SourceSurfaceDescriptor.ParameterPayloadReference` as `rect3d:x1,y1,z1;x2,y2,z2;x3,y3,z3;x4,y4,z4`.+- Emission of a minimal single-face BRep body (face/loop/edge/coedge/vertex topology, planar surface binding, line edge bindings).++## Readiness gate++The emission method is explicitly gated by `MaterializationReadinessReport`.++Rule: **No readiness, no emission.**++Emission is rejected when `OverallReadiness` is:++- `NotApplicable`+- `Deferred`+- `Unsupported`++This preserves CIR-F8.10 semantics while allowing a narrow local implementation.++## Rejected cases++CIR-F9 rejects:++- non-planar source surface families,+- any patch with outer or inner trims (including circular trims),+- planar descriptors missing the bounded `rect3d:` payload.++Diagnostic messages are returned in `SurfaceMaterializationResult.Diagnostics`.++## Relation to CIR-F8.10++`MaterializationReadinessAnalyzer` still reports global topology emission as not implemented. CIR-F9 does not generalize that; it adds a localized, explicitly constrained emission path in `PlanarSurfaceMaterializer` only.++## Non-goals++CIR-F9 does **not** implement:++- general topology assembly,+- spherical/cylindrical/conical/toroidal emission,+- circle/ellipse trim solving,+- public CLI exposure,+- production STEP/export behavior changes,+- generated topology naming.++## Next step++CIR-F10 should replace synthetic `rect3d:` input with direct consumption of real dry-run planned patch/loop evidence for exact-ready planar faces without expanding to circular trims.