Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
FORGE-M0a: add bounded Forge foundation and rounded corner box golden path
Yuechen Li94bed4b02d0a
diff --git a/Aetheris.Forge/Aetheris.Forge.csproj b/Aetheris.Forge/Aetheris.Forge.csprojnew file mode 100644index 00000000..f563f5a2--- /dev/null+++ b/Aetheris.Forge/Aetheris.Forge.csproj@@ -0,0 +1,11 @@+<Project Sdk="Microsoft.NET.Sdk">+ <PropertyGroup>+ <TargetFramework>net8.0</TargetFramework>+ <ImplicitUsings>enable</ImplicitUsings>+ <Nullable>enable</Nullable>+ </PropertyGroup>++ <ItemGroup>+ <ProjectReference Include="..\Aetheris.Kernel.Core\Aetheris.Kernel.Core.csproj" />+ </ItemGroup>+</Project>diff --git a/Aetheris.Forge/ForgeAtomics.cs b/Aetheris.Forge/ForgeAtomics.csnew file mode 100644index 00000000..039da1b1--- /dev/null+++ b/Aetheris.Forge/ForgeAtomics.cs@@ -0,0 +1,42 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Features;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Results;++namespace Aetheris.Forge;++public static class ForgeAtomics+{+ public static KernelResult<ForgeRoundedRectangleProfile> RoundedRectangle(double width, double depth, double cornerRadius, int cornerSegments = 8) =>+ ForgeRoundedRectangleProfile.Create(width, depth, cornerRadius, cornerSegments);++ public static KernelResult<BrepBody> ExtrudeCentered(ForgeRoundedRectangleProfile profile, double height)+ {+ ArgumentNullException.ThrowIfNull(profile);+ if (!double.IsFinite(height) || height <= 0d)+ {+ return KernelResult<BrepBody>.Failure(+ [+ new Aetheris.Kernel.Core.Diagnostics.KernelDiagnostic(+ Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticCode.InvalidArgument,+ Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticSeverity.Error,+ "height must be finite and greater than zero.")+ ]);+ }++ var polylineProfile = profile.ToPolylineProfile();+ if (!polylineProfile.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(polylineProfile.Diagnostics);+ }++ return BrepExtrude.Create(+ polylineProfile.Value,+ new ExtrudeFrame3D(+ new Point3D(0d, 0d, -height * 0.5d),+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ Direction3D.Create(new Vector3D(1d, 0d, 0d))),+ height);+ }+}diff --git a/Aetheris.Forge/ForgeRoundedRectangleProfile.cs b/Aetheris.Forge/ForgeRoundedRectangleProfile.csnew file mode 100644index 00000000..93cde5b2--- /dev/null+++ b/Aetheris.Forge/ForgeRoundedRectangleProfile.cs@@ -0,0 +1,98 @@+using Aetheris.Kernel.Core.Brep.Features;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Results;++namespace Aetheris.Forge;++public sealed record ForgeRoundedRectangleProfile(double Width, double Depth, double CornerRadius, int CornerSegments = 8)+{+ public static KernelResult<ForgeRoundedRectangleProfile> Create(double width, double depth, double cornerRadius, int cornerSegments = 8)+ {+ var diagnostics = Validate(width, depth, cornerRadius, cornerSegments);+ if (diagnostics.Count > 0)+ {+ return KernelResult<ForgeRoundedRectangleProfile>.Failure(diagnostics);+ }++ return KernelResult<ForgeRoundedRectangleProfile>.Success(new ForgeRoundedRectangleProfile(width, depth, cornerRadius, cornerSegments));+ }++ public KernelResult<PolylineProfile2D> ToPolylineProfile()+ {+ var diagnostics = Validate(Width, Depth, CornerRadius, CornerSegments);+ if (diagnostics.Count > 0)+ {+ return KernelResult<PolylineProfile2D>.Failure(diagnostics);+ }++ if (CornerRadius <= 1e-12d)+ {+ return KernelResult<PolylineProfile2D>.Success(PolylineProfile2D.Rectangle(Width, Depth));+ }++ var halfWidth = Width * 0.5d;+ var halfDepth = Depth * 0.5d;+ var radius = CornerRadius;+ var segmentCount = CornerSegments;+ var vertices = new List<ProfilePoint2D>(4 * segmentCount);+ const double quarterTurn = double.Pi * 0.5d;++ AppendCorner(halfWidth - radius, halfDepth - radius, 0d, quarterTurn);+ AppendCorner(-(halfWidth - radius), halfDepth - radius, quarterTurn, quarterTurn);+ AppendCorner(-(halfWidth - radius), -(halfDepth - radius), 2d * quarterTurn, quarterTurn);+ AppendCorner(halfWidth - radius, -(halfDepth - radius), 3d * quarterTurn, quarterTurn);++ return PolylineProfile2D.Create(vertices);++ void AppendCorner(double centerX, double centerY, double startAngle, double sweepAngle)+ {+ for (var i = 0; i < segmentCount; i++)+ {+ var t = i / (double)segmentCount;+ var angle = startAngle + (sweepAngle * t);+ vertices.Add(new ProfilePoint2D(+ centerX + (radius * double.Cos(angle)),+ centerY + (radius * double.Sin(angle))));+ }+ }+ }++ public static IReadOnlyList<KernelDiagnostic> Validate(double width, double depth, double cornerRadius, int cornerSegments = 8)+ {+ var diagnostics = new List<KernelDiagnostic>();+ ValidatePositiveFinite(width, nameof(width), diagnostics);+ ValidatePositiveFinite(depth, nameof(depth), diagnostics);++ if (!double.IsFinite(cornerRadius) || cornerRadius < 0d)+ {+ diagnostics.Add(Invalid($"{nameof(cornerRadius)} must be finite and greater than or equal to zero."));+ }++ if (double.IsFinite(width) && double.IsFinite(depth) && double.IsFinite(cornerRadius))+ {+ var maxRadius = double.Min(width, depth) * 0.5d;+ if (cornerRadius > maxRadius)+ {+ diagnostics.Add(Invalid($"{nameof(cornerRadius)} must be less than or equal to min(width, depth) / 2."));+ }+ }++ if (cornerSegments < 2)+ {+ diagnostics.Add(Invalid($"{nameof(cornerSegments)} must be greater than or equal to 2."));+ }++ return diagnostics;+ }++ private static void ValidatePositiveFinite(double value, string paramName, ICollection<KernelDiagnostic> diagnostics)+ {+ if (!double.IsFinite(value) || value <= 0d)+ {+ diagnostics.Add(Invalid($"{paramName} must be finite and greater than zero."));+ }+ }++ private static KernelDiagnostic Invalid(string message) =>+ new(KernelDiagnosticCode.InvalidArgument, KernelDiagnosticSeverity.Error, message);+}diff --git a/Aetheris.Kernel.Core.Tests/Aetheris.Kernel.Core.Tests.csproj b/Aetheris.Kernel.Core.Tests/Aetheris.Kernel.Core.Tests.csprojindex bc8cf2b3..a7a5d8f7 100644--- a/Aetheris.Kernel.Core.Tests/Aetheris.Kernel.Core.Tests.csproj+++ b/Aetheris.Kernel.Core.Tests/Aetheris.Kernel.Core.Tests.csproj@@ -19,5 +19,7 @@<ItemGroup><ProjectReference Include="..\Aetheris.Kernel.Core\Aetheris.Kernel.Core.csproj" />+ <ProjectReference Include="..\Aetheris.Forge\Aetheris.Forge.csproj" />+ <ProjectReference Include="..\Aetheris.Kernel.StandardLibrary\Aetheris.Kernel.StandardLibrary.csproj" /></ItemGroup></Project>diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/ForgeRoundedRectangleTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/ForgeRoundedRectangleTests.csnew file mode 100644index 00000000..017781e8--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/ForgeRoundedRectangleTests.cs@@ -0,0 +1,37 @@+using Aetheris.Forge;+using Aetheris.Kernel.StandardLibrary;++namespace Aetheris.Kernel.Core.Tests.Brep.Features;++public sealed class ForgeRoundedRectangleTests+{+ [Fact]+ public void RoundedRectangle_ValidParameters_Succeeds()+ {+ var profileResult = ForgeAtomics.RoundedRectangle(width: 40d, depth: 20d, cornerRadius: 3d);++ Assert.True(profileResult.IsSuccess);+ var polylineResult = profileResult.Value.ToPolylineProfile();+ Assert.True(polylineResult.IsSuccess);+ Assert.Equal(32, polylineResult.Value.Vertices.Count);+ }++ [Fact]+ public void RoundedRectangle_InvalidRadius_Fails()+ {+ var profileResult = ForgeAtomics.RoundedRectangle(width: 10d, depth: 6d, cornerRadius: 4d);++ Assert.False(profileResult.IsSuccess);+ Assert.Contains(profileResult.Diagnostics, diagnostic => diagnostic.Message.Contains("min(width, depth) / 2", StringComparison.Ordinal));+ }++ [Fact]+ public void RoundedCornerBox_StandardLibrary_Succeeds()+ {+ var result = StandardLibraryPrimitives.CreateRoundedCornerBox(width: 40d, depth: 20d, height: 12d, cornerRadius: 3d);++ Assert.True(result.IsSuccess);+ Assert.True(result.Value.Topology.Faces.Count() >= 10);+ Assert.True(result.Value.Topology.Edges.Count() >= 24);+ }+}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.csindex b4c14e84..f945d5f8 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs@@ -15,6 +15,7 @@ public sealed class FirmamentExamplePackSmokeTests"testdata/firmament/examples/triangular_prism_basic.firmament","testdata/firmament/examples/hexagonal_prism_basic.firmament","testdata/firmament/examples/straight_slot_basic.firmament",+ "testdata/firmament/examples/rounded_corner_box_basic.firmament","testdata/firmament/examples/box_add_basic.firmament","testdata/firmament/examples/boolean_add_basic.firmament","testdata/firmament/examples/boolean_subtract_basic.firmament",@@ -51,6 +52,7 @@ public sealed class FirmamentExamplePackSmokeTests[InlineData("testdata/firmament/examples/triangular_prism_basic.firmament", "tri1", 0, "primitive", "triangularprism")][InlineData("testdata/firmament/examples/hexagonal_prism_basic.firmament", "hex1", 0, "primitive", "hexagonalprism")][InlineData("testdata/firmament/examples/straight_slot_basic.firmament", "slot1", 0, "primitive", "straightslot")]+ [InlineData("testdata/firmament/examples/rounded_corner_box_basic.firmament", "rbox1", 0, "primitive", "roundedcornerbox")][InlineData("testdata/firmament/examples/box_add_basic.firmament", "joined", 1, "boolean", "add")][InlineData("testdata/firmament/examples/boolean_add_basic.firmament", "joined", 2, "boolean", "add")][InlineData("testdata/firmament/examples/boolean_subtract_basic.firmament", "carved", 2, "boolean", "subtract")]diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.csindex a49fc7a2..234e11c1 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs@@ -219,6 +219,23 @@ public sealed class FirmamentPrimitiveExecutionTestsAssert.True(executed.Body.Topology.Faces.Count() >= 10);}+ [Fact]+ public void Firmament_Routes_RoundedCornerBox_Through_Correct_Seam()+ {+ var result = CompileFixture("testdata/firmament/examples/rounded_corner_box_basic.firmament");++ Assert.True(result.Compilation.IsSuccess);+ var plan = result.Compilation.Value.PrimitiveLoweringPlan!;+ var lowered = Assert.Single(plan.Primitives);+ Assert.Equal(FirmamentLoweredPrimitiveKind.RoundedCornerBox, lowered.Kind);+ Assert.Equal("rbox1", lowered.FeatureId);++ var executed = Assert.Single(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedPrimitives);+ Assert.Equal("rbox1", executed.FeatureId);+ Assert.Equal(FirmamentLoweredPrimitiveKind.RoundedCornerBox, executed.Kind);+ Assert.True(executed.Body.Topology.Faces.Count() >= 10);+ }+[Fact]public void Compile_Executes_Add_Boolean_Into_Real_Body(){diff --git a/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj b/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csprojindex f563f5a2..0a27402b 100644--- a/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj+++ b/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj@@ -7,5 +7,6 @@<ItemGroup><ProjectReference Include="..\Aetheris.Kernel.Core\Aetheris.Kernel.Core.csproj" />+ <ProjectReference Include="..\Aetheris.Kernel.StandardLibrary\Aetheris.Kernel.StandardLibrary.csproj" /></ItemGroup></Project>diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex b176777b..e637b0b1 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -13,6 +13,7 @@ using Aetheris.Kernel.Core.Results;using Aetheris.Kernel.Core.Topology;using Aetheris.Kernel.Firmament.Lowering;using Aetheris.Kernel.Firmament.Validation;+using Aetheris.Kernel.StandardLibrary;namespace Aetheris.Kernel.Firmament.Execution;@@ -386,6 +387,7 @@ internal static class FirmamentPrimitiveExecutorFirmamentLoweredPrimitiveKind.TriangularPrism => TranslateBody(body, new Vector3D(0d, 0d, ((FirmamentLoweredTriangularPrismParameters)primitive.Parameters).Height * 0.5d)),FirmamentLoweredPrimitiveKind.HexagonalPrism => TranslateBody(body, new Vector3D(0d, 0d, ((FirmamentLoweredHexagonalPrismParameters)primitive.Parameters).Height * 0.5d)),FirmamentLoweredPrimitiveKind.StraightSlot => TranslateBody(body, new Vector3D(0d, 0d, ((FirmamentLoweredStraightSlotParameters)primitive.Parameters).Height * 0.5d)),+ FirmamentLoweredPrimitiveKind.RoundedCornerBox => TranslateBody(body, new Vector3D(0d, 0d, ((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Height * 0.5d)),_ => body};}@@ -410,6 +412,11 @@ internal static class FirmamentPrimitiveExecutor((FirmamentLoweredStraightSlotParameters)primitive.Parameters).Length,((FirmamentLoweredStraightSlotParameters)primitive.Parameters).Width,((FirmamentLoweredStraightSlotParameters)primitive.Parameters).Height),+ FirmamentLoweredPrimitiveKind.RoundedCornerBox => StandardLibraryPrimitives.CreateRoundedCornerBox(+ ((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Width,+ ((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Depth,+ ((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Height,+ ((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).CornerRadius),_ => KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Primitive execution for kind '{primitive.Kind}' is not implemented.")])};}diff --git a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.csindex 0829e98f..9bd505b9 100644--- a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs+++ b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs@@ -167,6 +167,12 @@ internal static class FirmamentCanonicalFormatterEmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "width");EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "height");break;+ case FirmamentKnownOpKind.RoundedCornerBox:+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "width");+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "depth");+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "height");+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "corner_radius");+ break;case FirmamentKnownOpKind.Add:EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "to");EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "with");diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.csindex ed5ca05c..69a845a1 100644--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs@@ -107,6 +107,18 @@ internal static class FirmamentPrimitiveLowererHeight: ParseScalar(entry.RawFields["height"])),Placement: LowerPlacement(entry.Placement)));break;+ case FirmamentKnownOpKind.RoundedCornerBox:+ loweredPrimitives.Add(new FirmamentLoweredPrimitive(+ OpIndex: index,+ FeatureId: entry.RawFields["id"],+ Kind: FirmamentLoweredPrimitiveKind.RoundedCornerBox,+ Parameters: new FirmamentLoweredRoundedCornerBoxParameters(+ Width: ParseScalar(entry.RawFields["width"]),+ Depth: ParseScalar(entry.RawFields["depth"]),+ Height: ParseScalar(entry.RawFields["height"]),+ CornerRadius: ParseScalar(entry.RawFields["corner_radius"])),+ Placement: LowerPlacement(entry.Placement)));+ break;case FirmamentKnownOpKind.Add:loweredBooleans.Add(LowerBoolean(index, entry, FirmamentLoweredBooleanKind.Add, "to"));diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.csindex c7a221d9..dad59e55 100644--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs@@ -58,7 +58,8 @@ public enum FirmamentLoweredPrimitiveKindSphere,TriangularPrism,HexagonalPrism,- StraightSlot+ StraightSlot,+ RoundedCornerBox}public abstract record FirmamentLoweredPrimitiveParameters;@@ -87,6 +88,9 @@ public sealed record FirmamentLoweredHexagonalPrismParameters(double AcrossFlatspublic sealed record FirmamentLoweredStraightSlotParameters(double Length, double Width, double Height): FirmamentLoweredPrimitiveParameters;+public sealed record FirmamentLoweredRoundedCornerBoxParameters(double Width, double Depth, double Height, double CornerRadius)+ : FirmamentLoweredPrimitiveParameters;+public sealed record FirmamentLoweredToolOp(string OpName,IReadOnlyDictionary<string, string> RawFields,diff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.csindex 23571985..a8e0214d 100644--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs@@ -10,6 +10,7 @@ public enum FirmamentKnownOpKindTriangularPrism,HexagonalPrism,StraightSlot,+ RoundedCornerBox,Add,Subtract,Intersect,@@ -37,6 +38,7 @@ internal static class FirmamentKnownOpKinds["triangular_prism"] = FirmamentKnownOpKind.TriangularPrism,["hexagonal_prism"] = FirmamentKnownOpKind.HexagonalPrism,["straight_slot"] = FirmamentKnownOpKind.StraightSlot,+ ["rounded_corner_box"] = FirmamentKnownOpKind.RoundedCornerBox,["add"] = FirmamentKnownOpKind.Add,["subtract"] = FirmamentKnownOpKind.Subtract,["intersect"] = FirmamentKnownOpKind.Intersect,@@ -65,6 +67,7 @@ internal static class FirmamentKnownOpKindsFirmamentKnownOpKind.TriangularPrism => FirmamentOpFamily.Primitive,FirmamentKnownOpKind.HexagonalPrism => FirmamentOpFamily.Primitive,FirmamentKnownOpKind.StraightSlot => FirmamentOpFamily.Primitive,+ FirmamentKnownOpKind.RoundedCornerBox => FirmamentOpFamily.Primitive,FirmamentKnownOpKind.Add => FirmamentOpFamily.Boolean,FirmamentKnownOpKind.Subtract => FirmamentOpFamily.Boolean,FirmamentKnownOpKind.Intersect => FirmamentOpFamily.Boolean,diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.csindex 2a23f140..b1e1f8b8 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs@@ -325,6 +325,7 @@ internal static class FirmamentPmiValidatoror FirmamentKnownOpKind.TriangularPrismor FirmamentKnownOpKind.HexagonalPrismor FirmamentKnownOpKind.StraightSlot+ or FirmamentKnownOpKind.RoundedCornerBoxor FirmamentKnownOpKind.Addor FirmamentKnownOpKind.Subtractor FirmamentKnownOpKind.Intersectdiff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.csindex ec4729b8..fc09177d 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs@@ -32,6 +32,7 @@ internal static class FirmamentPrimitiveRequiredFieldValidatorFirmamentKnownOpKind.TriangularPrism => ValidateTriangularPrism(entry, index),FirmamentKnownOpKind.HexagonalPrism => ValidateHexagonalPrism(entry, index),FirmamentKnownOpKind.StraightSlot => ValidateStraightSlot(entry, index),+ FirmamentKnownOpKind.RoundedCornerBox => ValidateRoundedCornerBox(entry, index),_ => KernelResult<bool>.Success(true)};@@ -264,6 +265,49 @@ internal static class FirmamentPrimitiveRequiredFieldValidatorreturn ValidatePlacement(entry, opIndex);}+ private static KernelResult<bool> ValidateRoundedCornerBox(FirmamentParsedOpEntry entry, int opIndex)+ {+ if (!TryGetRequiredNonEmptyScalar(entry, "id", opIndex, out var missingOrTypeDiagnostic))+ {+ return KernelResult<bool>.Failure([missingOrTypeDiagnostic!]);+ }++ var width = ValidatePositiveNumericField(entry, "width", opIndex);+ if (!width.IsSuccess)+ {+ return width;+ }++ var depth = ValidatePositiveNumericField(entry, "depth", opIndex);+ if (!depth.IsSuccess)+ {+ return depth;+ }++ var height = ValidatePositiveNumericField(entry, "height", opIndex);+ if (!height.IsSuccess)+ {+ return height;+ }++ var cornerRadius = ValidateNonNegativeNumericField(entry, "corner_radius", opIndex);+ if (!cornerRadius.IsSuccess)+ {+ return cornerRadius;+ }++ var widthValue = ParseRequiredNumeric(entry.RawFields["width"]);+ var depthValue = ParseRequiredNumeric(entry.RawFields["depth"]);+ var radiusValue = ParseRequiredNumeric(entry.RawFields["corner_radius"]);+ var maxAllowedRadius = double.Min(widthValue, depthValue) * 0.5d;+ if (radiusValue > maxAllowedRadius)+ {+ return InvalidFieldValue("corner_radius", opIndex, entry.OpName, "expected a numeric value less than or equal to min(width, depth) / 2");+ }++ return ValidatePlacement(entry, opIndex);+ }+private static KernelResult<bool> ValidateStraightSlot(FirmamentParsedOpEntry entry, int opIndex){if (!TryGetRequiredNonEmptyScalar(entry, "id", opIndex, out var missingOrTypeDiagnostic))diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.csindex e8343874..7d0b8716 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs@@ -73,6 +73,7 @@ internal static class FirmamentSelectorContractscase FirmamentKnownOpKind.TriangularPrism:case FirmamentKnownOpKind.HexagonalPrism:case FirmamentKnownOpKind.StraightSlot:+ case FirmamentKnownOpKind.RoundedCornerBox:allowedPorts = BoxAllowedPorts;return true;case FirmamentKnownOpKind.Cone:@@ -123,6 +124,7 @@ internal static class FirmamentSelectorContractscase FirmamentKnownOpKind.TriangularPrism:case FirmamentKnownOpKind.HexagonalPrism:case FirmamentKnownOpKind.StraightSlot:+ case FirmamentKnownOpKind.RoundedCornerBox:contracts = BoxPorts;return true;case FirmamentKnownOpKind.Cone:diff --git a/Aetheris.Kernel.StandardLibrary/Aetheris.Kernel.StandardLibrary.csproj b/Aetheris.Kernel.StandardLibrary/Aetheris.Kernel.StandardLibrary.csprojnew file mode 100644index 00000000..eed53a3f--- /dev/null+++ b/Aetheris.Kernel.StandardLibrary/Aetheris.Kernel.StandardLibrary.csproj@@ -0,0 +1,11 @@+<Project Sdk="Microsoft.NET.Sdk">+ <PropertyGroup>+ <TargetFramework>net8.0</TargetFramework>+ <ImplicitUsings>enable</ImplicitUsings>+ <Nullable>enable</Nullable>+ </PropertyGroup>++ <ItemGroup>+ <ProjectReference Include="..\Aetheris.Forge\Aetheris.Forge.csproj" />+ </ItemGroup>+</Project>diff --git a/Aetheris.Kernel.StandardLibrary/StandardLibraryPrimitives.cs b/Aetheris.Kernel.StandardLibrary/StandardLibraryPrimitives.csnew file mode 100644index 00000000..ccf86766--- /dev/null+++ b/Aetheris.Kernel.StandardLibrary/StandardLibraryPrimitives.cs@@ -0,0 +1,19 @@+using Aetheris.Forge;+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Results;++namespace Aetheris.Kernel.StandardLibrary;++public static class StandardLibraryPrimitives+{+ public static KernelResult<BrepBody> CreateRoundedCornerBox(double width, double depth, double height, double cornerRadius, int cornerSegments = 8)+ {+ var profile = ForgeAtomics.RoundedRectangle(width, depth, cornerRadius, cornerSegments);+ if (!profile.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(profile.Diagnostics);+ }++ return ForgeAtomics.ExtrudeCentered(profile.Value, height);+ }+}diff --git a/Aetheris.slnx b/Aetheris.slnxindex 8fa866e6..e73991f6 100644--- a/Aetheris.slnx+++ b/Aetheris.slnx@@ -2,6 +2,8 @@<Project Path="Aetheris.Server/Aetheris.Server.csproj" /><Project Path="Aetheris.Server.Tests/Aetheris.Server.Tests.csproj" /><Project Path="Aetheris.Kernel.Core/Aetheris.Kernel.Core.csproj" />+ <Project Path="Aetheris.Forge/Aetheris.Forge.csproj" />+ <Project Path="Aetheris.Kernel.StandardLibrary/Aetheris.Kernel.StandardLibrary.csproj" /><Project Path="Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj" /><Project Path="Aetheris.Kernel.Firmament.Tests/Aetheris.Kernel.Firmament.Tests.csproj" /><Project Path="Aetheris.Firmament.FrictionLab/Aetheris.Firmament.FrictionLab.csproj" />diff --git a/testdata/firmament/examples/rounded_corner_box_basic.firmament b/testdata/firmament/examples/rounded_corner_box_basic.firmamentnew file mode 100644index 00000000..de569c6f--- /dev/null+++ b/testdata/firmament/examples/rounded_corner_box_basic.firmament@@ -0,0 +1,15 @@+firmament:+ version: 1++model:+ name: rounded_corner_box_basic+ units: mm++ops[1]:+ -+ op: rounded_corner_box+ id: rbox1+ width: 40+ depth: 20+ height: 12+ corner_radius: 3