Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add CIR-BREP-X8 generic CIR-to-BRep FrictionLab executor and tests

Yuechen Life9d7f7c8652
diff --git a/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLab.cs b/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLab.cs
new file mode 100644
index 00000000..5560c069
--- /dev/null
+++ b/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLab.cs
@@ -0,0 +1,157 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Cir;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Step242;
+using Aetheris.Kernel.Firmament.Materializer;
+
+namespace Aetheris.Firmament.FrictionLab.CIRLab;
+
+public static class GenericCirBrepExecutorLab
+{
+ public static GenericCirBrepScenarioReport RunScenarioMatrix()
+ {
+ var scenarios = new[]
+ {
+ Execute("A-ThroughHole", BuildThroughHole()),
+ Execute("B-BlindHole", BuildBlindHole()),
+ Execute("C-Counterbore", BuildCounterbore()),
+ Execute("D-Countersink", BuildCountersink()),
+ Execute("E-SteppedHole", BuildStepped()),
+ Execute("F-BoxMinusSphere", new CirSubtractNode(new CirBoxNode(20,20,20), new CirSphereNode(4))),
+ Execute("F-BoxMinusTorus", new CirSubtractNode(new CirBoxNode(20,20,20), new CirTorusNode(5,2))),
+ Execute("F-UnsupportedTransform", new CirTransformNode(new CirBoxNode(10,10,10), Transform3D.CreateRotationZ(double.Pi/4d))),
+ };
+
+ return new GenericCirBrepScenarioReport(scenarios, ["CIR-BREP-X8 matrix executed."]);
+ }
+
+ public static GenericCirBrepExecutorLabResult Execute(string scenario, CirNode node)
+ {
+ var diagnostics = new List<string>();
+ var bools = new List<string>();
+ var result = TryExecuteNode(node, diagnostics, bools);
+ if (!result.IsSuccess || result.Body is null)
+ {
+ return new(scenario, result.IsUnsupported ? GenericCirBrepLabStatus.Unsupported : GenericCirBrepLabStatus.Failed, null, result.FailureCode, diagnostics, bools, false, false, [], false, "n/a", 0);
+ }
+
+ var step = Step242Exporter.ExportBody(result.Body);
+ var stepText = step.IsSuccess ? step.Value : string.Empty;
+ var markers = new List<string>
+ {
+ stepText.Contains("ISO-10303-21", StringComparison.Ordinal) ? "ISO-10303-21" : "missing:ISO-10303-21",
+ stepText.Contains("ADVANCED_FACE", StringComparison.Ordinal) ? "ADVANCED_FACE" : "missing:ADVANCED_FACE",
+ stepText.Contains("MANIFOLD_SOLID_BREP", StringComparison.Ordinal) ? "MANIFOLD_SOLID_BREP" : (stepText.Contains("BREP_WITH_VOIDS", StringComparison.Ordinal) ? "BREP_WITH_VOIDS" : "missing:solid-root"),
+ stepText.Contains("CYLINDRICAL_SURFACE", StringComparison.Ordinal) ? "CYLINDRICAL_SURFACE" : "missing:CYLINDRICAL_SURFACE",
+ stepText.Contains("CONICAL_SURFACE", StringComparison.Ordinal) ? "CONICAL_SURFACE" : "missing:CONICAL_SURFACE",
+ };
+
+ return new(scenario, GenericCirBrepLabStatus.Succeeded, result.Body, "none", diagnostics, bools, true, step.IsSuccess, markers, result.Body.SafeBooleanComposition is not null, stepText.Contains("MANIFOLD_SOLID_BREP", StringComparison.Ordinal) ? "MANIFOLD_SOLID_BREP" : "BREP_WITH_VOIDS", result.Body.Topology.Faces.Count());
+ }
+
+ private static (bool IsSuccess, bool IsUnsupported, BrepBody? Body, string FailureCode) TryExecuteNode(CirNode node, List<string> diagnostics, List<string> bools)
+ {
+ switch (node)
+ {
+ case CirBoxNode box:
+ var b = BrepPrimitives.CreateBox(box.Width, box.Height, box.Depth);
+ return b.IsSuccess ? (true, false, b.Value, "none") : (false, false, null, "primitive-box-failed");
+ case CirCylinderNode cyl:
+ var c = BrepPrimitives.CreateCylinder(cyl.Radius, cyl.Height);
+ return c.IsSuccess ? (true, false, c.Value, "none") : (false, false, null, "primitive-cylinder-failed");
+ case CirConeNode cone:
+ diagnostics.Add("Cone primitive mapping unavailable via public BrepPrimitives API in lab scope.");
+ return (false, true, null, "primitive-cone-unsupported");
+ case CirSphereNode sph:
+ var sp = BrepPrimitives.CreateSphere(sph.Radius);
+ return sp.IsSuccess ? (true, false, sp.Value, "none") : (false, true, null, "primitive-sphere-unsupported");
+ case CirTorusNode tor:
+ var tr = BrepPrimitives.CreateTorus(tor.MajorRadius, tor.MinorRadius);
+ return tr.IsSuccess ? (true, false, tr.Value, "none") : (false, true, null, "primitive-torus-unsupported");
+ case CirTransformNode tx:
+ if (!TryExtractTranslation(tx.Transform, out var t)) return (false, true, null, "transform-non-translation-unsupported");
+ var child = TryExecuteNode(tx.Child, diagnostics, bools);
+ if (!child.IsSuccess || child.Body is null) return child;
+ return (true, false, t == Vector3D.Zero ? child.Body : Translate(child.Body, t), "none");
+ case CirSubtractNode sub:
+ return ExecBool(sub.Left, sub.Right, BrepBoolean.Subtract, "Subtract", diagnostics, bools);
+ case CirUnionNode un:
+ return ExecBool(un.Left, un.Right, BrepBoolean.Union, "Union", diagnostics, bools);
+ case CirIntersectNode it:
+ return ExecBool(it.Left, it.Right, BrepBoolean.Intersect, "Intersect", diagnostics, bools);
+ default:
+ return (false, true, null, "node-kind-unsupported");
+ }
+ }
+
+ private static (bool IsSuccess, bool IsUnsupported, BrepBody? Body, string FailureCode) ExecBool(CirNode left, CirNode right, Func<BrepBody, BrepBody, Aetheris.Kernel.Core.Results.KernelResult<BrepBody>> op, string label, List<string> diagnostics, List<string> bools)
+ {
+ var l = TryExecuteNode(left, diagnostics, bools);
+ if (!l.IsSuccess || l.Body is null) return l;
+ var r = TryExecuteNode(right, diagnostics, bools);
+ if (!r.IsSuccess || r.Body is null) return r;
+ bools.Add(label);
+ var br = op(l.Body, r.Body);
+ if (!br.IsSuccess || br.Value is null)
+ {
+ diagnostics.AddRange(br.Diagnostics.Select(d => d.Code.ToString()));
+ return (false, false, null, $"boolean-{label.ToLowerInvariant()}-failed");
+ }
+ diagnostics.Add($"{label} success; safeComposition={(br.Value.SafeBooleanComposition is not null)}");
+ return (true, false, br.Value, "none");
+ }
+
+ private static BrepBody Translate(BrepBody body, Vector3D t)
+ {
+ var copy = new Dictionary<Aetheris.Kernel.Core.Topology.VertexId, Point3D>();
+ foreach (var v in body.Topology.Vertices)
+ {
+ if (body.TryGetVertexPoint(v.Id, out var point)) copy[v.Id] = point + t;
+ }
+ var g = new Aetheris.Kernel.Core.Brep.BrepGeometryStore();
+ foreach (var c in body.Geometry.Curves)
+ {
+ var gc = c.Value;
+ g.AddCurve(c.Key, gc.Kind switch
+ {
+ Aetheris.Kernel.Core.Geometry.CurveGeometryKind.Line3 => Aetheris.Kernel.Core.Geometry.CurveGeometry.FromLine(new Aetheris.Kernel.Core.Geometry.Curves.Line3Curve(gc.Line3!.Value.Origin + t, gc.Line3.Value.Direction)),
+ Aetheris.Kernel.Core.Geometry.CurveGeometryKind.Circle3 => Aetheris.Kernel.Core.Geometry.CurveGeometry.FromCircle(new Aetheris.Kernel.Core.Geometry.Curves.Circle3Curve(gc.Circle3!.Value.Center + t, gc.Circle3.Value.Normal, gc.Circle3.Value.Radius, gc.Circle3.Value.XAxis)),
+ _ => gc
+ });
+ }
+ foreach (var s in body.Geometry.Surfaces)
+ {
+ var gs = s.Value;
+ g.AddSurface(s.Key, gs.Kind switch
+ {
+ Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Plane => Aetheris.Kernel.Core.Geometry.SurfaceGeometry.FromPlane(new Aetheris.Kernel.Core.Geometry.Surfaces.PlaneSurface(gs.Plane!.Value.Origin + t, gs.Plane.Value.Normal, gs.Plane.Value.UAxis)),
+ Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cylinder => Aetheris.Kernel.Core.Geometry.SurfaceGeometry.FromCylinder(new Aetheris.Kernel.Core.Geometry.Surfaces.CylinderSurface(gs.Cylinder!.Value.Origin + t, gs.Cylinder.Value.Axis, gs.Cylinder.Value.Radius, gs.Cylinder.Value.XAxis)),
+ Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cone => Aetheris.Kernel.Core.Geometry.SurfaceGeometry.FromCone(new Aetheris.Kernel.Core.Geometry.Surfaces.ConeSurface(gs.Cone!.Value.PlacementOrigin + t, gs.Cone.Value.Axis, gs.Cone.Value.PlacementRadius, gs.Cone.Value.SemiAngleRadians, gs.Cone.Value.ReferenceAxis)),
+ Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Torus => Aetheris.Kernel.Core.Geometry.SurfaceGeometry.FromTorus(new Aetheris.Kernel.Core.Geometry.Surfaces.TorusSurface(gs.Torus!.Value.Center + t, gs.Torus.Value.Axis, gs.Torus.Value.MajorRadius, gs.Torus.Value.MinorRadius, gs.Torus.Value.XAxis)),
+ Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Sphere => Aetheris.Kernel.Core.Geometry.SurfaceGeometry.FromSphere(new Aetheris.Kernel.Core.Geometry.Surfaces.SphereSurface(gs.Sphere!.Value.Center + t, gs.Sphere.Value.Axis, gs.Sphere.Value.Radius, gs.Sphere.Value.XAxis)),
+ _ => gs
+ });
+ }
+ return new BrepBody(body.Topology, g, body.Bindings, copy, body.SafeBooleanComposition?.Translate(t));
+ }
+
+ private static bool TryExtractTranslation(Transform3D transform, out Vector3D translation)
+ {
+ var o = transform.Apply(Point3D.Origin); var x = transform.Apply(new Point3D(1, 0, 0)); var y = transform.Apply(new Point3D(0, 1, 0)); var z = transform.Apply(new Point3D(0, 0, 1));
+ const double eps = 1e-9;
+ if (Math.Abs((x - o).X - 1d) > eps || Math.Abs((x - o).Y) > eps || Math.Abs((x - o).Z) > eps
+ || Math.Abs((y - o).Y - 1d) > eps || Math.Abs((z - o).Z - 1d) > eps)
+ { translation = Vector3D.Zero; return false; }
+ translation = o - Point3D.Origin;
+ return true;
+ }
+
+ private static CirNode BuildThroughHole() => new CirSubtractNode(new CirBoxNode(30, 30, 20), new CirCylinderNode(4, 30));
+ private static CirNode BuildBlindHole() => new CirSubtractNode(new CirBoxNode(30, 30, 20), new CirTransformNode(new CirCylinderNode(4, 8), Transform3D.CreateTranslation(new Vector3D(0,0,6))));
+ private static CirNode BuildCounterbore() => new CirSubtractNode(new CirSubtractNode(new CirBoxNode(30,30,20), new CirCylinderNode(3,30)), new CirTransformNode(new CirCylinderNode(5,4), Transform3D.CreateTranslation(new Vector3D(0,0,8))));
+ private static CirNode BuildCountersink() => new CirSubtractNode(new CirSubtractNode(new CirBoxNode(30,30,20), new CirCylinderNode(3,30)), new CirTransformNode(new CirConeNode(5,3,4), Transform3D.CreateTranslation(new Vector3D(0,0,8))));
+ private static CirNode BuildStepped() => new CirSubtractNode(new CirSubtractNode(new CirSubtractNode(new CirBoxNode(30,30,20), new CirCylinderNode(2,30)), new CirTransformNode(new CirCylinderNode(3,8), Transform3D.CreateTranslation(new Vector3D(0,0,6)))), new CirTransformNode(new CirCylinderNode(4,4), Transform3D.CreateTranslation(new Vector3D(0,0,8))));
+
+ public static HoleRecoveryExecutionResult RunSemantic(HoleRecoveryPlan plan) => HoleRecoveryExecutor.Execute(plan);
+}
diff --git a/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLabResult.cs b/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLabResult.cs
new file mode 100644
index 00000000..c3fad79a
--- /dev/null
+++ b/Aetheris.Firmament.FrictionLab/CIRLab/GenericCirBrepExecutorLabResult.cs
@@ -0,0 +1,23 @@
+using Aetheris.Kernel.Core.Brep;
+
+namespace Aetheris.Firmament.FrictionLab.CIRLab;
+
+public enum GenericCirBrepLabStatus { Succeeded, Unsupported, Failed }
+
+public sealed record GenericCirBrepExecutorLabResult(
+ string Scenario,
+ GenericCirBrepLabStatus Status,
+ BrepBody? Body,
+ string FailureCode,
+ IReadOnlyList<string> Diagnostics,
+ IReadOnlyList<string> BooleanSequence,
+ bool StepExportAttempted,
+ bool StepExportSucceeded,
+ IReadOnlyList<string> StepMarkers,
+ bool HasSafeBooleanComposition,
+ string ShellRootKind,
+ int FaceCount);
+
+public sealed record GenericCirBrepScenarioReport(
+ IReadOnlyList<GenericCirBrepExecutorLabResult> Scenarios,
+ IReadOnlyList<string> Diagnostics);
diff --git a/Aetheris.FrictionLab.Tests/CIRLab/GenericCirBrepExecutorLabTests.cs b/Aetheris.FrictionLab.Tests/CIRLab/GenericCirBrepExecutorLabTests.cs
new file mode 100644
index 00000000..33d6e484
--- /dev/null
+++ b/Aetheris.FrictionLab.Tests/CIRLab/GenericCirBrepExecutorLabTests.cs
@@ -0,0 +1,74 @@
+using Aetheris.Firmament.FrictionLab.CIRLab;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Firmament.Materializer;
+
+namespace Aetheris.FrictionLab.Tests.CIRLab;
+
+public class GenericCirBrepExecutorLabTests
+{
+ [Fact]
+ public void GenericExecutor_ThroughHole_SucceedsAndExports()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "A-ThroughHole");
+ Assert.True(r.Status == GenericCirBrepLabStatus.Succeeded, string.Join(" | ", r.Diagnostics));
+ Assert.True(r.StepExportSucceeded, string.Join(" | ", r.StepMarkers));
+ }
+
+ [Fact]
+ public void GenericExecutor_BlindHole_SucceedsAndExports()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "B-BlindHole");
+ Assert.True(r.Status == GenericCirBrepLabStatus.Succeeded, $"Expected blind success, got {r.Status}/{r.FailureCode}");
+ }
+
+ [Fact]
+ public void GenericExecutor_Counterbore_SucceedsAndExportsOrReportsBlocker()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "C-Counterbore");
+ Assert.True(r.Status == GenericCirBrepLabStatus.Succeeded || !string.IsNullOrWhiteSpace(r.FailureCode));
+ }
+
+ [Fact]
+ public void GenericExecutor_Countersink_SucceedsAndExportsOrReportsBlocker()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "D-Countersink");
+ Assert.True(r.Status == GenericCirBrepLabStatus.Succeeded || !string.IsNullOrWhiteSpace(r.FailureCode));
+ }
+
+ [Fact]
+ public void GenericExecutor_SteppedHole_CharacterizesWhetherGenericRouteHelps()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "E-SteppedHole");
+ Assert.True(r.Status == GenericCirBrepLabStatus.Succeeded || r.FailureCode.Contains("boolean"));
+ }
+
+ [Fact]
+ public void GenericExecutor_UnsupportedTransform_Rejects()
+ {
+ var r = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.Single(s => s.Scenario == "F-UnsupportedTransform");
+ Assert.Equal(GenericCirBrepLabStatus.Unsupported, r.Status);
+ Assert.Equal("transform-non-translation-unsupported", r.FailureCode);
+ }
+
+ [Fact]
+ public void GenericExecutor_ReportContainsScenarioMatrix()
+ {
+ var report = GenericCirBrepExecutorLab.RunScenarioMatrix();
+ Assert.Contains(report.Scenarios, s => s.Scenario == "A-ThroughHole");
+ Assert.Contains(report.Scenarios, s => s.Scenario == "E-SteppedHole");
+ Assert.Contains(report.Scenarios, s => s.Scenario == "F-BoxMinusTorus");
+ }
+
+ [Fact]
+ public void GenericExecutor_DeterministicResults()
+ {
+ var a = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.ToDictionary(x => x.Scenario);
+ var b = GenericCirBrepExecutorLab.RunScenarioMatrix().Scenarios.ToDictionary(x => x.Scenario);
+ foreach (var key in a.Keys)
+ {
+ Assert.Equal(a[key].Status, b[key].Status);
+ Assert.Equal(a[key].FailureCode, b[key].FailureCode);
+ Assert.Equal(string.Join(";", a[key].BooleanSequence), string.Join(";", b[key].BooleanSequence));
+ }
+ }
+}
diff --git a/docs/frictionlab/cir-brep-x8-generic-cir-brep-executor-lab.md b/docs/frictionlab/cir-brep-x8-generic-cir-brep-executor-lab.md
new file mode 100644
index 00000000..6df7b2a1
--- /dev/null
+++ b/docs/frictionlab/cir-brep-x8-generic-cir-brep-executor-lab.md
@@ -0,0 +1,51 @@
+# CIR-BREP-X8 generic CIR tree → BRep executor feasibility lab
+
+## Purpose and scope
+FrictionLab-only feasibility probe for recursive `CirNode -> BrepBody` execution; no production wiring changes.
+
+## Code inspected
+`CirNode` / all node types, `BrepPrimitives`, `BrepBoolean` + safe composition/coaxial families, `HoleRecoveryPolicy` variants, `HoleRecoveryExecutor`, STEP exporter.
+
+## Prototype shape
+`GenericCirBrepExecutorLab` recursively maps CIR primitives/booleans/transforms into BRep constructors + `BrepBoolean` calls and emits structured per-scenario diagnostics.
+
+## Support matrix
+- Box/Cylinder/Sphere/Torus: supported via `BrepPrimitives`.
+- Cone: unsupported in this lab scope (no public cone primitive constructor from FrictionLab assembly).
+- Transform: identity + pure translation only.
+- Boolean: subtract/union/intersect via `BrepBoolean`.
+
+## Scenario results
+- Through-hole: succeeded, STEP succeeded.
+- Blind-hole: succeeded, STEP succeeded.
+- Counterbore (coaxial subtract stack): succeeded, STEP succeeded.
+- Countersink: blocked by cone primitive mapping in lab scope.
+- Stepped-hole: failed on subtract stack (`boolean-subtract-failed`), matching deferred semantic characterization intent.
+- Unsupported transform: correctly rejected.
+- Box-sphere/box-torus: executed through generic path (status captured by tests).
+
+## Semantic comparison
+Generic behavior is aligned with current semantic executor outcomes for through/blind/counterbore (success), stepped (still blocked), and countersink remains blocked in this experiment due to lab-scope cone primitive access.
+
+## STEP smoke
+On successful generic outputs: exporter produced expected STEP markers (`ISO-10303-21`, `ADVANCED_FACE`, solid root marker) and analytic surface markers as available.
+
+## SafeBooleanComposition findings
+Per subtract diagnostics include whether safe composition persisted. Multi-step counterbore preserved executable composed state. Stepped still fails at repeated coaxial subtract despite recursive-tree execution, indicating recursive execution alone does not remove the existing blocker.
+
+## Stepped-hole conclusion
+Generic recursive execution does **not** inherently solve stepped-hole in current boolean stack.
+
+## Architecture recommendation
+Hybrid path: keep semantic policy for admissibility/ordering + use generic executor where primitive coverage is complete; retain variant-specific fallback for known hard families (stepped, cone-gated paths) until public primitive/boolean coverage closes.
+
+## HoleRecoveryExecutor disposition
+Keep current executor as production path; treat generic CIR executor as a future internal execution backend once cone + stepped blockers are closed.
+
+## Recommended milestone
+M1: expose/standardize cone primitive construction for non-production labs and add deeper safe-composition observability hooks.
+
+## Confidence
+- Through/blind/counterbore: high.
+- Stepped blocker characterization: high.
+- Countersink generic viability: medium (blocked by scope/API visibility, not proven false).