Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement truthful box-cone boolean failure coverage

Yuechen Li860b6cb609bb
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 4e00d78e..b03107fe 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -1,5 +1,6 @@
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Brep.Features;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Geometry;
using Aetheris.Kernel.Core.Geometry.Curves;
@@ -373,6 +374,62 @@ public sealed class BrepBooleanTests
Assert.Equal("Boolean Intersect: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
}
+ [Fact]
+ public void Subtract_BoxPointedCone_StillReturnsDeterministicNotImplemented()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var right = CreateCone(bottomRadius: 6d, topRadius: 0d, height: 20d);
+
+ var result = BrepBoolean.Subtract(left, right);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Boolean Subtract: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
+ }
+
+ [Fact]
+ public void Subtract_BoxFrustumCone_StillReturnsDeterministicNotImplemented()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var right = CreateCone(bottomRadius: 6d, topRadius: 2d, height: 20d);
+
+ var result = BrepBoolean.Subtract(left, right);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Boolean Subtract: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
+ }
+
+ [Fact]
+ public void Union_BoxConeOverlap_StillReturnsDeterministicNotImplemented()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var right = CreateCone(bottomRadius: 6d, topRadius: 0d, height: 20d);
+
+ var result = BrepBoolean.Union(left, right);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
+ }
+
+ [Fact]
+ public void Intersect_BoxConeOverlap_StillReturnsDeterministicNotImplemented()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var right = CreateCone(bottomRadius: 6d, topRadius: 0d, height: 20d);
+
+ var result = BrepBoolean.Intersect(left, right);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Boolean Intersect: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
+ }
+
[Fact]
public void Execute_NonBoxInput_ReturnsDeterministicNotImplementedWithoutThrowing()
{
@@ -389,6 +446,26 @@ public sealed class BrepBooleanTests
Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);
}
+ private static BrepBody CreateCone(double bottomRadius, double topRadius, double height)
+ {
+ var frame = new ExtrudeFrame3D(
+ origin: Point3D.Origin,
+ normal: Direction3D.Create(new Vector3D(0d, 0d, 1d)),
+ uAxis: Direction3D.Create(new Vector3D(1d, 0d, 0d)));
+ var axis = new RevolveAxis3D(Point3D.Origin, new Vector3D(0d, 0d, 1d));
+
+ var result = BrepRevolve.Create(
+ [
+ new ProfilePoint2D(bottomRadius, 0d),
+ new ProfilePoint2D(topRadius, height)
+ ],
+ frame,
+ axis);
+
+ Assert.True(result.IsSuccess);
+ return result.Value;
+ }
+
private static BrepBody TransformBody(BrepBody body, Transform3D transform)
{
var geometry = new BrepGeometryStore();
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
index 354f3290..766af05a 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
@@ -86,7 +86,10 @@ public sealed class FirmamentBooleanCanonicalSuccessTests
{ "testdata/firmament/fixtures/m10j-unsupported-box-intersect-cylinder.firmament", "overlap", "intersect" },
{ "testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament", "cavity", "subtract" },
{ "testdata/firmament/fixtures/m10l-unsupported-box-add-sphere.firmament", "joined", "add" },
- { "testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "overlap", "intersect" }
+ { "testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "overlap", "intersect" },
+ { "testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament", "tapered_cut", "subtract" },
+ { "testdata/firmament/fixtures/m10m-unsupported-box-add-cone.firmament", "joined", "add" },
+ { "testdata/firmament/fixtures/m10m-unsupported-box-intersect-cone.firmament", "overlap", "intersect" }
};
[Theory]
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index 6b283f05..fdd99916 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -258,7 +258,7 @@ public sealed class FirmamentPrimitiveExecutionTests
Assert.False(result.Compilation.IsSuccess);
var diagnostic = Assert.Single(result.Compilation.Diagnostics);
Assert.Equal(Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticCode.NotImplemented, diagnostic.Code);
- Assert.Contains("supports nested tool ops 'box', 'cylinder', and 'sphere' only", diagnostic.Message, StringComparison.Ordinal);
+ Assert.Contains("supports nested tool ops 'box', 'cylinder', 'sphere', and 'cone' only", diagnostic.Message, StringComparison.Ordinal);
}
[Fact]
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
index 759c9475..575e7c84 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
@@ -104,6 +104,9 @@ public sealed class FirmamentStepExporterTests
[InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-partially-outside.firmament", "leaking_cavity")]
[InlineData("testdata/firmament/fixtures/m10l-unsupported-box-add-sphere.firmament", "joined")]
[InlineData("testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "overlap")]
+ [InlineData("testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament", "tapered_cut")]
+ [InlineData("testdata/firmament/fixtures/m10m-unsupported-box-add-cone.firmament", "joined")]
+ [InlineData("testdata/firmament/fixtures/m10m-unsupported-box-intersect-cone.firmament", "overlap")]
public void Export_BoxSphereFixtures_Fail_Loudly_Without_Fallback(string fixturePath, string expectedFeatureId)
{
var first = ExportFixture(fixturePath);
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index 260618ea..7d6ec342 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -176,7 +176,22 @@ internal static class FirmamentPrimitiveExecutor
return BrepPrimitives.CreateSphere(FirmamentPrimitiveToolParsing.ParseScalar(radiusRaw));
}
- return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Boolean execution supports nested tool ops 'box', 'cylinder', and 'sphere' only. Got '{tool.OpName}'.")]);
+ if (string.Equals(tool.OpName, "cone", StringComparison.Ordinal))
+ {
+ if (!tool.RawFields.TryGetValue("bottom_radius", out var bottomRadiusRaw) || string.IsNullOrWhiteSpace(bottomRadiusRaw)
+ || !tool.RawFields.TryGetValue("top_radius", out var topRadiusRaw) || string.IsNullOrWhiteSpace(topRadiusRaw)
+ || !tool.RawFields.TryGetValue("height", out var coneHeightRaw) || string.IsNullOrWhiteSpace(coneHeightRaw))
+ {
+ return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, "Boolean execution expected validated nested fields 'with.bottom_radius', 'with.top_radius', and 'with.height' for tool op 'cone'.")]);
+ }
+
+ return ExecuteCone(new FirmamentLoweredConeParameters(
+ FirmamentPrimitiveToolParsing.ParseScalar(bottomRadiusRaw),
+ FirmamentPrimitiveToolParsing.ParseScalar(topRadiusRaw),
+ FirmamentPrimitiveToolParsing.ParseScalar(coneHeightRaw)));
+ }
+
+ return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Boolean execution supports nested tool ops 'box', 'cylinder', 'sphere', and 'cone' only. Got '{tool.OpName}'.")]);
}
private static KernelResult<BrepBody> ExecuteBoolean(FirmamentLoweredBooleanKind kind, BrepBody left, BrepBody right) =>
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
index 6d966bc1..9b21fffa 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
@@ -92,6 +92,11 @@ internal static class FirmamentBooleanRequiredFieldValidator
return ValidateSphereTool(entry, opIndex, withFields);
}
+ if (string.Equals(withOpRaw, "cone", StringComparison.Ordinal))
+ {
+ return ValidateConeTool(entry, opIndex, withFields);
+ }
+
return KernelResult<bool>.Success(true);
}
@@ -137,6 +142,41 @@ internal static class FirmamentBooleanRequiredFieldValidator
private static KernelResult<bool> ValidateSphereTool(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields)
=> ValidatePositiveNumericWithField(entry, opIndex, withFields, "radius");
+ private static KernelResult<bool> ValidateConeTool(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields)
+ {
+ var bottomRadiusResult = ValidateNonNegativeNumericWithField(entry, opIndex, withFields, "bottom_radius");
+ if (!bottomRadiusResult.IsSuccess)
+ {
+ return bottomRadiusResult;
+ }
+
+ var topRadiusResult = ValidateNonNegativeNumericWithField(entry, opIndex, withFields, "top_radius");
+ if (!topRadiusResult.IsSuccess)
+ {
+ return topRadiusResult;
+ }
+
+ var heightResult = ValidatePositiveNumericWithField(entry, opIndex, withFields, "height");
+ if (!heightResult.IsSuccess)
+ {
+ return heightResult;
+ }
+
+ _ = TryParseNumeric(withFields["bottom_radius"], out var bottomRadius);
+ _ = TryParseNumeric(withFields["top_radius"], out var topRadius);
+ if (bottomRadius <= 1e-12d && topRadius <= 1e-12d)
+ {
+ return InvalidFieldValue("with.top_radius", opIndex, entry.OpName, "expected at least one of 'with.bottom_radius' or 'with.top_radius' to be greater than 0");
+ }
+
+ if (bottomRadius > 1e-12d && topRadius > 1e-12d && double.Abs(bottomRadius - topRadius) <= 1e-12d)
+ {
+ return InvalidFieldValue("with.top_radius", opIndex, entry.OpName, "expected a numeric value different from 'with.bottom_radius' when both cone radii are greater than 0");
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
private static KernelResult<bool> ValidatePositiveNumericWithField(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields, string fieldName)
{
var qualifiedFieldName = $"with.{fieldName}";
@@ -158,6 +198,27 @@ internal static class FirmamentBooleanRequiredFieldValidator
return KernelResult<bool>.Success(true);
}
+ private static KernelResult<bool> ValidateNonNegativeNumericWithField(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields, string fieldName)
+ {
+ var qualifiedFieldName = $"with.{fieldName}";
+ if (!withFields.TryGetValue(fieldName, out var raw) || string.IsNullOrWhiteSpace(raw))
+ {
+ return MissingField(qualifiedFieldName, opIndex, entry.OpName);
+ }
+
+ if (!TryParseNumeric(raw, out var value))
+ {
+ return InvalidFieldTypeOrShape(qualifiedFieldName, opIndex, entry.OpName, "expected a numeric scalar value");
+ }
+
+ if (value < 0)
+ {
+ return InvalidFieldValue(qualifiedFieldName, opIndex, entry.OpName, "expected a numeric value greater than or equal to 0");
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
private static bool TryGetRequiredNonEmptyScalar(FirmamentParsedOpEntry entry, string fieldName, int opIndex, out KernelDiagnostic? diagnostic)
{
diagnostic = null;
diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.md
index 9e367f3c..daf56e22 100644
--- a/testdata/firmament/examples/README.md
+++ b/testdata/firmament/examples/README.md
@@ -19,4 +19,4 @@ Other combinations may fail and are intentionally not supported yet.
- `placed_primitive.firmament` — selector-based placement using `place.on` and `offset[3]`; helper export path: `testdata/firmament/exports/placed_primitive.step`.
- `schema_box_basic.firmament` — minimal schema-present export example showing schema presence without changing export body semantics; helper export path: `testdata/firmament/exports/schema_box_basic.step`.
-Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The only supported box+cylinder case is `subtract(box, cylinder)` where the cylinder stays axis-aligned with +Z/-Z, fully spans the box from bottom face to top face, and remains strictly inside the box footprint so the result is one connected box-with-through-hole solid. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, and outside-footprint cuts remain unsupported. Box+sphere booleans are currently unsupported in all audited forms, including `subtract(box, sphere)` with a fully contained sphere, boundary-touching sphere, or partially outside sphere, plus all current box+sphere `add` and `intersect` requests. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.
+Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The only supported box+cylinder case is `subtract(box, cylinder)` where the cylinder stays axis-aligned with +Z/-Z, fully spans the box from bottom face to top face, and remains strictly inside the box footprint so the result is one connected box-with-through-hole solid. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, and outside-footprint cuts remain unsupported. Box+sphere booleans are currently unsupported in all audited forms, including `subtract(box, sphere)` with a fully contained sphere, boundary-touching sphere, or partially outside sphere, plus all current box+sphere `add` and `intersect` requests. Box+cone booleans are also currently unsupported in all audited forms, including `subtract(box, cone)` with both pointed-cone and frustum-cone tools, plus all current box+cone `add` and `intersect` requests. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.
diff --git a/testdata/firmament/fixtures/m10m-unsupported-box-add-cone.firmament b/testdata/firmament/fixtures/m10m-unsupported-box-add-cone.firmament
new file mode 100644
index 00000000..417940b3
--- /dev/null
+++ b/testdata/firmament/fixtures/m10m-unsupported-box-add-cone.firmament
@@ -0,0 +1,25 @@
+firmament:
+ version: 1
+
+model:
+ name: m10m_unsupported_box_add_cone
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 30
+ 12
+
+ -
+ op: add
+ id: joined
+ to: base
+ with:
+ op: cone
+ bottom_radius: 6
+ top_radius: 0
+ height: 20
diff --git a/testdata/firmament/fixtures/m10m-unsupported-box-intersect-cone.firmament b/testdata/firmament/fixtures/m10m-unsupported-box-intersect-cone.firmament
new file mode 100644
index 00000000..7894faa3
--- /dev/null
+++ b/testdata/firmament/fixtures/m10m-unsupported-box-intersect-cone.firmament
@@ -0,0 +1,25 @@
+firmament:
+ version: 1
+
+model:
+ name: m10m_unsupported_box_intersect_cone
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 30
+ 12
+
+ -
+ op: intersect
+ id: overlap
+ left: base
+ with:
+ op: cone
+ bottom_radius: 6
+ top_radius: 0
+ height: 20
diff --git a/testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament b/testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament
new file mode 100644
index 00000000..7d1a1c71
--- /dev/null
+++ b/testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament
@@ -0,0 +1,25 @@
+firmament:
+ version: 1
+
+model:
+ name: m10m_unsupported_box_subtract_cone
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 30
+ 12
+
+ -
+ op: subtract
+ id: tapered_cut
+ from: base
+ with:
+ op: cone
+ bottom_radius: 6
+ top_radius: 0
+ height: 20