Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add bounded countersink recovery variant, execution, and STEP smoke

Yuechen Lidd57cdf6390a
diff --git a/Aetheris.Kernel.Firmament.Tests/CountersinkVariantAndExecutorTests.cs b/Aetheris.Kernel.Firmament.Tests/CountersinkVariantAndExecutorTests.cs
index afa96f81..ec0a29bc 100644
--- a/Aetheris.Kernel.Firmament.Tests/CountersinkVariantAndExecutorTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/CountersinkVariantAndExecutorTests.cs
@@ -1,4 +1,7 @@
+using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Cir;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Step242;
using Aetheris.Kernel.Firmament.Materializer;
namespace Aetheris.Kernel.Firmament.Tests;
@@ -6,26 +9,54 @@ namespace Aetheris.Kernel.Firmament.Tests;
public sealed class CountersinkVariantAndExecutorTests
{
[Fact]
- public void CountersinkVariant_IsEvaluated_AndRejectedWithExplicitConePrimitiveBlocker()
+ public void CountersinkVariant_AdmitsSimpleBoxCountersinkPlan()
{
- var root = new CirSubtractNode(new CirBoxNode(20d, 20d, 10d), new CirCylinderNode(2d, 20d));
+ var eval = new HoleRecoveryPolicy().Evaluate(new FrepMaterializerContext(BuildCanonical()));
+ Assert.Contains("selected-variant:CountersinkVariant", eval.Evidence);
+ var plan = Assert.IsType<HoleRecoveryPlan>(eval.Plan);
+ Assert.Equal(HoleKind.Countersink, plan.HoleKind);
+ Assert.Equal(HoleProfileSegmentKind.Conical, plan.ProfileStack[0].SegmentKind);
+ Assert.Equal(HoleProfileSegmentKind.Cylindrical, plan.ProfileStack[1].SegmentKind);
+ }
+
+ [Fact]
+ public void CountersinkVariant_RejectsNonCoaxialConeCylinder()
+ {
+ var cone = new CirTransformNode(new CirConeNode(2d, 4d, 4d), Transform3D.CreateTranslation(new Vector3D(3d, 0d, 3d)));
+ var root = new CirSubtractNode(new CirSubtractNode(new CirBoxNode(20,20,10), new CirCylinderNode(2,20)), cone);
var eval = new HoleRecoveryPolicy().Evaluate(new FrepMaterializerContext(root));
+ Assert.Contains(eval.EvaluationsFor(nameof(CountersinkVariant)), d => d.Contains("not coaxial", StringComparison.OrdinalIgnoreCase));
+ }
- var countersinkDiagnostics = eval.EvaluationsFor(nameof(CountersinkVariant));
- Assert.NotEmpty(countersinkDiagnostics);
- Assert.Contains(countersinkDiagnostics, d => d.Contains("no cone primitive node", StringComparison.OrdinalIgnoreCase));
+ [Fact]
+ public void CountersinkExecutor_CanonicalCountersink_ProducesBrepBody()
+ {
+ var plan = Assert.IsType<HoleRecoveryPlan>(new HoleRecoveryPolicy().Evaluate(new FrepMaterializerContext(BuildCanonical())).Plan);
+ var result = HoleRecoveryExecutor.Execute(plan);
+ Assert.Equal(HoleRecoveryExecutionStatus.Succeeded, result.Status);
+ Assert.NotNull(result.Body);
+ Assert.Contains(result.Diagnostics, d => d.Contains("cylinder subtract invoked", StringComparison.OrdinalIgnoreCase));
+ Assert.Contains(result.Diagnostics, d => d.Contains("cone subtract invoked", StringComparison.OrdinalIgnoreCase));
}
[Fact]
- public void CountersinkVariant_DoesNotOverrideCounterboreSelection()
+ public void CountersinkStepSmoke_CanonicalCountersink_ExportsStep()
{
- var root = new CirSubtractNode(
- new CirSubtractNode(new CirBoxNode(20, 20, 10), new CirCylinderNode(2, 20)),
- new CirTransformNode(new CirCylinderNode(4, 4), Aetheris.Kernel.Core.Math.Transform3D.CreateTranslation(new Aetheris.Kernel.Core.Math.Vector3D(0, 0, -3))));
+ var plan = Assert.IsType<HoleRecoveryPlan>(new HoleRecoveryPolicy().Evaluate(new FrepMaterializerContext(BuildCanonical())).Plan);
+ var exec = HoleRecoveryExecutor.Execute(plan);
+ var step = Step242Exporter.ExportBody(exec.Body!);
+ Assert.True(step.IsSuccess);
+ Assert.Contains("ISO-10303-21", step.Value);
+ Assert.Contains("MANIFOLD_SOLID_BREP", step.Value);
+ Assert.Contains("ADVANCED_FACE", step.Value);
+ Assert.Contains("CONICAL_SURFACE", step.Value);
+ Assert.Contains("CYLINDRICAL_SURFACE", step.Value);
+ Assert.DoesNotContain("BREP_WITH_VOIDS", step.Value);
+ }
- var eval = new HoleRecoveryPolicy().Evaluate(new FrepMaterializerContext(root));
- Assert.True(eval.Admissible);
- Assert.Contains("selected-variant:CounterboreVariant", eval.Evidence);
- Assert.DoesNotContain("selected-variant:CountersinkVariant", eval.Evidence);
+ private static CirNode BuildCanonical()
+ {
+ var cone = new CirTransformNode(new CirConeNode(2d, 4d, 4d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 3d)));
+ return new CirSubtractNode(new CirSubtractNode(new CirBoxNode(20d, 20d, 10d), new CirCylinderNode(2d, 20d)), cone);
}
}
diff --git a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryExecutor.cs b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryExecutor.cs
index eb3bf54a..410e4f5e 100644
--- a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryExecutor.cs
@@ -2,6 +2,7 @@ using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Boolean;
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Firmament.Execution;
+using Aetheris.Kernel.Firmament.Lowering;
namespace Aetheris.Kernel.Firmament.Materializer;
@@ -53,6 +54,12 @@ public static class HoleRecoveryExecutor
return ExecuteBlind(plan, diagnostics);
}
+ if (plan.HoleKind == HoleKind.Countersink && (plan.DepthKind == HoleDepthKind.ThroughWithEntryRelief || plan.DepthKind == HoleDepthKind.BlindWithEntryRelief))
+ {
+ diagnostics.Add("Countersink plan accepted for bounded execution.");
+ return ExecuteCountersink(plan, diagnostics);
+ }
+
if (plan.HoleKind != HoleKind.Counterbore || plan.DepthKind != HoleDepthKind.ThroughWithEntryRelief)
{
diagnostics.Add("Plan rejected: only bounded blind-hole and counterbore are supported.");
@@ -203,6 +210,65 @@ public static class HoleRecoveryExecutor
return new(HoleRecoveryExecutionStatus.Succeeded, sub.Value, diagnostics);
}
+ private static HoleRecoveryExecutionResult ExecuteCountersink(HoleRecoveryPlan plan, List<string> diagnostics)
+ {
+ if (plan.HostKind != HoleHostKind.RectangularBox || plan.Axis != HoleAxisKind.Z || plan.ProfileStack.Count != 2)
+ {
+ diagnostics.Add("Countersink plan rejected: host/axis/profile mismatch.");
+ return new(HoleRecoveryExecutionStatus.UnsupportedPlan, null, diagnostics);
+ }
+
+ var coneSeg = plan.ProfileStack[0];
+ var cylSeg = plan.ProfileStack[1];
+ if (coneSeg.SegmentKind != HoleProfileSegmentKind.Conical || cylSeg.SegmentKind != HoleProfileSegmentKind.Cylindrical)
+ {
+ diagnostics.Add("Countersink plan rejected: expected conical then cylindrical profile segments.");
+ return new(HoleRecoveryExecutionStatus.UnsupportedPlan, null, diagnostics);
+ }
+
+ var boxResult = BrepPrimitives.CreateBox(plan.HostSizeX, plan.HostSizeY, plan.HostSizeZ);
+ var cylResult = BrepPrimitives.CreateCylinder(cylSeg.RadiusStart, double.Max(plan.ThroughLength, plan.HostSizeZ));
+ if (!boxResult.IsSuccess || !cylResult.IsSuccess)
+ {
+ diagnostics.Add("Countersink primitive construction failed for host/cylinder.");
+ return new(HoleRecoveryExecutionStatus.PrimitiveConstructionFailed, null, diagnostics);
+ }
+
+ var boxBody = TranslateBody(boxResult.Value, plan.HostTranslation);
+ var cylBody = TranslateBody(cylResult.Value, plan.ToolTranslation);
+ diagnostics.Add("cylinder subtract invoked.");
+ var firstSub = BrepBoolean.Subtract(boxBody, cylBody);
+ if (!firstSub.IsSuccess || firstSub.Value is null)
+ {
+ diagnostics.Add("cylinder subtract failed.");
+ return new(HoleRecoveryExecutionStatus.BooleanFailed, null, diagnostics);
+ }
+ diagnostics.Add("cylinder subtract succeeded.");
+
+ var coneHeight = coneSeg.DepthEnd - coneSeg.DepthStart;
+ var coneResult = FirmamentPrimitiveExecutor.ExecuteCone(new FirmamentLoweredConeParameters(coneSeg.RadiusEnd, coneSeg.RadiusStart, coneHeight));
+ if (!coneResult.IsSuccess)
+ {
+ diagnostics.Add("cone primitive construction failed.");
+ return new(HoleRecoveryExecutionStatus.PrimitiveConstructionFailed, null, diagnostics);
+ }
+
+ var entryTopZ = plan.HostTranslation.Z + (plan.HostSizeZ * 0.5d);
+ var coneCenterZ = entryTopZ - (coneHeight * 0.5d);
+ var coneBody = TranslateBody(coneResult.Value, new Vector3D(plan.ToolTranslation.X, plan.ToolTranslation.Y, coneCenterZ));
+ diagnostics.Add("cone subtract invoked.");
+ var secondSub = BrepBoolean.Subtract(firstSub.Value, coneBody);
+ if (!secondSub.IsSuccess || secondSub.Value is null)
+ {
+ diagnostics.Add("cone subtract failed.");
+ return new(HoleRecoveryExecutionStatus.BooleanFailed, null, diagnostics);
+ }
+
+ diagnostics.Add("cone subtract succeeded.");
+ diagnostics.Add("Result BRep body produced.");
+ return new(HoleRecoveryExecutionStatus.Succeeded, secondSub.Value, diagnostics);
+ }
+
private static BrepBody TranslateBody(BrepBody body, Vector3D translation)
=> translation == Vector3D.Zero ? body : FirmamentPrimitiveExecutionTranslation.TranslateBody(body, translation);
}
diff --git a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPlan.cs b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPlan.cs
index 6765453d..d7b2d3bb 100644
--- a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPlan.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPlan.cs
@@ -5,11 +5,11 @@ namespace Aetheris.Kernel.Firmament.Materializer;
public enum HoleHostKind { RectangularBox, Unsupported }
public enum HoleAxisKind { Z, Unsupported }
public enum HoleKind { Through, Blind, Counterbore, Countersink, Unsupported }
-public enum HoleDepthKind { Through, Blind, ThroughWithEntryRelief, Unsupported }
+public enum HoleDepthKind { Through, Blind, ThroughWithEntryRelief, BlindWithEntryRelief, Unsupported }
public enum HoleProfileSegmentKind { Cylindrical, Conical, Chamfer, ThreadDeferred, Unsupported }
public enum HoleEntryFeatureKind { Plain, Counterbore, Countersink, Unsupported }
public enum HoleExitFeatureKind { Plain, ClosedBottom, Unsupported }
-public enum HoleSurfacePatchRole { EntryFace, ExitFace, HostRetainedPlanarFaces, CylindricalWall, BlindBottomCap, CounterboreFloorAnnulus, CounterboreWall }
+public enum HoleSurfacePatchRole { EntryFace, ExitFace, HostRetainedPlanarFaces, CylindricalWall, BlindBottomCap, CounterboreFloorAnnulus, CounterboreWall, CountersinkWall }
public enum HoleTrimCurveRole { CircularRimTrim, Deferred }
public sealed record HoleProfileSegment(HoleProfileSegmentKind SegmentKind, double RadiusStart, double RadiusEnd, double DepthStart, double DepthEnd);
diff --git a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPolicy.cs b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPolicy.cs
index b9359c93..71b77b6d 100644
--- a/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPolicy.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/HoleRecoveryPolicy.cs
@@ -51,24 +51,115 @@ public sealed class HoleRecoveryPolicy : IFrepMaterializerPolicy
internal sealed class CountersinkVariant : IHoleRecoveryVariant
{
+ private const double Score = 1050d;
public string Name => nameof(CountersinkVariant);
public HoleRecoveryVariantEvaluation Evaluate(FrepMaterializerContext context)
{
var diagnostics = new List<string>
{
- "CountersinkVariant evaluated.",
- "Blocked: CIR currently has no cone primitive node (only Box/Cylinder/Sphere/Torus plus booleans/transforms).",
- "Unsupported bounded countersink recognition until cone primitive exists in CIR tree."
+ "CountersinkVariant evaluated."
};
+ if (context.Root is not CirSubtractNode outer || outer.Left is not CirSubtractNode inner)
+ {
+ diagnostics.Add("not countersink shape: requires Subtract(Subtract(Box,Cylinder),Cone). ");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedCountersinkShape"], diagnostics);
+ }
+
+ var hostRec = CirBoxCylinderRecognizer.Recognize(new CirBoxCylinderRecognizerInput(new CirSubtractNode(inner.Left, inner.Right), context.ReplayLog, context.SourceLabel));
+ if (!hostRec.Success || hostRec.Value is null)
+ {
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], [hostRec.Diagnostic, $"host-recognizer-reason:{hostRec.Reason}"], hostRec.Diagnostics);
+ }
+
+ if (!CounterboreVariant.TryUnwrapTranslation(outer.Right, out var coneNode, out var coneTranslation) || coneNode is not CirConeNode cone)
+ {
+ diagnostics.Add("missing cone primitive / unexpected tool kind.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedMissingConePrimitiveOrTransform"], diagnostics);
+ }
+ diagnostics.Add("cone primitive detected.");
+
+ var host = hostRec.Value;
+ var tol = Aetheris.Kernel.Core.Numerics.ToleranceContext.Default.Linear;
+ if (Math.Abs(coneTranslation.X - host.CylinderTranslation.X) > tol || Math.Abs(coneTranslation.Y - host.CylinderTranslation.Y) > tol)
+ {
+ diagnostics.Add("cone/cylinder not coaxial in XY.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedNonCoaxialConeCylinder"], diagnostics);
+ }
+ diagnostics.Add("cone/cylinder coaxial in XY.");
+
+ var boxMinZ = host.BoxTranslation.Z - (host.BoxDepth * 0.5d);
+ var boxMaxZ = host.BoxTranslation.Z + (host.BoxDepth * 0.5d);
+ var coneMinZ = coneTranslation.Z - (cone.Height * 0.5d);
+ var coneMaxZ = coneTranslation.Z + (cone.Height * 0.5d);
+ var touchesTop = Math.Abs(coneMaxZ - boxMaxZ) <= tol;
+ var touchesBottom = Math.Abs(coneMinZ - boxMinZ) <= tol;
+ if (!touchesTop && !touchesBottom)
+ {
+ diagnostics.Add("cone does not touch entry face.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedConeMissingEntryFace"], diagnostics);
+ }
+
+ if (touchesTop && touchesBottom)
+ {
+ diagnostics.Add("cone through full depth unsupported.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedConeThroughFullDepth"], diagnostics);
+ }
+
+ var entryFromTop = touchesTop;
+ var entryRadius = entryFromTop ? cone.TopRadius : cone.BottomRadius;
+ var transitionRadius = entryFromTop ? cone.BottomRadius : cone.TopRadius;
+ if (entryRadius <= transitionRadius + tol)
+ {
+ diagnostics.Add("cone radius ordering invalid for entry side.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedConeRadiusOrderingInvalid"], diagnostics);
+ }
+
+ if (Math.Abs(transitionRadius - host.CylinderRadius) > tol)
+ {
+ diagnostics.Add("cone transition radius incompatible with cylinder radius.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedTransitionRadiusMismatch"], diagnostics);
+ }
+
+ var coneDepth = cone.Height;
+ if (coneDepth >= host.BoxDepth - tol)
+ {
+ diagnostics.Add("cone through full depth.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedConeThroughFullDepth"], diagnostics);
+ }
+
+ var halfW = host.BoxWidth * 0.5d;
+ var halfH = host.BoxHeight * 0.5d;
+ var dx = coneTranslation.X - host.BoxTranslation.X;
+ var dy = coneTranslation.Y - host.BoxTranslation.Y;
+ if ((dx + halfW - entryRadius) <= tol || (halfW - dx - entryRadius) <= tol || (dy + halfH - entryRadius) <= tol || (halfH - dy - entryRadius) <= tol)
+ {
+ diagnostics.Add("cone max radius tangent/grazing/oversized.");
+ return new(Name, false, 0d, null, ["countersink", "rectangular-box-host"], ["UnsupportedConeClearance"], diagnostics);
+ }
+
+ var depthKind = hostRec.Value.ThroughLength >= host.BoxDepth - tol ? HoleDepthKind.ThroughWithEntryRelief : HoleDepthKind.BlindWithEntryRelief;
+ var exitKind = depthKind == HoleDepthKind.ThroughWithEntryRelief ? HoleExitFeatureKind.Plain : HoleExitFeatureKind.ClosedBottom;
+ diagnostics.Add($"entry side detected: {(entryFromTop ? "top(+Z)" : "bottom(-Z)")}.");
+ diagnostics.Add("cone radius/order validated.");
+ diagnostics.Add("transition radius compatible.");
+ diagnostics.Add($"countersink depth computed: {coneDepth:R}.");
+ diagnostics.Add("Countersink plan produced.");
+
+ var plan = new HoleRecoveryPlan(HoleHostKind.RectangularBox, HoleAxisKind.Z, HoleKind.Countersink, depthKind, HoleEntryFeatureKind.Countersink, exitKind,
+ host.ThroughLength, host.BoxWidth, host.BoxHeight, host.BoxDepth, host.BoxTranslation, host.CylinderTranslation,
+ [new(HoleProfileSegmentKind.Conical, entryRadius, transitionRadius, 0d, coneDepth), new(HoleProfileSegmentKind.Cylindrical, host.CylinderRadius, host.CylinderRadius, 0d, host.ThroughLength)],
+ [new(HoleSurfacePatchRole.HostRetainedPlanarFaces, "Host planar faces are retained after countersink subtraction."), new(HoleSurfacePatchRole.CountersinkWall, "Conical countersink wall patch is expected."), new(HoleSurfacePatchRole.CylindricalWall, "Cylindrical continuation wall patch is expected.")],
+ [new(HoleTrimCurveRole.CircularRimTrim, "Circular entry/transition trims are expected.")], FrepMaterializerCapability.ExactBRep, diagnostics.ToArray());
+
return new(
Name,
- false,
- 0d,
- null,
- ["countersink", "rectangular-box-host"],
- ["UnsupportedMissingConePrimitiveInCir"],
+ true,
+ Score,
+ plan,
+ ["countersink", "rectangular-box-host", "cone-primitive", "coaxial-cone-cylinder", "entry-relief", "semantic-profile-stack"],
+ Array.Empty<string>(),
diagnostics);
}
}
diff --git a/docs/cir-recovery-v10-countersink-variant-executor-step.md b/docs/cir-recovery-v10-countersink-variant-executor-step.md
index 0a85be53..72eeacaf 100644
--- a/docs/cir-recovery-v10-countersink-variant-executor-step.md
+++ b/docs/cir-recovery-v10-countersink-variant-executor-step.md
@@ -37,3 +37,8 @@ We added `CountersinkVariant` to the `HoleRecoveryPolicy` JudgmentEngine lane an
2. Add `CountersinkVariant` bounded recognition for `Subtract(Subtract(Box,Cylinder),Cone)` with strict coaxial/entry/depth/radius checks.
3. Extend `HoleRecoveryExecutor` with cone subtract path using existing `BrepPrimitives.CreateCone` + `BrepBoolean.Subtract`.
4. Add countersink STEP smoke asserting `CONICAL_SURFACE`, `CYLINDRICAL_SURFACE`, and no `BREP_WITH_VOIDS`.
+
+
+## Status update
+
+Superseded in part by `docs/cir-recovery-v11-countersink-cone-execution-step.md`, which resolves the prior cone-primitive blocker for a bounded countersink shape.
diff --git a/docs/cir-recovery-v11-countersink-cone-execution-step.md b/docs/cir-recovery-v11-countersink-cone-execution-step.md
new file mode 100644
index 00000000..bd3a00e5
--- /dev/null
+++ b/docs/cir-recovery-v11-countersink-cone-execution-step.md
@@ -0,0 +1,15 @@
+# CIR-RECOVERY-V11: CountersinkVariant via CirConeNode + executor + STEP smoke
+
+Bounded supported shape: `Subtract(Subtract(Box,Cylinder),Cone)` with translation-only wrappers.
+
+- `CountersinkVariant` now detects canonical countersink with `CirConeNode`.
+- Coaxial XY, entry-face touch, cone ordering, transition radius compatibility, strict clearance, and non-through cone depth are enforced.
+- Produces `HoleRecoveryPlan` with conical + cylindrical profile stack and `HoleKind.Countersink`.
+- `HoleRecoveryExecutor` now executes countersink by subtracting through cylinder then cone.
+- Cone construction convention used: `FirmamentPrimitiveExecutor.ExecuteCone(bottomRadius, topRadius, height)` emits a Z-axis revolve then translates by `-height/2`, so resulting cone spans `[-h/2,+h/2]` with bottom radius at lower Z and top radius at upper Z.
+- STEP smoke remains through `Step242Exporter.ExportBody(...)` unchanged; expected `MANIFOLD_SOLID_BREP`, `CONICAL_SURFACE`, `CYLINDRICAL_SURFACE`, and no `BREP_WITH_VOIDS` for open countersink.
+
+Non-goals preserved:
+- no threaded/generic profile stack recovery,
+- no exporter behavior changes,
+- no topology naming expansion (SEM-A0 preserved).