Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add EDGE-X2 concave planar AirChamfer patch lab proof
Yuechen Libba7085f371a
diff --git a/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPatchLab.cs b/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPatchLab.csnew file mode 100644index 00000000..b2319081--- /dev/null+++ b/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPatchLab.cs@@ -0,0 +1,111 @@+using System.Numerics;++namespace Aetheris.Firmament.FrictionLab.CIRLab;++public sealed record AirChamferPatchCase(string CaseName, Vector3 EdgeStart, Vector3 EdgeEnd, Vector3 FaceANormal, Vector3 FaceBNormal, double ChamferDistance);+public sealed record AirChamferPatchArtifact(IReadOnlyList<Vector3> Vertices, IReadOnlyList<(int A, int B)> Edges, Vector3 PlaneNormal, double Area);+public sealed record AirChamferPatchTopologySummary(bool PatchProduced, int VertexCount, int EdgeCount, int FaceCount, int PlanarFaceCount, int BoundaryLoopCount, int CoedgeCount);+public sealed record AirChamferPatchRow(string CaseName, LabProfileStatus Status, bool OffsetCurveAConstructed, bool OffsetCurveBConstructed, AirChamferPatchTopologySummary Topology, AirChamferPatchArtifact? Artifact, IReadOnlyList<string> Diagnostics, string Recommendation);++public static class AirChamferPatchLab+{+ private const double Tol = 1e-9;+ public static readonly IReadOnlySet<string> AllowedRecommendations = new HashSet<string>(StringComparer.Ordinal)+ {+ "air-chamfer-patch-constructive-proof-succeeded",+ "air-chamfer-patch-needs-brep-open-shell-support",+ "air-chamfer-patch-invalid-rejected",+ "air-chamfer-patch-deferred-topology"+ };++ public static AirChamferPatchCase Canonical(double edgeLength = 10d, double distance = 1d)+ {+ var hz = (float)(edgeLength / 2d);+ return new(+ $"canonical-l{edgeLength:0.###}-d{distance:0.###}",+ new Vector3(0f, 0f, -hz),+ new Vector3(0f, 0f, hz),+ new Vector3(1f, 0f, 0f),+ new Vector3(0f, 1f, 0f),+ distance);+ }++ public static IReadOnlyList<AirChamferPatchRow> RunAll() =>+ [+ Run(Canonical(10d, 1d)),+ Run(Canonical(10d, 2d)),+ Run(Canonical(7.5d, 1d)),+ Run(Canonical(10d, 0d) with { CaseName = "invalid-distance-zero" }),+ Run(Canonical(10d, double.NaN) with { CaseName = "invalid-distance-nan" }),+ Run(Canonical(0d, 1d) with { CaseName = "invalid-edge-length-zero" }),+ Run(Canonical(10d, 1d) with { CaseName = "invalid-edge-non-finite", EdgeStart = new Vector3(float.NaN, 0f, 0f) }),+ Run(Canonical(10d, 1d) with { CaseName = "invalid-face-adjacency-parallel", FaceBNormal = new Vector3(1f, 0f, 0f) })+ ];++ public static AirChamferPatchRow Run(AirChamferPatchCase c)+ {+ var d = new List<string> { "edge-x2-air-chamfer-patch-lab-started" };+ d.Add("edge-x2-no-3d-boolean-used");++ if (!Finite(c.ChamferDistance) || c.ChamferDistance <= Tol)+ return Reject(c.CaseName, d, "edge-x2-invalid-distance-rejected");+ if (!Finite(c.EdgeStart) || !Finite(c.EdgeEnd))+ return Reject(c.CaseName, d, "edge-x2-invalid-edge-rejected");++ var edge = c.EdgeEnd - c.EdgeStart;+ var edgeLen = edge.Length();+ if (!Finite(edgeLen) || edgeLen <= Tol)+ return Reject(c.CaseName, d, "edge-x2-invalid-edge-rejected");++ if (!TryNormalize(c.FaceANormal, out var nA) || !TryNormalize(c.FaceBNormal, out var nB))+ return Reject(c.CaseName, d, "edge-x2-invalid-face-adjacency-rejected");++ if (!TryNormalize(edge, out var eDir))+ return Reject(c.CaseName, d, "edge-x2-invalid-edge-rejected");++ var offA = Vector3.Cross(eDir, nA);+ var offB = Vector3.Cross(nB, eDir);+ if (!TryNormalize(offA, out offA) || !TryNormalize(offB, out offB) || Math.Abs(Vector3.Dot(offA, offB)) >= 1d - 1e-8)+ return Reject(c.CaseName, d, "edge-x2-invalid-face-adjacency-rejected");++ d.Add("edge-x2-concave-planar-edge-accepted");++ var a0 = c.EdgeStart + offA * (float)c.ChamferDistance;+ var a1 = c.EdgeEnd + offA * (float)c.ChamferDistance;+ d.Add("edge-x2-offset-curve-a-constructed");+ var b0 = c.EdgeStart + offB * (float)c.ChamferDistance;+ var b1 = c.EdgeEnd + offB * (float)c.ChamferDistance;+ d.Add("edge-x2-offset-curve-b-constructed");++ var verts = new[] { a0, a1, b1, b0 };+ var normal = Vector3.Cross(a1 - a0, b0 - a0);+ if (!TryNormalize(normal, out normal))+ return Reject(c.CaseName, d, "edge-x2-invalid-face-adjacency-rejected");++ var area = 0.5d * Vector3.Cross(a1 - a0, b1 - a0).Length() + 0.5d * Vector3.Cross(b1 - a0, b0 - a0).Length();+ var artifact = new AirChamferPatchArtifact(verts, [(0, 1), (1, 2), (2, 3), (3, 0)], normal, area);+ d.Add("edge-x2-ruled-chamfer-patch-constructed");+ d.Add("edge-x2-patch-topology-captured");+ d.Add("edge-x2-step-smoke-deferred:open-patch-export-unsupported");++ return new(c.CaseName, LabProfileStatus.Succeeded, true, true, new(true, 4, 4, 1, 1, 1, 4), artifact,+ d.Distinct().OrderBy(x => x, StringComparer.Ordinal).ToArray(), "air-chamfer-patch-constructive-proof-succeeded");+ }++ private static AirChamferPatchRow Reject(string caseName, List<string> d, string why)+ {+ d.Add(why);+ return new(caseName, LabProfileStatus.Failed, false, false, new(false, 0, 0, 0, 0, 0, 0), null,+ d.Distinct().OrderBy(x => x, StringComparer.Ordinal).ToArray(), "air-chamfer-patch-invalid-rejected");+ }++ private static bool Finite(double x) => !double.IsNaN(x) && !double.IsInfinity(x);+ private static bool Finite(Vector3 v) => float.IsFinite(v.X) && float.IsFinite(v.Y) && float.IsFinite(v.Z);+ private static bool TryNormalize(Vector3 v, out Vector3 normalized)+ {+ var len = v.Length();+ if (!float.IsFinite(len) || len <= Tol) { normalized = default; return false; }+ normalized = v / len;+ return Finite(normalized);+ }+}diff --git a/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPatchLabTests.cs b/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPatchLabTests.csnew file mode 100644index 00000000..b13f5191--- /dev/null+++ b/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPatchLabTests.cs@@ -0,0 +1,67 @@+using Aetheris.Firmament.FrictionLab.CIRLab;++namespace Aetheris.FrictionLab.Tests.CIRLab;++public sealed class AirChamferPatchLabTests+{+ [Fact]+ public void Rows_AreDeterministic()+ {+ var a = AirChamferPatchLab.RunAll();+ var b = AirChamferPatchLab.RunAll();+ Assert.Equal(a.Select(Serialize), b.Select(Serialize));+ }++ [Fact]+ public void Canonical_Succeeds_WithExpectedTopologyAndDiagnostics()+ {+ var row = AirChamferPatchLab.Run(AirChamferPatchLab.Canonical(10d, 1d));+ Assert.Equal(LabProfileStatus.Succeeded, row.Status);+ Assert.True(row.OffsetCurveAConstructed);+ Assert.True(row.OffsetCurveBConstructed);+ Assert.True(row.Topology.PatchProduced);+ Assert.Equal(4, row.Topology.VertexCount);+ Assert.Equal(4, row.Topology.EdgeCount);+ Assert.Equal(1, row.Topology.FaceCount);+ Assert.Equal(1, row.Topology.PlanarFaceCount);+ Assert.Equal(1, row.Topology.BoundaryLoopCount);+ Assert.Contains("edge-x2-concave-planar-edge-accepted", row.Diagnostics);+ Assert.Contains("edge-x2-offset-curve-a-constructed", row.Diagnostics);+ Assert.Contains("edge-x2-offset-curve-b-constructed", row.Diagnostics);+ Assert.Contains("edge-x2-ruled-chamfer-patch-constructed", row.Diagnostics);+ Assert.Contains("edge-x2-no-3d-boolean-used", row.Diagnostics);+ Assert.NotNull(row.Artifact);+ Assert.True(row.Artifact!.Area > 0d);+ }++ [Theory]+ [InlineData(0d)]+ [InlineData(-1d)]+ public void InvalidDistance_Rejects(double distance)+ {+ var row = AirChamferPatchLab.Run(AirChamferPatchLab.Canonical(10d, distance));+ Assert.Equal(LabProfileStatus.Failed, row.Status);+ Assert.Contains("edge-x2-invalid-distance-rejected", row.Diagnostics);+ Assert.False(row.Topology.PatchProduced);+ }++ [Fact]+ public void InvalidFaceAdjacency_RejectsBeforePatch()+ {+ var c = AirChamferPatchLab.Canonical() with { FaceBNormal = new(1f, 0f, 0f) };+ var row = AirChamferPatchLab.Run(c);+ Assert.Equal(LabProfileStatus.Failed, row.Status);+ Assert.Contains("edge-x2-invalid-face-adjacency-rejected", row.Diagnostics);+ Assert.DoesNotContain("edge-x2-ruled-chamfer-patch-constructed", row.Diagnostics);+ }++ [Fact]+ public void Recommendations_AreFiniteAllowedSet()+ {+ foreach (var row in AirChamferPatchLab.RunAll())+ Assert.Contains(row.Recommendation, AirChamferPatchLab.AllowedRecommendations);+ }++ private static string Serialize(AirChamferPatchRow row)+ => $"{row.CaseName}|{row.Status}|{row.OffsetCurveAConstructed}|{row.OffsetCurveBConstructed}|{row.Topology.PatchProduced}|{row.Topology.VertexCount}|{row.Topology.EdgeCount}|{row.Topology.FaceCount}|{row.Topology.PlanarFaceCount}|{row.Topology.BoundaryLoopCount}|{row.Topology.CoedgeCount}|{row.Recommendation}|{string.Join(',', row.Diagnostics)}";+}diff --git a/docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.md b/docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.mdindex f1c53dc7..206b6ffa 100644--- a/docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.md+++ b/docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.md@@ -256,3 +256,8 @@ Each future `AirEdgeSweep` PR should include:## EDGE-X1 follow-up note- EDGE-X1 added a decision-grade chamfer/fillet capability and diagnostic matrix inventory: `docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md`.- This confirms current bounded chamfer/fillet routes remain legacy-authoritative and defines first AirEdgeSweep lab sequencing from observed support/reject envelopes.+++## EDGE-X2 follow-on++A lab-only constructive concave planar AirChamfer patch proof was added in EDGE-X2 (`docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.md`) without production chamfer/fillet migration.diff --git a/docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md b/docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.mdindex 1104ef7e..7429c470 100644--- a/docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md+++ b/docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md@@ -170,3 +170,8 @@ Evidence-driven recommended order:- No STEP importer/exporter changes.- No Boolean core changes.- No test weakening.+++## EDGE-X2 note++EDGE-X2 starts the first constructive AirChamfer proof lane with a lab-only concave planar single-edge patch artifact (`docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.md`).diff --git a/docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.md b/docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.mdnew file mode 100644index 00000000..f82c81cf--- /dev/null+++ b/docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.md@@ -0,0 +1,79 @@+# EDGE-X2 — Concave planar chamfer AirEdgeSweep patch lab++## Purpose and scope+This milestone adds a **lab-only constructive proof** for `AirChamfer` as an `AirEdgeSweep`-style edge patch over a single concave planar edge. It does not modify production body-editing behavior.++References:+- `docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.md`+- `docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md`++## Why concave planar chamfer first+EDGE-A0 and EDGE-X1 concluded that the lowest-risk first lane is a local concave planar chamfer patch with no edge chains/corners and no migration of legacy routes.++## Local coordinate model+Canonical case:+- shared edge on Z axis from `(0,0,-h/2)` to `(0,0,+h/2)`+- Face A normal `+X`+- Face B normal `+Y`+- chamfer distance `d > 0`++## Offset-curve construction+Given edge direction `e` and planar face normals:+- offset-A direction: `normalize(cross(e, nA))`+- offset-B direction: `normalize(cross(nB, e))`++Offsets are applied to both edge endpoints at distance `d`, yielding two offset lines (`A0-A1`, `B0-B1`).++## Ruled/planar patch construction+The patch artifact is a deterministic quad:+`[A0, A1, B1, B0]`, with boundary edges `(0-1,1-2,2-3,3-0)`.+Plane normal is derived from cross products of quad spans, and area is reported.++## Test cases and results+Covered cases:+- valid canonical `h=10, d=1`+- valid canonical `h=10, d=2`+- valid canonical `h=7.5, d=1`+- invalid: `d<=0`+- invalid: non-finite `d`+- invalid: zero edge length+- invalid: non-finite edge endpoint+- invalid: degenerate/parallel face adjacency++Result: constructive proof succeeded for valid canonical cases, with deterministic topology/artifact rows and deterministic diagnostics.++## Topology/artifact findings+For valid canonical rows:+- patch produced+- vertices: 4+- edges: 4+- faces: 1+- planar faces: 1+- boundary loops: 1+- coedges: 4++## STEP/export status+`edge-x2-step-smoke-deferred:open-patch-export-unsupported` is emitted in this lab.+No `Step242Exporter` changes were made.++## No-3D-Boolean guarantee+Each run emits `edge-x2-no-3d-boolean-used`.+No boolean subtraction or 3D boolean fallback is used in the candidate path.++## Invalid-case handling+Invalid input is rejected before patch construction with explicit diagnostics:+- `edge-x2-invalid-distance-rejected`+- `edge-x2-invalid-edge-rejected`+- `edge-x2-invalid-face-adjacency-rejected`++## Non-goals (preserved)+- no production chamfer behavior change+- no convex replacement+- no fillet implementation+- no edge chains/corner chains+- no STEP importer/exporter changes+- no boolean core changes+- no sketch solver/clipping/NURBS/freeform additions++## Recommendation for next milestone+Recommended next step: **EDGE-X2.1 non-orthogonal concave patch lab** to expand admissible planar adjacency while keeping local patch-only scope.