Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add STEP Tier1 circle and curved surface import support
Yuechen Lidbfb4a04e77f
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.csindex 4eeac635..26108dbf 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs@@ -8,7 +8,7 @@ internal static class Step242FixtureCorpus// M24 generated golden: regenerate by exporting CreateBox(2,2,2) via Step242Exporter.public static readonly string CanonicalBoxGolden = CreateCanonicalBoxGolden();- public const string UnsupportedSphericalSurface = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=SPHERICAL_SURFACE($,#2,1.0);\n#2=AXIS2_PLACEMENT_3D($,#3,#4,#5);\n#3=CARTESIAN_POINT($,(0,0,0));\n#4=DIRECTION($,(0,0,1));\n#5=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";+ public const string UnsupportedToroidalSurface = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=TOROIDAL_SURFACE($,#2,2.0,0.5);\n#2=AXIS2_PLACEMENT_3D($,#3,#4,#5);\n#3=CARTESIAN_POINT($,(0,0,0));\n#4=DIRECTION($,(0,0,1));\n#5=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";public const string MalformedMissingParen = "ISO-10303-21; DATA; #1=MANIFOLD_SOLID_BREP('bad',#2 ENDSEC; END-ISO-10303-21;";diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.csindex 3bf24237..329ae9dc 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs@@ -60,7 +60,7 @@ public sealed class Step242ImporterTests[Fact]public void ImportBody_UnsupportedEntityInParseableText_ReturnsNotImplementedDiagnostic(){- var unsupported = Step242FixtureCorpus.UnsupportedSphericalSurface;+ var unsupported = Step242FixtureCorpus.UnsupportedToroidalSurface;var import = Step242Importer.ImportBody(unsupported);diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.csnew file mode 100644index 00000000..08755978--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs@@ -0,0 +1,104 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Picking;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Step242;++public sealed class Step242Tier1GeometryTests+{+ [Fact]+ public void ImportBody_CircleEdgeSubset_ImportsValidatesAndTessellates()+ {+ var import = Step242Importer.ImportBody(BuildCylinderSideFaceStepText());++ Assert.True(import.IsSuccess);+ var validation = BrepBindingValidator.Validate(import.Value, requireAllEdgeAndFaceBindings: true);+ Assert.True(validation.IsSuccess);++ var tessellation = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellation.IsSuccess);++ var ray = new Ray3D(new Point3D(0d, 1.5d, 0.5d), Direction3D.Create(new Vector3D(0d, -1d, 0d)));+ var pick = BrepPicker.Pick(import.Value, tessellation.Value, ray, PickQueryOptions.Default with { NearestOnly = true });+ Assert.True(pick.IsSuccess);+ Assert.NotEmpty(pick.Value);+ }++ [Fact]+ public void ImportBody_CircleFullLoopTrim_ProducesFullCircleInterval()+ {+ var import = Step242Importer.ImportBody(BuildSphereFaceStepText());++ Assert.True(import.IsSuccess);+ Assert.True(import.Value.Bindings.TryGetEdgeBinding(new Aetheris.Kernel.Core.Topology.EdgeId(2), out var trim));+ Assert.NotNull(trim.TrimInterval);+ Assert.Equal(0d, trim.TrimInterval!.Value.Start, 8);+ Assert.Equal(2d * double.Pi, trim.TrimInterval.Value.End, 8);+ }++ [Fact]+ public void ImportBody_CircleTrimProjectionFailure_ReturnsDeterministicDiagnostic()+ {+ var import = Step242Importer.ImportBody(BuildInvalidCircleTrimStepText());++ Assert.False(import.IsSuccess);+ var diagnostic = Assert.Single(import.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.ValidationFailed, diagnostic.Code);+ Assert.Equal("Importer.Geometry.CircleTrim", diagnostic.Source);+ Assert.StartsWith("Unable to compute circle trim", diagnostic.Message, StringComparison.Ordinal);+ }++ [Fact]+ public void ImportBody_CylindricalSurfaceFace_ImportsAndTessellates()+ {+ var import = Step242Importer.ImportBody(BuildCylinderSideFaceStepText());++ Assert.True(import.IsSuccess);+ var tessellation = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellation.IsSuccess);+ Assert.NotEmpty(tessellation.Value.FacePatches);+ }++ [Fact]+ public void ImportBody_ConicalSurfaceFace_ImportsAndTessellates()+ {+ var import = Step242Importer.ImportBody(BuildConeSideFaceStepText());++ Assert.True(import.IsSuccess);+ var tessellation = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellation.IsSuccess);+ Assert.NotEmpty(tessellation.Value.FacePatches);+ }++ [Fact]+ public void ImportBody_SphericalSurfaceFace_ImportsAndPickSucceeds()+ {+ var import = Step242Importer.ImportBody(BuildSphereOnlyStepText());++ Assert.True(import.IsSuccess);+ var tessellation = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellation.IsSuccess);++ var ray = new Ray3D(new Point3D(0d, 0d, 3d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));+ var pick = BrepPicker.Pick(import.Value, tessellation.Value, ray, PickQueryOptions.Default with { NearestOnly = true });+ Assert.True(pick.IsSuccess);+ Assert.NotEmpty(pick.Value);+ }++ private static string BuildCylinderSideFaceStepText() =>+ "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4),#5,.T.);\n#4=FACE_OUTER_BOUND($,#6,.T.);\n#5=CYLINDRICAL_SURFACE($,#30,1.0);\n#6=EDGE_LOOP($,(#7,#8,#9,#10));\n#7=ORIENTED_EDGE($,$,$,#11,.T.);\n#8=ORIENTED_EDGE($,$,$,#12,.T.);\n#9=ORIENTED_EDGE($,$,$,#13,.T.);\n#10=ORIENTED_EDGE($,$,$,#14,.T.);\n#11=EDGE_CURVE($,#15,#16,#17,.T.);\n#12=EDGE_CURVE($,#16,#16,#18,.T.);\n#13=EDGE_CURVE($,#16,#15,#19,.T.);\n#14=EDGE_CURVE($,#15,#15,#20,.T.);\n#15=VERTEX_POINT($,#21);\n#16=VERTEX_POINT($,#22);\n#17=LINE($,#21,#23);\n#18=CIRCLE($,#31,1.0);\n#19=LINE($,#22,#24);\n#20=CIRCLE($,#30,1.0);\n#21=CARTESIAN_POINT($,(1,0,0));\n#22=CARTESIAN_POINT($,(1,0,1));\n#23=VECTOR($,#25,1.0);\n#24=VECTOR($,#26,1.0);\n#25=DIRECTION($,(0,0,1));\n#26=DIRECTION($,(0,0,-1));\n#30=AXIS2_PLACEMENT_3D($,#27,#28,#29);\n#31=AXIS2_PLACEMENT_3D($,#32,#28,#29);\n#32=CARTESIAN_POINT($,(0,0,1));\n#27=CARTESIAN_POINT($,(0,0,0));\n#28=DIRECTION($,(0,0,1));\n#29=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";++ private static string BuildConeSideFaceStepText() =>+ "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4),#5,.T.);\n#4=FACE_OUTER_BOUND($,#6,.T.);\n#5=CONICAL_SURFACE($,#30,1.0,0.7853981633974483);\n#6=EDGE_LOOP($,(#7,#8,#9,#10));\n#7=ORIENTED_EDGE($,$,$,#11,.T.);\n#8=ORIENTED_EDGE($,$,$,#12,.T.);\n#9=ORIENTED_EDGE($,$,$,#13,.T.);\n#10=ORIENTED_EDGE($,$,$,#14,.T.);\n#11=EDGE_CURVE($,#15,#16,#17,.T.);\n#12=EDGE_CURVE($,#16,#16,#18,.T.);\n#13=EDGE_CURVE($,#16,#15,#19,.T.);\n#14=EDGE_CURVE($,#15,#15,#20,.T.);\n#15=VERTEX_POINT($,#21);\n#16=VERTEX_POINT($,#22);\n#17=LINE($,#21,#23);\n#18=CIRCLE($,#31,2.0);\n#19=LINE($,#22,#24);\n#20=CIRCLE($,#30,1.0);\n#21=CARTESIAN_POINT($,(1,0,1));\n#22=CARTESIAN_POINT($,(2,0,2));\n#23=VECTOR($,#25,1.0);\n#24=VECTOR($,#26,1.0);\n#25=DIRECTION($,(1,0,1));\n#26=DIRECTION($,(-1,0,-1));\n#30=AXIS2_PLACEMENT_3D($,#27,#28,#29);\n#31=AXIS2_PLACEMENT_3D($,#32,#28,#29);\n#32=CARTESIAN_POINT($,(0,0,2));\n#27=CARTESIAN_POINT($,(0,0,1));\n#28=DIRECTION($,(0,0,1));\n#29=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";++ private static string BuildSphereOnlyStepText() =>+ "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((),#4,.T.);\n#4=SPHERICAL_SURFACE($,#10,1.0);\n#10=AXIS2_PLACEMENT_3D($,#11,#12,#13);\n#11=CARTESIAN_POINT($,(0,0,0));\n#12=DIRECTION($,(0,0,1));\n#13=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";++ private static string BuildSphereFaceStepText() => BuildCylinderSideFaceStepText();++ private static string BuildInvalidCircleTrimStepText() =>+ "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4),#5,.T.);\n#4=FACE_OUTER_BOUND($,#6,.T.);\n#5=PLANE($,#30);\n#6=EDGE_LOOP($,(#7));\n#7=ORIENTED_EDGE($,$,$,#8,.T.);\n#8=EDGE_CURVE($,#9,#10,#11,.T.);\n#9=VERTEX_POINT($,#12);\n#10=VERTEX_POINT($,#13);\n#11=CIRCLE($,#31,1.0);\n#12=CARTESIAN_POINT($,(2,0,0));\n#13=CARTESIAN_POINT($,(0,2,0));\n#30=AXIS2_PLACEMENT_3D($,#14,#15,#16);\n#31=AXIS2_PLACEMENT_3D($,#14,#15,#16);\n#14=CARTESIAN_POINT($,(0,0,0));\n#15=DIRECTION($,(0,0,1));\n#16=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";+}diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.csindex d028c4ae..f8c348b7 100644--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs@@ -98,13 +98,27 @@ public static class Step242Importer}var faceEntity = faceEntityResult.Value;+ var surfaceRefResult = Step242SubsetDecoder.ReadReference(faceEntity, 1, "ADVANCED_FACE surface");+ if (!surfaceRefResult.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(surfaceRefResult.Diagnostics);+ }++ var surfaceEntityResult = document.TryGetEntity(surfaceRefResult.Value.TargetId);+ if (!surfaceEntityResult.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(surfaceEntityResult.Diagnostics);+ }++ var isSphericalFace = string.Equals(surfaceEntityResult.Value.Name, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase);+var boundRefsResult = Step242SubsetDecoder.ReadReferenceList(faceEntity, 0, "ADVANCED_FACE bounds");if (!boundRefsResult.IsSuccess){return KernelResult<BrepBody>.Failure(boundRefsResult.Diagnostics);}- if (boundRefsResult.Value.Count == 0)+ if (boundRefsResult.Value.Count == 0 && !isSphericalFace){return Failure("ADVANCED_FACE without bounds is unsupported in M23 subset.", $"Entity:{faceEntity.Id}");}@@ -234,45 +248,21 @@ public static class Step242Importervar faceId = builder.AddFace(loopIds);faceIds.Add(faceId);- var planeRefResult = Step242SubsetDecoder.ReadReference(faceEntity, 1, "ADVANCED_FACE surface");- if (!planeRefResult.IsSuccess)- {- return KernelResult<BrepBody>.Failure(planeRefResult.Diagnostics);- }-- var planeEntityResult = document.TryGetEntity(planeRefResult.Value.TargetId, "PLANE");- if (!planeEntityResult.IsSuccess)- {- return KernelResult<BrepBody>.Failure(planeEntityResult.Diagnostics);- }-- var planeResult = Step242SubsetDecoder.ReadPlaneSurface(document, planeEntityResult.Value);- if (!planeResult.IsSuccess)- {- return KernelResult<BrepBody>.Failure(planeResult.Diagnostics);- }-var faceSameSenseResult = Step242SubsetDecoder.ReadBoolean(faceEntity, 2, "ADVANCED_FACE same_sense");if (!faceSameSenseResult.IsSuccess){return KernelResult<BrepBody>.Failure(faceSameSenseResult.Diagnostics);}- var faceSurface = planeResult.Value;- if (!faceSameSenseResult.Value)+ var bindSurfaceResult = DecodeSurfaceGeometry(document, surfaceEntityResult.Value, faceSameSenseResult.Value, nextSurfaceGeometryId);+ if (!bindSurfaceResult.IsSuccess){- if (!Direction3D.TryCreate(-faceSurface.Normal.ToVector(), out var reversedNormal))- {- return OrientationFailure<BrepBody>(- "ADVANCED_FACE same_sense not supported for this face",- SourceFor(faceEntity.Id, "Importer.Orientation.AdvancedFaceSense"));- }-- faceSurface = new PlaneSurface(faceSurface.Origin, reversedNormal, faceSurface.UAxis);+ return KernelResult<BrepBody>.Failure(bindSurfaceResult.Diagnostics);}- var surfaceGeometryId = new SurfaceGeometryId(nextSurfaceGeometryId++);- geometry.AddSurface(surfaceGeometryId, SurfaceGeometry.FromPlane(faceSurface));+ var (surfaceGeometryId, surfaceGeometry) = bindSurfaceResult.Value;+ nextSurfaceGeometryId++;+ geometry.AddSurface(surfaceGeometryId, surfaceGeometry);bindings.AddFaceBinding(new FaceGeometryBinding(faceId, surfaceGeometryId));}@@ -347,40 +337,31 @@ public static class Step242Importerreturn KernelResult<EdgeId>.Failure(endVertexResult.Diagnostics);}- var lineEntityResult = document.TryGetEntity(lineRefResult.Value.TargetId, "LINE");- if (!lineEntityResult.IsSuccess)- {- return KernelResult<EdgeId>.Failure(lineEntityResult.Diagnostics);- }-- var lineResult = Step242SubsetDecoder.ReadLineCurve(document, lineEntityResult.Value);- if (!lineResult.IsSuccess)+ var curveEntityResult = document.TryGetEntity(lineRefResult.Value.TargetId);+ if (!curveEntityResult.IsSuccess){- return KernelResult<EdgeId>.Failure(lineResult.Diagnostics);+ return KernelResult<EdgeId>.Failure(curveEntityResult.Diagnostics);}var edgeId = builder.AddEdge(startVertexResult.Value.VertexId, endVertexResult.Value.VertexId);edgeMap.Add(edgeCurveEntity.Id, edgeId);- var startParameter = ComputeLineParameter(lineResult.Value, startVertexResult.Value.Point);- var endParameter = ComputeLineParameter(lineResult.Value, endVertexResult.Value.Point);+ var curveGeometryId = new CurveGeometryId(nextCurveGeometryId++);- if (endParameter < startParameter)+ var bindCurveResult = DecodeCurveGeometry(+ document,+ curveEntityResult.Value,+ startVertexResult.Value.Point,+ endVertexResult.Value.Point,+ edgeSameSense,+ edgeCurveEntity.Id);+ if (!bindCurveResult.IsSuccess){- if (!edgeSameSense)- {- return OrientationFailure<EdgeId>(- "EDGE_CURVE same_sense semantics unsupported for this edge",- SourceFor(edgeCurveEntity.Id, "Importer.Orientation.EdgeCurveSense"));- }-- return FailureEdge("EDGE_CURVE line parameterization is opposite to vertex ordering.", SourceFor(edgeCurveEntity.Id, "Importer.Geometry.EdgeCurveParameters"));+ return KernelResult<EdgeId>.Failure(bindCurveResult.Diagnostics);}- var curveGeometryId = new CurveGeometryId(nextCurveGeometryId++);-- geometry.AddCurve(curveGeometryId, CurveGeometry.FromLine(lineResult.Value));- bindings.AddEdgeBinding(new EdgeGeometryBinding(edgeId, curveGeometryId, new ParameterInterval(startParameter, endParameter)));+ geometry.AddCurve(curveGeometryId, bindCurveResult.Value.CurveGeometry);+ bindings.AddEdgeBinding(new EdgeGeometryBinding(edgeId, curveGeometryId, bindCurveResult.Value.TrimInterval));return KernelResult<EdgeId>.Success(edgeId);}@@ -409,10 +390,191 @@ public static class Step242Importerprivate static bool IsClearlyUnsupportedEntity(Step242ParsedEntity entity){- return string.Equals(entity.Name, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase)- || string.Equals(entity.Name, "CIRCLE", StringComparison.OrdinalIgnoreCase)- || string.Equals(entity.Name, "CYLINDRICAL_SURFACE", StringComparison.OrdinalIgnoreCase)- || string.Equals(entity.Name, "CONICAL_SURFACE", StringComparison.OrdinalIgnoreCase);+ return string.Equals(entity.Name, "TOROIDAL_SURFACE", StringComparison.OrdinalIgnoreCase);+ }++ private static KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)> DecodeCurveGeometry(+ Step242ParsedDocument document,+ Step242ParsedEntity curveEntity,+ Point3D startPoint,+ Point3D endPoint,+ bool edgeSameSense,+ int edgeCurveEntityId)+ {+ if (string.Equals(curveEntity.Name, "LINE", StringComparison.OrdinalIgnoreCase))+ {+ var lineResult = Step242SubsetDecoder.ReadLineCurve(document, curveEntity);+ if (!lineResult.IsSuccess)+ {+ return KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Failure(lineResult.Diagnostics);+ }++ var startParameter = ComputeLineParameter(lineResult.Value, startPoint);+ var endParameter = ComputeLineParameter(lineResult.Value, endPoint);++ if (endParameter < startParameter)+ {+ if (!edgeSameSense)+ {+ return OrientationFailure<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>(+ "EDGE_CURVE same_sense semantics unsupported for this edge",+ SourceFor(edgeCurveEntityId, "Importer.Orientation.EdgeCurveSense"));+ }++ return FailureCurveBinding("EDGE_CURVE line parameterization is opposite to vertex ordering.", SourceFor(edgeCurveEntityId, "Importer.Geometry.EdgeCurveParameters"));+ }++ return KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Success((+ CurveGeometry.FromLine(lineResult.Value),+ new ParameterInterval(startParameter, endParameter)));+ }++ if (string.Equals(curveEntity.Name, "CIRCLE", StringComparison.OrdinalIgnoreCase))+ {+ var circleResult = Step242SubsetDecoder.ReadCircleCurve(document, curveEntity);+ if (!circleResult.IsSuccess)+ {+ return KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Failure(circleResult.Diagnostics);+ }++ var trimResult = ComputeCircleTrim(circleResult.Value, startPoint, endPoint);+ if (!trimResult.IsSuccess)+ {+ return KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Failure(trimResult.Diagnostics);+ }++ return KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Success((+ CurveGeometry.FromCircle(circleResult.Value),+ trimResult.Value));+ }++ return FailureCurveBinding($"EDGE_CURVE geometry '{curveEntity.Name}' is unsupported.", SourceFor(curveEntity.Id, "Importer.EntityFamily"));+ }++ private static KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)> DecodeSurfaceGeometry(+ Step242ParsedDocument document,+ Step242ParsedEntity surfaceEntity,+ bool faceSameSense,+ int nextSurfaceGeometryId)+ {+ var geometryId = new SurfaceGeometryId(nextSurfaceGeometryId);++ if (string.Equals(surfaceEntity.Name, "PLANE", StringComparison.OrdinalIgnoreCase))+ {+ var planeResult = Step242SubsetDecoder.ReadPlaneSurface(document, surfaceEntity);+ if (!planeResult.IsSuccess)+ {+ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(planeResult.Diagnostics);+ }++ var faceSurface = planeResult.Value;+ if (!faceSameSense)+ {+ if (!Direction3D.TryCreate(-faceSurface.Normal.ToVector(), out var reversedNormal))+ {+ return OrientationFailure<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>(+ "ADVANCED_FACE same_sense not supported for this face",+ SourceFor(surfaceEntity.Id, "Importer.Orientation.AdvancedFaceSense"));+ }++ faceSurface = new PlaneSurface(faceSurface.Origin, reversedNormal, faceSurface.UAxis);+ }++ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromPlane(faceSurface)));+ }++ if (string.Equals(surfaceEntity.Name, "CYLINDRICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ {+ var cylinderResult = Step242SubsetDecoder.ReadCylindricalSurface(document, surfaceEntity);+ if (!cylinderResult.IsSuccess)+ {+ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(cylinderResult.Diagnostics);+ }++ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromCylinder(cylinderResult.Value)));+ }++ if (string.Equals(surfaceEntity.Name, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ {+ var sphereResult = Step242SubsetDecoder.ReadSphericalSurface(document, surfaceEntity);+ if (!sphereResult.IsSuccess)+ {+ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(sphereResult.Diagnostics);+ }++ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromSphere(sphereResult.Value)));+ }++ if (string.Equals(surfaceEntity.Name, "CONICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ {+ var coneResult = Step242SubsetDecoder.ReadConicalSurface(document, surfaceEntity);+ if (!coneResult.IsSuccess)+ {+ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(coneResult.Diagnostics);+ }++ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromCone(coneResult.Value)));+ }++ return FailureSurfaceBinding($"ADVANCED_FACE surface '{surfaceEntity.Name}' is unsupported.", SourceFor(surfaceEntity.Id, "Importer.EntityFamily"));+ }++ private static KernelResult<ParameterInterval> ComputeCircleTrim(Circle3Curve circle, Point3D startPoint, Point3D endPoint)+ {+ const double tolerance = 1e-6d;+ if ((startPoint - endPoint).Length <= tolerance)+ {+ return KernelResult<ParameterInterval>.Success(new ParameterInterval(0d, 2d * double.Pi));+ }++ var startAngleResult = ProjectPointToCircleAngle(circle, startPoint, tolerance);+ if (!startAngleResult.IsSuccess)+ {+ return KernelResult<ParameterInterval>.Failure(startAngleResult.Diagnostics);+ }++ var endAngleResult = ProjectPointToCircleAngle(circle, endPoint, tolerance);+ if (!endAngleResult.IsSuccess)+ {+ return KernelResult<ParameterInterval>.Failure(endAngleResult.Diagnostics);+ }++ var start = startAngleResult.Value;+ var end = endAngleResult.Value;+ if (end < start)+ {+ end += 2d * double.Pi;+ }++ if (end <= start)+ {+ return FailureCircleTrim("Unable to compute circle trim interval with a positive span.", "Importer.Geometry.CircleTrim");+ }++ return KernelResult<ParameterInterval>.Success(new ParameterInterval(start, end));+ }++ private static KernelResult<double> ProjectPointToCircleAngle(Circle3Curve circle, Point3D point, double tolerance)+ {+ var radial = point - circle.Center;+ var normalComponent = radial.Dot(circle.Normal.ToVector());+ var inPlane = radial - (circle.Normal.ToVector() * normalComponent);+ var inPlaneLength = inPlane.Length;++ if (double.Abs(normalComponent) > tolerance || double.Abs(inPlaneLength - circle.Radius) > tolerance)+ {+ return FailureCircleTrimAngle("Unable to compute circle trim from supplied vertices.", "Importer.Geometry.CircleTrim");+ }++ var x = inPlane.Dot(circle.XAxis.ToVector());+ var y = inPlane.Dot(circle.YAxis.ToVector());+ var angle = double.Atan2(y, x);+ if (angle < 0d)+ {+ angle += 2d * double.Pi;+ }++ return KernelResult<double>.Success(angle);}private static double ComputeLineParameter(Line3Curve line, Point3D point)@@ -427,6 +589,18 @@ public static class Step242Importerprivate static KernelResult<EdgeId> FailureEdge(string message, string source) =>KernelResult<EdgeId>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);+ private static KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)> FailureCurveBinding(string message, string source) =>+ KernelResult<(CurveGeometry CurveGeometry, ParameterInterval TrimInterval)>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);++ private static KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)> FailureSurfaceBinding(string message, string source) =>+ KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);++ private static KernelResult<ParameterInterval> FailureCircleTrim(string message, string source) =>+ KernelResult<ParameterInterval>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, message, source)]);++ private static KernelResult<double> FailureCircleTrimAngle(string message, string source) =>+ KernelResult<double>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, message, source)]);+private static KernelResult<T> OrientationFailure<T>(string message, string source) =>KernelResult<T>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, message, source)]);diff --git a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.csindex 9ab35529..f164e97f 100644--- a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs@@ -218,6 +218,225 @@ internal static class Step242SubsetDecoder}}+ public static KernelResult<Circle3Curve> ReadCircleCurve(Step242ParsedDocument document, Step242ParsedEntity circleEntity)+ {+ var placementResult = ReadAxis2Placement3D(document, circleEntity, 1, "CIRCLE position", "Importer.Geometry.Circle");+ if (!placementResult.IsSuccess)+ {+ return KernelResult<Circle3Curve>.Failure(placementResult.Diagnostics);+ }++ var radiusResult = ReadPositiveNumber(circleEntity, 2, "CIRCLE radius", "Importer.Geometry.Circle");+ if (!radiusResult.IsSuccess)+ {+ return KernelResult<Circle3Curve>.Failure(radiusResult.Diagnostics);+ }++ try+ {+ return KernelResult<Circle3Curve>.Success(new Circle3Curve(placementResult.Value.Origin, placementResult.Value.Axis, radiusResult.Value, placementResult.Value.ReferenceAxis));+ }+ catch (ArgumentException)+ {+ return FailureCircle("Invalid CIRCLE placement produced degenerate frame.", "Importer.Geometry.Circle");+ }+ }++ public static KernelResult<CylinderSurface> ReadCylindricalSurface(Step242ParsedDocument document, Step242ParsedEntity cylinderEntity)+ {+ var placementResult = ReadAxis2Placement3D(document, cylinderEntity, 1, "CYLINDRICAL_SURFACE position", "Importer.Geometry.Cylinder");+ if (!placementResult.IsSuccess)+ {+ return KernelResult<CylinderSurface>.Failure(placementResult.Diagnostics);+ }++ var radiusResult = ReadPositiveNumber(cylinderEntity, 2, "CYLINDRICAL_SURFACE radius", "Importer.Geometry.Cylinder");+ if (!radiusResult.IsSuccess)+ {+ return KernelResult<CylinderSurface>.Failure(radiusResult.Diagnostics);+ }++ try+ {+ return KernelResult<CylinderSurface>.Success(new CylinderSurface(placementResult.Value.Origin, placementResult.Value.Axis, radiusResult.Value, placementResult.Value.ReferenceAxis));+ }+ catch (ArgumentException)+ {+ return FailureCylinder("Invalid CYLINDRICAL_SURFACE placement produced degenerate frame.", "Importer.Geometry.Cylinder");+ }+ }++ public static KernelResult<SphereSurface> ReadSphericalSurface(Step242ParsedDocument document, Step242ParsedEntity sphereEntity)+ {+ var placementResult = ReadAxis2Placement3D(document, sphereEntity, 1, "SPHERICAL_SURFACE position", "Importer.Geometry.Sphere");+ if (!placementResult.IsSuccess)+ {+ return KernelResult<SphereSurface>.Failure(placementResult.Diagnostics);+ }++ var radiusResult = ReadPositiveNumber(sphereEntity, 2, "SPHERICAL_SURFACE radius", "Importer.Geometry.Sphere");+ if (!radiusResult.IsSuccess)+ {+ return KernelResult<SphereSurface>.Failure(radiusResult.Diagnostics);+ }++ try+ {+ return KernelResult<SphereSurface>.Success(new SphereSurface(placementResult.Value.Origin, placementResult.Value.Axis, radiusResult.Value, placementResult.Value.ReferenceAxis));+ }+ catch (ArgumentException)+ {+ return FailureSphere("Invalid SPHERICAL_SURFACE placement produced degenerate frame.", "Importer.Geometry.Sphere");+ }+ }++ public static KernelResult<ConeSurface> ReadConicalSurface(Step242ParsedDocument document, Step242ParsedEntity coneEntity)+ {+ var placementResult = ReadAxis2Placement3D(document, coneEntity, 1, "CONICAL_SURFACE position", "Importer.Geometry.Cone");+ if (!placementResult.IsSuccess)+ {+ return KernelResult<ConeSurface>.Failure(placementResult.Diagnostics);+ }++ var radiusResult = ReadPositiveNumber(coneEntity, 2, "CONICAL_SURFACE radius", "Importer.Geometry.Cone");+ if (!radiusResult.IsSuccess)+ {+ return KernelResult<ConeSurface>.Failure(radiusResult.Diagnostics);+ }++ var semiAngleResult = ReadNumberArgument(coneEntity, 3, "CONICAL_SURFACE semi_angle", "Importer.Geometry.Cone");+ if (!semiAngleResult.IsSuccess)+ {+ return KernelResult<ConeSurface>.Failure(semiAngleResult.Diagnostics);+ }++ if (semiAngleResult.Value <= 0d || semiAngleResult.Value >= (double.Pi / 2d))+ {+ return FailureCone("CONICAL_SURFACE semi-angle must be in the range (0, pi/2).", "Importer.Geometry.Cone");+ }++ var offset = placementResult.Value.Axis.ToVector() * (radiusResult.Value / double.Tan(semiAngleResult.Value));+ var apex = placementResult.Value.Origin - offset;++ try+ {+ return KernelResult<ConeSurface>.Success(new ConeSurface(apex, placementResult.Value.Axis, semiAngleResult.Value, placementResult.Value.ReferenceAxis));+ }+ catch (ArgumentException)+ {+ return FailureCone("Invalid CONICAL_SURFACE placement produced degenerate frame.", "Importer.Geometry.Cone");+ }+ }++ private static KernelResult<(Point3D Origin, Direction3D Axis, Direction3D ReferenceAxis)> ReadAxis2Placement3D(+ Step242ParsedDocument document,+ Step242ParsedEntity ownerEntity,+ int argumentIndex,+ string context,+ string geometrySource)+ {+ var placementRefResult = ReadReference(ownerEntity, argumentIndex, context);+ if (!placementRefResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(placementRefResult.Diagnostics);+ }++ var placementEntityResult = document.TryGetEntity(placementRefResult.Value.TargetId, "AXIS2_PLACEMENT_3D");+ if (!placementEntityResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(placementEntityResult.Diagnostics);+ }++ var placementEntity = placementEntityResult.Value;++ var originRefResult = ReadReference(placementEntity, 1, "AXIS2_PLACEMENT_3D origin");+ if (!originRefResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(originRefResult.Diagnostics);+ }++ var originEntityResult = document.TryGetEntity(originRefResult.Value.TargetId, "CARTESIAN_POINT");+ if (!originEntityResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(originEntityResult.Diagnostics);+ }++ var originResult = ReadCartesianPoint(originEntityResult.Value, "AXIS2_PLACEMENT_3D origin");+ if (!originResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(originResult.Diagnostics);+ }++ var axisRefResult = ReadReference(placementEntity, 2, "AXIS2_PLACEMENT_3D axis");+ if (!axisRefResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(axisRefResult.Diagnostics);+ }++ var axisEntityResult = document.TryGetEntity(axisRefResult.Value.TargetId, "DIRECTION");+ if (!axisEntityResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(axisEntityResult.Diagnostics);+ }++ var axisResult = ReadDirection(axisEntityResult.Value, "AXIS2_PLACEMENT_3D axis");+ if (!axisResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(axisResult.Diagnostics);+ }++ var refDirRefResult = ReadReference(placementEntity, 3, "AXIS2_PLACEMENT_3D ref direction");+ if (!refDirRefResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(refDirRefResult.Diagnostics);+ }++ var refDirEntityResult = document.TryGetEntity(refDirRefResult.Value.TargetId, "DIRECTION");+ if (!refDirEntityResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(refDirEntityResult.Diagnostics);+ }++ var refDirResult = ReadDirection(refDirEntityResult.Value, "AXIS2_PLACEMENT_3D ref direction");+ if (!refDirResult.IsSuccess)+ {+ return KernelResult<(Point3D, Direction3D, Direction3D)>.Failure(refDirResult.Diagnostics);+ }++ if (double.Abs(axisResult.Value.ToVector().Dot(refDirResult.Value.ToVector())) >= 1d - 1e-12d)+ {+ return FailureAxisPlacement("AXIS2_PLACEMENT_3D axis and ref direction must not be parallel.", geometrySource);+ }++ return KernelResult<(Point3D, Direction3D, Direction3D)>.Success((originResult.Value, axisResult.Value, refDirResult.Value));+ }++ private static KernelResult<double> ReadNumberArgument(Step242ParsedEntity entity, int argumentIndex, string context, string source)+ {+ if (argumentIndex < 0 || argumentIndex >= entity.Arguments.Count)+ {+ return FailureNumberCode($"{context}: missing argument at index {argumentIndex}.", source);+ }++ return ReadNumberCode(entity.Arguments[argumentIndex], context, source);+ }++ private static KernelResult<double> ReadPositiveNumber(Step242ParsedEntity entity, int argumentIndex, string context, string source)+ {+ var numberResult = ReadNumberArgument(entity, argumentIndex, context, source);+ if (!numberResult.IsSuccess)+ {+ return numberResult;+ }++ if (numberResult.Value <= 0d)+ {+ return FailureNumberCode($"{context}: value must be greater than zero.", source);+ }++ return numberResult;+ }+private static KernelResult<Point3D> ReadCartesianPoint(Step242ParsedEntity pointEntity, string context){if (pointEntity.Arguments.Count < 2)@@ -284,6 +503,21 @@ internal static class Step242SubsetDecoderreturn KernelResult<double>.Success(number.Value);}+ private static KernelResult<double> ReadNumberCode(Step242Value value, string context, string source)+ {+ if (value is not Step242NumberValue number)+ {+ return Failure<double>(KernelDiagnosticCode.InvalidArgument, $"{context}: expected numeric value.", source);+ }++ if (!double.IsFinite(number.Value))+ {+ return Failure<double>(KernelDiagnosticCode.InvalidArgument, $"{context}: numeric value must be finite.", source);+ }++ return KernelResult<double>.Success(number.Value);+ }+private static KernelResult<Step242EntityReference> FailureRef(string message, string source) => Failure<Step242EntityReference>(message, source);private static KernelResult<IReadOnlyList<Step242EntityReference>> FailureList(string message, string source) => Failure<IReadOnlyList<Step242EntityReference>>(message, source);@@ -298,8 +532,24 @@ internal static class Step242SubsetDecoderprivate static KernelResult<PlaneSurface> FailurePlane(string message, string source) => Failure<PlaneSurface>(message, source);+ private static KernelResult<Circle3Curve> FailureCircle(string message, string source) => Failure<Circle3Curve>(KernelDiagnosticCode.InvalidArgument, message, source);++ private static KernelResult<CylinderSurface> FailureCylinder(string message, string source) => Failure<CylinderSurface>(KernelDiagnosticCode.InvalidArgument, message, source);++ private static KernelResult<SphereSurface> FailureSphere(string message, string source) => Failure<SphereSurface>(KernelDiagnosticCode.InvalidArgument, message, source);++ private static KernelResult<ConeSurface> FailureCone(string message, string source) => Failure<ConeSurface>(KernelDiagnosticCode.InvalidArgument, message, source);++ private static KernelResult<(Point3D Origin, Direction3D Axis, Direction3D ReferenceAxis)> FailureAxisPlacement(string message, string source)+ => Failure<(Point3D Origin, Direction3D Axis, Direction3D ReferenceAxis)>(KernelDiagnosticCode.InvalidArgument, message, source);++ private static KernelResult<double> FailureNumberCode(string message, string source) => Failure<double>(KernelDiagnosticCode.InvalidArgument, message, source);+private static string SourceFor(int _entityId, string stableSource) => stableSource;private static KernelResult<T> Failure<T>(string message, string source) =>KernelResult<T>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);++ private static KernelResult<T> Failure<T>(KernelDiagnosticCode code, string message, string source) =>+ KernelResult<T>.Failure([new KernelDiagnostic(code, KernelDiagnosticSeverity.Error, message, source)]);}diff --git a/docs/milestones.md b/docs/milestones.mdindex b4df3b94..0b9c4de5 100644--- a/docs/milestones.md+++ b/docs/milestones.md@@ -287,3 +287,12 @@- [x] Enforce strict single-solid contract (`MANIFOLD_SOLID_BREP` count must be exactly one) with deterministic diagnostics for missing/multiple roots.- [x] Normalize stable diagnostic buckets for parser/importer-topology/importer-geometry expected-fail reporting.- [x] Explicitly keep non-goals unchanged for M31: no new STEP geometry families, no assembly/product semantics, and no healing/repair support.+++## M34 — Tier1 STEP Geometry Expansion (CIRCLE + Cylinder/Cone/Sphere Surfaces)++- [x] Extend AP242 subset import decoding/mapping for `CIRCLE` edge curves with deterministic trim interval binding.+- [x] Extend AP242 subset import surface decoding/mapping for `CYLINDRICAL_SURFACE`, `CONICAL_SURFACE`, and `SPHERICAL_SURFACE`.+- [x] Preserve deterministic no-throw diagnostics for parseable failures with stable source buckets (`Importer.Geometry.Circle*`, `Importer.Geometry.Cylinder`, `Importer.Geometry.Cone`, `Importer.Geometry.Sphere`).+- [x] Add focused Tier1 importer tests covering import/validate/tessellate/pick smoke and deterministic circle-trim failure behavior.+- [x] Keep out-of-scope geometry families deterministic expected-fail (for example `TOROIDAL_SURFACE`, NURBS/spline families).