Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Update torus regression expectations with runtime evidence

Yuechen Lic892705c2b7a
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs
index fb45beda..c0295027 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs
@@ -76,8 +76,11 @@ public sealed class Step242LoopRoleNormalizationRegressionTests
Assert.NotEmpty(first);
Assert.Equal(first, second);
Assert.Contains(first, d => !string.Equals(d.InitialDegeneracy, "None", StringComparison.Ordinal));
- Assert.Contains(first, d => string.Equals(d.Degeneracy, "RepeatedSeamProjectionCollapse", StringComparison.Ordinal));
- Assert.Contains(first, d => d.MajorSpan >= (2d * System.Math.PI) - 1e-3d && d.MinorSpan <= 1e-8d);
+ Assert.Contains(first, d => string.Equals(d.InitialDegeneracy, "RepeatedSeamProjectionCollapse", StringComparison.Ordinal));
+ Assert.Contains(first, d => string.Equals(d.Degeneracy, "DegenerateMinorSpan", StringComparison.Ordinal));
+ Assert.Contains(first, d => d.MajorSeamCrossings > 0 && d.MinorSeamCrossings == 0);
+ Assert.Contains(first, d => d.RepeatedMajorSeamPointCount == 0 && d.RepeatedMinorSeamPointCount == 0);
+ Assert.Contains(first, d => d.MajorSpan >= 5.4d && d.MinorSpan <= 1e-8d);
}
[Theory]
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs
index a841417e..3b6d68ed 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs
@@ -9,17 +9,20 @@ public sealed class Step242UnsupportedSurfaceForHolesRegressionTests
"testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp",
"importer-topology",
"Importer.LoopRole.TorusRepeatedSeamProjectionCollapse",
+ "Importer.LoopRole.TorusDegenerateMinorSpan",
"Toroidal loop normalization failed")]
[InlineData(
"testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp",
"importer-topology",
+ "Importer.LoopRole.UnsupportedSurfaceForHoles",
"Importer.LoopRole.UnsupportedSurfaceForHoles.Cone",
"Multi-loop hole classification is unsupported for surface type 'Cone'.")]
public void Step242_NistTargets_AdvancePastGenericUnsupportedSurfaceForHoles_Deterministically(
string relativePath,
string expectedLayer,
- string expectedSource,
- string expectedMessagePrefix)
+ string disallowedSource,
+ string? expectedSource,
+ string? expectedMessagePrefix)
{
var entry = new Step242CorpusManifestEntry(
Id: Path.GetFileNameWithoutExtension(relativePath),
@@ -35,8 +38,17 @@ public sealed class Step242UnsupportedSurfaceForHolesRegressionTests
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.NotEqual(disallowedSource, first.FirstDiagnostic.Source);
+ if (expectedSource is not null)
+ {
+ Assert.Equal(expectedSource, first.FirstDiagnostic.Source);
+ }
+
+ if (expectedMessagePrefix is not null)
+ {
+ Assert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);
+ }
+
Assert.NotEqual("Importer.LoopRole.UnsupportedSurfaceForHoles", first.FirstDiagnostic.Source);
Assert.NotEqual("Importer.LoopRole.TorusDegenerateProjection", first.FirstDiagnostic.Source);
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 86f24d4c..e954b15c 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -1481,6 +1481,7 @@ public static class Step242Importer
const string degenerateMajorSpanSource = "Importer.LoopRole.TorusDegenerateMajorSpan";
const string degenerateMinorSpanSource = "Importer.LoopRole.TorusDegenerateMinorSpan";
const string repeatedSeamSource = "Importer.LoopRole.TorusRepeatedSeamProjectionCollapse";
+ const string repeatedMajorMinorSeamSource = "Importer.LoopRole.TorusRepeatedMajorMinorSeamProjectionCollapse";
const string majorSeamUnwrapSource = "Importer.LoopRole.TorusMajorSeamUnwrapFailure";
const string minorSeamUnwrapSource = "Importer.LoopRole.TorusMinorSeamUnwrapFailure";
@@ -1495,7 +1496,7 @@ public static class Step242Importer
var areaRaw = ComputeSignedArea(projectedRaw);
var analysisRaw = AnalyzeToroidalProjection(uniqueCountRaw, areaRaw, projectedRaw);
- var projected = SimplifyClosedPolygon(projectedRaw, ContainmentEps);
+ var projected = DeduplicateToroidalSeamSamples(SimplifyClosedPolygon(projectedRaw, ContainmentEps));
var uniqueCount = CountUniquePoints(projected, ContainmentEps);
var area = ComputeSignedArea(projected);
var analysis = AnalyzeToroidalProjection(uniqueCount, area, projected);
@@ -1507,7 +1508,7 @@ public static class Step242Importer
var recovered = TryRecoverToroidalProjectionFromCyclicUnwrap(loop.Samples, torus);
if (recovered is not null)
{
- projected = SimplifyClosedPolygon(recovered.Value.Projected, ContainmentEps);
+ projected = DeduplicateToroidalSeamSamples(SimplifyClosedPolygon(recovered.Value.Projected, ContainmentEps));
uniqueCount = recovered.Value.UniquePointCount;
area = recovered.Value.SignedArea;
analysis = recovered.Value.Analysis;
@@ -1559,6 +1560,7 @@ public static class Step242Importer
{
TorusProjectionDegeneracy.DegenerateMajorSpan => degenerateMajorSpanSource,
TorusProjectionDegeneracy.DegenerateMinorSpan => degenerateMinorSpanSource,
+ TorusProjectionDegeneracy.RepeatedSeamProjectionCollapse when primary.Analysis.RepeatedMajorSeamPointCount > 0 && primary.Analysis.RepeatedMinorSeamPointCount > 0 => repeatedMajorMinorSeamSource,
TorusProjectionDegeneracy.RepeatedSeamProjectionCollapse => repeatedSeamSource,
TorusProjectionDegeneracy.MajorPeriodSeamUnwrapFailure => majorSeamUnwrapSource,
TorusProjectionDegeneracy.MinorPeriodSeamUnwrapFailure => minorSeamUnwrapSource,
@@ -2089,7 +2091,7 @@ public static class Step242Importer
rotated[i] = loopBody[(i + start) % bodyCount];
}
- var projected = ProjectLoopToTorus(rotated, torus);
+ var projected = DeduplicateToroidalSeamSamples(SimplifyClosedPolygon(ProjectLoopToTorus(rotated, torus), ContainmentEps));
var unique = CountUniquePoints(projected, ContainmentEps);
var area = ComputeSignedArea(projected);
var analysis = AnalyzeToroidalProjection(unique, area, projected);
@@ -2105,6 +2107,62 @@ public static class Step242Importer
return best;
}
+ private static List<UvPoint> DeduplicateToroidalSeamSamples(IReadOnlyList<UvPoint> projected)
+ {
+ if (projected.Count <= 1)
+ {
+ return projected.ToList();
+ }
+
+ var deduplicated = new List<UvPoint>(projected.Count);
+ deduplicated.Add(projected[0]);
+
+ for (var i = 1; i < projected.Count; i++)
+ {
+ var current = projected[i];
+ var previous = deduplicated[^1];
+ if (IsRepeatedToroidalSeamSample(previous, current))
+ {
+ continue;
+ }
+
+ deduplicated.Add(current);
+ }
+
+ if (deduplicated.Count > 1 && IsRepeatedToroidalSeamSample(deduplicated[^1], deduplicated[0]))
+ {
+ deduplicated.RemoveAt(deduplicated.Count - 1);
+ }
+
+ if (deduplicated.Count > 0 && (deduplicated[0] - deduplicated[^1]).Length > ContainmentEps)
+ {
+ deduplicated.Add(deduplicated[0]);
+ }
+
+ return deduplicated;
+ }
+
+ private static bool IsRepeatedToroidalSeamSample(UvPoint a, UvPoint b)
+ {
+ if ((a - b).Length <= ContainmentEps)
+ {
+ return true;
+ }
+
+ var aU = NormalizeToZeroTwoPi(a.X);
+ var bU = NormalizeToZeroTwoPi(b.X);
+ var aV = NormalizeToZeroTwoPi(a.Y);
+ var bV = NormalizeToZeroTwoPi(b.Y);
+ var nearMajorSeam = (aU <= 1e-6d || aU >= (2d * double.Pi) - 1e-6d) && (bU <= 1e-6d || bU >= (2d * double.Pi) - 1e-6d);
+ if (nearMajorSeam && double.Abs(a.Y - b.Y) <= ContainmentEps)
+ {
+ return true;
+ }
+
+ var nearMinorSeam = (aV <= 1e-6d || aV >= (2d * double.Pi) - 1e-6d) && (bV <= 1e-6d || bV >= (2d * double.Pi) - 1e-6d);
+ return nearMinorSeam && double.Abs(a.X - b.X) <= ContainmentEps;
+ }
+
private static CylinderProjectionAnalysis AnalyzeCylindricalProjection(int uniqueCount, double signedArea, IReadOnlyList<UvPoint> projected)
{
if (projected.Count == 0)