Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Tune circle trim tolerance and lock new NIST blockers

Yuechen Li7ac8246aa5eb
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs
index e3039f67..43e2b990 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs
@@ -32,7 +32,6 @@ public sealed class Step242ConicalSurfaceRegressionTests
[Theory]
[InlineData("testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp", "tessellator", "Viewer.Tessellation.CurvedTopologyUnsupported", "Face 57 curved tessellation expected mirrored line uses for this cone/revolved topology. Observed")]
- [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "importer-geometry", "Importer.Geometry.CircleTrim", "Unable to compute circle trim from supplied vertices.")]
[InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp", "importer-topology", "Importer.LoopRole.InnerBoundaryIntersectionWithOutsideVerticesAfterNormalization", "Inner loop could not be normalized")]
[InlineData("testdata/step242/nist/FTC/nist_ftc_06_asme1_ap242-e2.stp", "tessellator", "", "Face 2 curved tessellation does not support this torus/revolved boundary topology yet. Observed")]
public void Step242_NistConicalTargets_AdvancePastConicalRadius_AndReportDeterministicNextBlocker(
@@ -63,4 +62,43 @@ public sealed class Step242ConicalSurfaceRegressionTests
Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);
Assert.Equal(first.FirstDiagnostic.MessagePrefix, second.FirstDiagnostic.MessagePrefix);
}
+
+ [Theory]
+ [InlineData(
+ "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp",
+ "importer-topology",
+ "Importer.EntityFamily",
+ "ADVANCED_FACE surface 'B_SPLINE_SURFACE_WITH_KNOTS' is unsupported.")]
+ [InlineData(
+ "testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp",
+ "importer-topology",
+ "Importer.LoopRole.InnerBoundaryIntersectionWithOutsideVerticesAfterNormalization",
+ "Inner loop could not be normalized")]
+ public void Step242_NistTargets_AdvancePastCircleTrim_AndKeepDeterministicNextBlocker(
+ string relativePath,
+ string expectedLayer,
+ string expectedSource,
+ string expectedMessagePrefix)
+ {
+ var entry = new Step242CorpusManifestEntry(
+ Id: Path.GetFileNameWithoutExtension(relativePath),
+ Path: relativePath,
+ Group: "nist-circle-trim-regression",
+ Notes: "regression",
+ ExpectedFirstDiagnostic: null,
+ ExpectHashStableAfterCanonicalization: null,
+ ExpectTopologyCounts: null,
+ ExpectGeometryKinds: null);
+
+ var first = Step242CorpusManifestRunner.RunOne(entry);
+ var second = Step242CorpusManifestRunner.RunOne(entry);
+
+ Assert.Equal(expectedLayer, first.FirstFailureLayer);
+ Assert.Equal(expectedSource, first.FirstDiagnostic.Source);
+ Assert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);
+
+ Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);
+ Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);
+ Assert.Equal(first.FirstDiagnostic.MessagePrefix, second.FirstDiagnostic.MessagePrefix);
+ }
}
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs
index 08755978..f1fe5964 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242Tier1GeometryTests.cs
@@ -47,8 +47,8 @@ public sealed class Step242Tier1GeometryTests
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);
+ Assert.StartsWith("Importer.Geometry.CircleTrim", diagnostic.Source, StringComparison.Ordinal);
+ Assert.StartsWith("Unable to project circular trim point", diagnostic.Message, StringComparison.Ordinal);
}
[Fact]
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index ef059ea1..9ee977b6 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -872,7 +872,7 @@ public static class Step242Importer
private static KernelResult<ParameterInterval> ComputeCircleTrim(Circle3Curve circle, Point3D startPoint, Point3D endPoint)
{
- const double tolerance = 1e-6d;
+ var tolerance = ComputeCircleTrimTolerance(circle, startPoint, endPoint);
if ((startPoint - endPoint).Length <= tolerance)
{
return KernelResult<ParameterInterval>.Success(new ParameterInterval(0d, 2d * double.Pi));
@@ -890,19 +890,13 @@ public static class Step242Importer
return KernelResult<ParameterInterval>.Failure(endAngleResult.Diagnostics);
}
- var start = startAngleResult.Value;
- var end = endAngleResult.Value;
- if (end < start)
+ var intervalResult = CanonicalizeCircleTrimInterval(startAngleResult.Value, endAngleResult.Value, tolerance);
+ if (!intervalResult.IsSuccess)
{
- end += 2d * double.Pi;
+ return KernelResult<ParameterInterval>.Failure(intervalResult.Diagnostics);
}
- 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));
+ return KernelResult<ParameterInterval>.Success(intervalResult.Value);
}
private static KernelResult<double> ProjectPointToCircleAngle(Circle3Curve circle, Point3D point, double tolerance)
@@ -912,13 +906,24 @@ public static class Step242Importer
var inPlane = radial - (circle.Normal.ToVector() * normalComponent);
var inPlaneLength = inPlane.Length;
- if (double.Abs(normalComponent) > tolerance || double.Abs(inPlaneLength - circle.Radius) > tolerance)
+ if (double.Abs(normalComponent) > tolerance)
+ {
+ return FailureCircleTrimAngle($"Unable to project circular trim point: off-circle plane deviation {double.Abs(normalComponent):G17} exceeds tolerance {tolerance:G17}.", "Importer.Geometry.CircleTrim.OffPlane");
+ }
+
+ if (double.Abs(inPlaneLength - circle.Radius) > tolerance)
{
- return FailureCircleTrimAngle("Unable to compute circle trim from supplied vertices.", "Importer.Geometry.CircleTrim");
+ return FailureCircleTrimAngle($"Unable to project circular trim point: radial deviation {double.Abs(inPlaneLength - circle.Radius):G17} exceeds tolerance {tolerance:G17}.", "Importer.Geometry.CircleTrim.OffRadius");
}
- var x = inPlane.Dot(circle.XAxis.ToVector());
- var y = inPlane.Dot(circle.YAxis.ToVector());
+ if (inPlaneLength <= tolerance)
+ {
+ return FailureCircleTrimAngle("Unable to project circular trim point: projected in-plane radius is degenerate.", "Importer.Geometry.CircleTrim.DegeneratePoint");
+ }
+
+ var projected = inPlane * (circle.Radius / inPlaneLength);
+ var x = projected.Dot(circle.XAxis.ToVector());
+ var y = projected.Dot(circle.YAxis.ToVector());
var angle = double.Atan2(y, x);
if (angle < 0d)
{
@@ -928,6 +933,71 @@ public static class Step242Importer
return KernelResult<double>.Success(angle);
}
+ private static double ComputeCircleTrimTolerance(Circle3Curve circle, Point3D startPoint, Point3D endPoint)
+ {
+ const double baseTolerance = 1e-6d;
+ const double scaleFactor = 5e-4d;
+ var startRadius = (startPoint - circle.Center).Length;
+ var endRadius = (endPoint - circle.Center).Length;
+ var scale = double.Max(1d, double.Max(circle.Radius, double.Max(startRadius, endRadius)));
+ return double.Max(baseTolerance, scale * scaleFactor);
+ }
+
+ private static KernelResult<ParameterInterval> CanonicalizeCircleTrimInterval(double startAngle, double endAngle, double tolerance)
+ {
+ var start = NormalizeAngle(startAngle);
+ var end = NormalizeAngle(endAngle);
+ var span = NormalizePositiveAngle(end - start);
+ var angleTolerance = tolerance;
+
+ if (span <= angleTolerance)
+ {
+ return KernelResult<ParameterInterval>.Success(new ParameterInterval(0d, 2d * double.Pi));
+ }
+
+ if (span >= (2d * double.Pi) - angleTolerance)
+ {
+ return KernelResult<ParameterInterval>.Success(new ParameterInterval(0d, 2d * double.Pi));
+ }
+
+ var normalizedEnd = start + span;
+ if (normalizedEnd <= start)
+ {
+ return FailureCircleTrim("Unable to compute circle trim interval with a positive span after canonicalization.", "Importer.Geometry.CircleTrim.Interval");
+ }
+
+ return KernelResult<ParameterInterval>.Success(new ParameterInterval(start, normalizedEnd));
+ }
+
+ private static double NormalizeAngle(double angle)
+ {
+ var period = 2d * double.Pi;
+ var normalized = angle % period;
+ if (normalized < 0d)
+ {
+ normalized += period;
+ }
+
+ if (normalized >= period)
+ {
+ normalized -= period;
+ }
+
+ return normalized;
+ }
+
+ private static double NormalizePositiveAngle(double angle)
+ {
+ var period = 2d * double.Pi;
+ var normalized = angle % period;
+ if (normalized < 0d)
+ {
+ normalized += period;
+ }
+
+ return normalized;
+ }
+
private static double ComputeLineParameter(Line3Curve line, Point3D point)
{
var offset = point - line.Origin;
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index 70de17ac..76c18174 100644
--- a/testdata/step242/manifests/nist.v0.report.json
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -28,11 +28,11 @@
"path": "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp",
"sizeBytes": 1958442,
"status": "importFail",
- "firstFailureLayer": "importer-geometry",
+ "firstFailureLayer": "importer-topology",
"firstDiagnostic": {
- "code": "ValidationFailed",
- "source": "Importer.Geometry.CircleTrim",
- "messagePrefix": "Unable to compute circle trim from supplied vertices."
+ "code": "NotImplemented",
+ "source": "Importer.EntityFamily",
+ "messagePrefix": "ADVANCED_FACE surface \u0027B_SPLINE_SURFACE_WITH_KNOTS\u0027 is unsupported."
},
"diagnosticCount": 1,
"exceptionEscaped": false,
@@ -388,11 +388,11 @@
"path": "testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp",
"sizeBytes": 4807322,
"status": "importFail",
- "firstFailureLayer": "importer-geometry",
+ "firstFailureLayer": "importer-topology",
"firstDiagnostic": {
"code": "ValidationFailed",
- "source": "Importer.Geometry.CircleTrim",
- "messagePrefix": "Unable to compute circle trim from supplied vertices."
+ "source": "Importer.LoopRole.InnerBoundaryIntersectionWithOutsideVerticesAfterNormalization",
+ "messagePrefix": "Inner loop could not be normalized"
},
"diagnosticCount": 1,
"exceptionEscaped": false,