Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Clarify and harden triangular_prism geometry contract

Yuechen Li43828030d13a
diff --git a/Aetheris.CLI.Tests/CliBaselineTests.cs b/Aetheris.CLI.Tests/CliBaselineTests.cs
index 53aec3f7..eb588961 100644
--- a/Aetheris.CLI.Tests/CliBaselineTests.cs
+++ b/Aetheris.CLI.Tests/CliBaselineTests.cs
@@ -177,6 +177,44 @@ public sealed class CliBaselineTests
Assert.Equal(2d, torusFace.GetProperty("minorRadius").GetDouble(), 8);
}
+ [Fact]
+ public void Build_And_Analyze_TriangularPrism_Example_Reports_IsoscelesContractBounds()
+ {
+ var outputPath = Path.Combine(RepoRoot, "testdata", "firmament", "exports", "cli-triangular-prism-contract.step");
+ if (File.Exists(outputPath))
+ {
+ File.Delete(outputPath);
+ }
+
+ var buildStdout = new StringWriter();
+ var buildStderr = new StringWriter();
+ var buildExitCode = Aetheris.CLI.CliRunner.Run(
+ ["build", Path.Combine(RepoRoot, "testdata/firmament/examples/triangular_prism_basic.firmament"), "--out", outputPath],
+ buildStdout,
+ buildStderr);
+ Assert.Equal(0, buildExitCode);
+ Assert.True(File.Exists(outputPath), buildStderr.ToString());
+
+ var analyzeStdout = new StringWriter();
+ var analyzeStderr = new StringWriter();
+ var analyzeExitCode = Aetheris.CLI.CliRunner.Run(
+ ["analyze", outputPath, "--json"],
+ analyzeStdout,
+ analyzeStderr);
+ Assert.Equal(0, analyzeExitCode);
+
+ using var doc = JsonDocument.Parse(analyzeStdout.ToString());
+ var summary = doc.RootElement.GetProperty("summary");
+ Assert.Equal(5, summary.GetProperty("faceCount").GetInt32());
+ Assert.Equal(9, summary.GetProperty("edgeCount").GetInt32());
+ Assert.Equal(6, summary.GetProperty("vertexCount").GetInt32());
+ var bbox = summary.GetProperty("boundingBox");
+ AssertPoint(bbox.GetProperty("min"), -10d, -6d, 0d);
+ AssertPoint(bbox.GetProperty("max"), 10d, 6d, 10d);
+
+ File.Delete(outputPath);
+ }
+
[Fact]
public void Analyze_Command_Uses_Binding_Missing_Surface_Status_Instead_Of_Unknown_Surface_Type()
{
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Primitives/BrepPrimitivesTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Primitives/BrepPrimitivesTests.cs
index e8a54805..7f143d6a 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Primitives/BrepPrimitivesTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Primitives/BrepPrimitivesTests.cs
@@ -1,6 +1,7 @@
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Geometry;
+using Aetheris.Kernel.Core.Step242;
namespace Aetheris.Kernel.Core.Tests.Brep.Primitives;
@@ -214,6 +215,56 @@ public sealed class BrepPrimitivesTests
});
}
+ [Fact]
+ public void CreateTriangularPrism_UsesCenteredIsoscelesProfileContract()
+ {
+ var result = BrepPrimitives.CreateTriangularPrism(8d, 6d, 10d);
+
+ Assert.True(result.IsSuccess);
+ var step = Step242Exporter.ExportBody(result.Value);
+ Assert.True(step.IsSuccess);
+ var imported = Step242Importer.ImportBody(step.Value);
+ Assert.True(imported.IsSuccess);
+ var body = imported.Value;
+
+ var vertices = body.Topology.Vertices
+ .Select(vertex =>
+ {
+ Assert.True(body.TryGetVertexPoint(vertex.Id, out var point));
+ return point;
+ })
+ .OrderBy(point => point.Z)
+ .ThenBy(point => point.Y)
+ .ThenBy(point => point.X)
+ .ToArray();
+
+ Assert.Equal(6, vertices.Length);
+ Assert.Equal(-4d, vertices.Min(p => p.X), 8);
+ Assert.Equal(4d, vertices.Max(p => p.X), 8);
+ Assert.Equal(-3d, vertices.Min(p => p.Y), 8);
+ Assert.Equal(3d, vertices.Max(p => p.Y), 8);
+ Assert.Equal(-5d, vertices.Min(p => p.Z), 8);
+ Assert.Equal(5d, vertices.Max(p => p.Z), 8);
+
+ var expected = new (double X, double Y, double Z)[]
+ {
+ (-4d, -3d, -5d),
+ (4d, -3d, -5d),
+ (0d, 3d, -5d),
+ (-4d, -3d, 5d),
+ (4d, -3d, 5d),
+ (0d, 3d, 5d),
+ };
+
+ Assert.Equal(expected.Length, vertices.Length);
+ for (var index = 0; index < expected.Length; index++)
+ {
+ Assert.Equal(expected[index].X, vertices[index].X, 8);
+ Assert.Equal(expected[index].Y, vertices[index].Y, 8);
+ Assert.Equal(expected[index].Z, vertices[index].Z, 8);
+ }
+ }
+
[Fact]
public void CreateHexagonalPrism_ProducesPlanarPolyhedralBody()
{
diff --git a/Aetheris.Kernel.Core/Brep/BrepPrimitives.cs b/Aetheris.Kernel.Core/Brep/BrepPrimitives.cs
index 31e3993c..7ad11b19 100644
--- a/Aetheris.Kernel.Core/Brep/BrepPrimitives.cs
+++ b/Aetheris.Kernel.Core/Brep/BrepPrimitives.cs
@@ -17,10 +17,11 @@ namespace Aetheris.Kernel.Core.Brep;
public static class BrepPrimitives
{
/// <summary>
- /// Bounded M3 triangular prism primitive.
- /// Profile frame is XY, extrusion is world +Z, and the triangle base is centered about origin:
+ /// Bounded M3 triangular prism primitive with a centered isosceles profile.
+ /// Profile frame is XY, extrusion is world +Z, and the local profile vertices are:
/// (-baseWidth/2,-baseDepth/2), (+baseWidth/2,-baseDepth/2), (0,+baseDepth/2).
/// Legacy body is centered on Z in [-height/2,+height/2].
+ /// This primitive is intentionally not a right-triangle contract.
/// </summary>
public static KernelResult<BrepBody> CreateTriangularPrism(double baseWidth, double baseDepth, double height)
{
diff --git a/docs/triangular-prism-contract.md b/docs/triangular-prism-contract.md
new file mode 100644
index 00000000..61d128d5
--- /dev/null
+++ b/docs/triangular-prism-contract.md
@@ -0,0 +1,45 @@
+# `triangular_prism` contract (P2 hardening)
+
+This document makes the current `triangular_prism` primitive explicit so future work does not need to infer its geometry.
+
+## Primitive shape
+
+`triangular_prism` is a **centered isosceles triangular prism**, not a right-triangular prism.
+
+Given:
+- `base_width = w`
+- `base_depth = d`
+- `height = h`
+
+the local 2D profile in XY is exactly:
+1. `(-w/2, -d/2)`
+2. `( w/2, -d/2)`
+3. `( 0, d/2)`
+
+Extrusion is along local `+Z` for distance `h`.
+
+## Local frame / origin semantics
+
+Kernel primitive construction produces a legacy body centered on `Z` in `[-h/2, +h/2]`.
+
+Firmament primitive publishing applies the standard prism default-frame translation of `+h/2` in `Z`, so published primitive coordinates become `Z ∈ [0, h]` before any user `placement` offset/selector transform.
+
+## Bounding box contract
+
+For the published primitive (before extra placement offsets), expected axis-aligned bounds are:
+
+- `X ∈ [-w/2, +w/2]`
+- `Y ∈ [-d/2, +d/2]`
+- `Z ∈ [0, h]`
+
+Example (`w=20, d=12, h=10`) yields bbox min `(-10, -6, 0)` max `(10, 6, 10)`.
+
+## Canonical example
+
+- `testdata/firmament/examples/triangular_prism_basic.firmament`
+
+This example is used by tests that assert both topology counts and analyze JSON bounding-box facts.
+
+## Scope boundary
+
+This clarification pass does **not** introduce arbitrary triangle profiles, prism DSL changes, or generalized prism-family redesign.