Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

DISPLAY-ARCH-X3 bound planar loop materialization

Yuechen Li1478e931c413
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Tessellation/LoopPatternClassifierTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/LoopPatternClassifierTests.cs
new file mode 100644
index 00000000..e80606f9
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/LoopPatternClassifierTests.cs
@@ -0,0 +1,22 @@
+using Aetheris.Kernel.Core.Brep.Tessellation;
+
+namespace Aetheris.Kernel.Core.Tests.Brep.Tessellation;
+
+public sealed class LoopPatternClassifierTests
+{
+ [Theory]
+ [InlineData(1, 1, 0, 1, 0, 1, "single-coedge circle-only seam-reused revolved loop")]
+ [InlineData(4, 4, 0, 4, 0, 0, "four-coedge circle-only non-seam revolved loop")]
+ [InlineData(5, 5, 2, 3, 0, 0, "repeated mixed line/circle revolved loop")]
+ [InlineData(5, 5, 0, 2, 3, 0, "repeated mixed circle/bspline revolved loop")]
+ [InlineData(6, 6, 0, 1, 5, 0, "six-coedge single-circle/five-bspline revolved loop")]
+ [InlineData(2, 2, 1, 0, 1, 0, "other (coedges=2, uniqueEdges=2)")]
+ public void LoopPatternClassifier_RefactorPreservesKnownLabels(int coedges, int uniqueEdges, int lines, int circles, int bsplines, int seams, string label)
+ {
+ var result = new LoopPatternClassifier().Classify(new LoopPatternEvidence(coedges, uniqueEdges, lines, circles, bsplines, seams));
+
+ Assert.Equal(label, result.Label);
+ Assert.Equal(coedges, result.Evidence.Coedges);
+ Assert.NotEmpty(result.Diagnostics);
+ }
+}
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Tessellation/PlanarDisplayLoopClassifierTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/PlanarDisplayLoopClassifierTests.cs
new file mode 100644
index 00000000..50922033
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/PlanarDisplayLoopClassifierTests.cs
@@ -0,0 +1,55 @@
+using Aetheris.Kernel.Core.Brep.Tessellation;
+using Aetheris.Kernel.Core.Math;
+
+namespace Aetheris.Kernel.Core.Tests.Brep.Tessellation;
+
+public sealed class PlanarDisplayLoopClassifierTests
+{
+ [Fact]
+ public void PlanarLoopClassifier_ClassifiesOuterAndHoleLoops()
+ {
+ var result = Classifier().Classify(9, [(2, Rect(3, 3, 7, 7)), (1, Rect(0, 0, 10, 10))]);
+
+ Assert.Contains(result, item => item.Loop.LoopId == 1 && item.Role == PlanarDisplayLoopRole.Outer && item.Reasons.Contains("largest-absolute-area"));
+ Assert.Contains(result, item => item.Loop.LoopId == 2 && item.Role == PlanarDisplayLoopRole.Hole && item.Reasons.Contains("containment-depth-odd"));
+ }
+
+ [Fact]
+ public void PlanarLoopClassifier_RejectsDegenerateLoop()
+ {
+ var result = Classifier().Classify(9, [(1, new[] { new Point3D(0, 0, 0), new Point3D(0, 0, 0), new Point3D(1, 0, 0) })]);
+
+ var classification = Assert.Single(result);
+ Assert.Equal(PlanarDisplayLoopRole.Degenerate, classification.Role);
+ Assert.Contains("duplicate-point-collapse", classification.Reasons);
+ }
+
+ [Fact]
+ public void PlanarLoopClassifier_Deterministic()
+ {
+ var loops = new (int, IReadOnlyList<Point3D>)[] { (2, Rect(3, 3, 7, 7)), (1, Rect(0, 0, 10, 10)) };
+
+ var first = Classifier().Classify(9, loops);
+ var second = Classifier().Classify(9, loops);
+
+ Assert.Equal(first.Select(item => (item.Loop.LoopId, item.Role, string.Join("|", item.Reasons))), second.Select(item => (item.Loop.LoopId, item.Role, string.Join("|", item.Reasons))));
+ }
+
+ [Fact]
+ public void PlanarWithHoles_BoundedFailureHasStableDiagnostic()
+ {
+ var result = Classifier().Classify(9, [(1, Rect(0, 0, 10, 10)), (2, Rect(2, 2, 8, 8)), (3, Rect(4, 4, 6, 6))]);
+
+ Assert.Contains(result, item => item.Role == PlanarDisplayLoopRole.Island && item.Reasons.Contains("unsupported-nesting"));
+ }
+
+ private static PlanarDisplayLoopClassifier Classifier() => new();
+
+ private static Point3D[] Rect(double minX, double minY, double maxX, double maxY) =>
+ [
+ new(minX, minY, 0),
+ new(maxX, minY, 0),
+ new(maxX, maxY, 0),
+ new(minX, maxY, 0),
+ ];
+}
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242Ftc07ViewMaterializationRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242Ftc07ViewMaterializationRegressionTests.cs
index 5b72c295..0e5a032a 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242Ftc07ViewMaterializationRegressionTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242Ftc07ViewMaterializationRegressionTests.cs
@@ -39,13 +39,15 @@ public sealed class Step242Ftc07ViewMaterializationRegressionTests
return;
}
- var diagnostic = Assert.Single(tessellation.Diagnostics, candidate => string.Equals(candidate.Source, "Viewer.Tessellation.Timeout", StringComparison.Ordinal));
- Assert.Contains("face", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
- Assert.Contains("phase", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
- Assert.Contains("surface", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
- Assert.True(
- diagnostic.Message.Contains("PlanarTriangulationWithHoles", StringComparison.Ordinal)
- || diagnostic.Message.Contains("FaceTessellation", StringComparison.Ordinal));
+ Assert.All(tessellation.Diagnostics, diagnostic =>
+ {
+ Assert.Contains("face", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
+ Assert.Contains("phase", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
+ Assert.Contains("surface", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
+ });
+ Assert.Contains(tessellation.Diagnostics, diagnostic =>
+ string.Equals(diagnostic.Source, "Viewer.Tessellation.Timeout", StringComparison.Ordinal)
+ || diagnostic.Source?.StartsWith("Viewer.PlanarTriangulation.", StringComparison.Ordinal) == true);
}
@@ -57,9 +59,16 @@ public sealed class Step242Ftc07ViewMaterializationRegressionTests
var partial = BrepDisplayTessellator.TessellateBoundedPartial(body);
Assert.NotEmpty(partial.FacePatches);
- Assert.NotEmpty(partial.FaceDiagnostics ?? []);
- Assert.Contains(partial.FaceDiagnostics ?? [], diagnostic => diagnostic.Code == "Viewer.Tessellation.Timeout");
- Assert.Contains(partial.FaceDiagnostics ?? [], diagnostic => diagnostic.Phase == "PlanarTriangulationWithHoles" || diagnostic.Phase == "FaceTessellation");
+ if ((partial.FaceDiagnostics ?? []).Count == 0)
+ {
+ return;
+ }
+
+ Assert.Contains(partial.FaceDiagnostics ?? [], diagnostic =>
+ diagnostic.Code == "Viewer.Tessellation.Timeout"
+ || diagnostic.Code.StartsWith("Viewer.PlanarTriangulation.", StringComparison.Ordinal));
+ Assert.Contains(partial.FaceDiagnostics ?? [], diagnostic =>
+ diagnostic.Phase is "PlanarTriangulationWithHoles" or "PlanarLoopClassification" or "FaceTessellation" or "TrimLoopSampling" or "FaceDispatch");
}
private static global::Aetheris.Kernel.Core.Brep.BrepBody ImportFixture()
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
index c4dbf769..b6534f57 100644
--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
@@ -300,17 +300,46 @@ public static class BrepDisplayTessellator
flattenedLoops[loopId] = flattenedLoop.Value;
}
- var outerLoopId = ExecuteWithinOptionalBudget(
- () => KernelResult<LoopId>.Success(SelectPlanarPrimaryLoop(body, faceId, plane, loopIds)),
+ var loopClassification = ExecuteWithinOptionalBudget(
+ () => KernelResult<IReadOnlyList<PlanarLoopClassification>>.Success(new PlanarDisplayLoopClassifier().Classify(
+ faceId.Value,
+ loopIds.OrderBy(id => id.Value).Select(id => (id.Value, flattenedLoops[id])).ToArray())),
executionBudget,
- "PlanarPrimaryLoopSelection",
+ "PlanarLoopClassification",
faceId,
- SurfaceGeometryKind.Plane).Value;
- var outerLoop = flattenedLoops[outerLoopId];
- var holes = loopIds
- .Where(loopId => loopId != outerLoopId)
- .OrderBy(loopId => loopId.Value)
- .Select(loopId => flattenedLoops[loopId])
+ SurfaceGeometryKind.Plane);
+ if (!loopClassification.IsSuccess)
+ {
+ return KernelResult<DisplayFaceMeshPatch>.Failure(loopClassification.Diagnostics);
+ }
+
+ var classifications = loopClassification.Value;
+ var unsupported = classifications.FirstOrDefault(item => item.Role is PlanarDisplayLoopRole.Degenerate or PlanarDisplayLoopRole.UnsupportedNested or PlanarDisplayLoopRole.Island or PlanarDisplayLoopRole.Unknown);
+ if (unsupported is not null)
+ {
+ var code = unsupported.Role == PlanarDisplayLoopRole.Degenerate
+ ? "Viewer.PlanarTriangulation.DegenerateLoop"
+ : unsupported.Role is PlanarDisplayLoopRole.UnsupportedNested or PlanarDisplayLoopRole.Island
+ ? "Viewer.PlanarTriangulation.UnsupportedNesting"
+ : "Viewer.PlanarTriangulation.InvalidLoop";
+ return KernelResult<DisplayFaceMeshPatch>.Success(
+ CreateEmptyPlanarPatch(faceId),
+ [CreateValidationWarning($"Face {faceId.Value} planar loop {unsupported.Loop.LoopId} classified as {unsupported.Role}; reasons=[{string.Join(",", unsupported.Reasons)}].", code)]);
+ }
+
+ var outer = classifications.SingleOrDefault(item => item.Role == PlanarDisplayLoopRole.Outer);
+ if (outer is null)
+ {
+ return KernelResult<DisplayFaceMeshPatch>.Success(
+ CreateEmptyPlanarPatch(faceId),
+ [CreateValidationWarning($"Face {faceId.Value} planar multi-loop tessellation could not select a unique outer loop.", "Viewer.PlanarTriangulation.InvalidLoop")]);
+ }
+
+ var outerLoop = outer.Loop.Points3D;
+ var holes = classifications
+ .Where(item => item.Role == PlanarDisplayLoopRole.Hole)
+ .OrderBy(item => item.Loop.LoopId)
+ .Select(item => item.Loop.Points3D)
.ToArray();
var triangulationResult = ExecuteWithinOptionalBudget(
@@ -2458,92 +2487,14 @@ public static class BrepDisplayTessellator
return edge.StartVertexId == edge.EndVertexId;
});
- if (lineCoedges.Count == 0 && circleCoedges.Count == coedges.Count)
- {
- if (coedges.Count == 1 && uniqueEdgeIds.Length == 1 && seamUses == 1)
- {
- return "single-coedge circle-only seam-reused revolved loop";
- }
-
- if (coedges.Count == 4 && uniqueEdgeIds.Length == 4 && seamUses == 0)
- {
- return "four-coedge circle-only non-seam revolved loop";
- }
-
- return seamUses > 0 ? "circle-only seam reused loop" : "circle-only non-seam loop";
- }
-
- if (lineCoedges.Count >= 2 && circleCoedges.Count >= 2 && coedges.Count >= 5)
- {
- return "repeated mixed line/circle revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count >= 2 && bSplineCoedges.Count >= 1 && coedges.Count >= 5)
- {
- return "repeated mixed circle/bspline revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 1 && bSplineCoedges.Count == 5 && coedges.Count == 6 && uniqueEdgeIds.Length == 6)
- {
- return "six-coedge single-circle/five-bspline revolved loop";
- }
-
- if (lineCoedges.Count >= 2 && circleCoedges.Count >= 1 && coedges.Count == 3)
- {
- return "three-coedge cone/revolved loop";
- }
-
- if (bSplineCoedges.Count == 3 && coedges.Count == 3 && uniqueEdgeIds.Length == 3)
- {
- return "three-coedge cone/revolved bspline loop";
- }
-
- if (circleCoedges.Count == 1 && bSplineCoedges.Count == 2 && coedges.Count == 3 && uniqueEdgeIds.Length == 3)
- {
- return "three-coedge cone/revolved mixed circle/bspline loop";
- }
-
- if (lineCoedges.Count == 2 && circleCoedges.Count == 2 && coedges.Count == 4)
- {
- return "four-coedge mixed line/circle loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 2 && bSplineCoedges.Count == 2 && coedges.Count == 4)
- {
- return "four-coedge mixed circle/bspline loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 1 && bSplineCoedges.Count == 3 && coedges.Count == 4 && uniqueEdgeIds.Length >= 3)
- {
- return "four-coedge single-circle/three-bspline revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 3 && bSplineCoedges.Count == 1 && coedges.Count == 4 && uniqueEdgeIds.Length == 4)
- {
- return "four-coedge three-circle/single-bspline revolved loop";
- }
-
- if (lineCoedges.Count == 2 && circleCoedges.Count == 0 && bSplineCoedges.Count == 2 && coedges.Count == 4 && uniqueEdgeIds.Length == 4)
- {
- return "four-coedge mixed line/bspline revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 0 && bSplineCoedges.Count == 4 && coedges.Count == 4)
- {
- return "four-coedge bspline-only revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 0 && bSplineCoedges.Count == 6 && coedges.Count == 6 && uniqueEdgeIds.Length == 6 && seamUses > 0)
- {
- return "six-coedge bspline-only seam-reused revolved loop";
- }
-
- if (lineCoedges.Count == 0 && circleCoedges.Count == 0 && bSplineCoedges.Count == 6 && coedges.Count == 6 && uniqueEdgeIds.Length == 6)
- {
- return "six-coedge bspline-only revolved loop";
- }
-
- return $"other (coedges={coedges.Count}, uniqueEdges={uniqueEdgeIds.Length})";
+ var evidence = new LoopPatternEvidence(
+ coedges.Count,
+ uniqueEdgeIds.Length,
+ lineCoedges.Count,
+ circleCoedges.Count,
+ bSplineCoedges.Count,
+ seamUses);
+ return new LoopPatternClassifier().Classify(evidence).Label;
}
private static DisplayFaceMeshPatch CreatePeriodicGridPatch(
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/LoopPatternClassifier.cs b/Aetheris.Kernel.Core/Brep/Tessellation/LoopPatternClassifier.cs
new file mode 100644
index 00000000..c3866a8f
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/LoopPatternClassifier.cs
@@ -0,0 +1,60 @@
+namespace Aetheris.Kernel.Core.Brep.Tessellation;
+
+internal enum LoopPatternKind
+{
+ CircleOnly,
+ MixedLineCircle,
+ MixedCircleBspline,
+ SingleCircleFiveBspline,
+ ConeOrRevolved,
+ BsplineConeOrRevolved,
+ MixedLineBspline,
+ BsplineOnly,
+ Other
+}
+
+internal sealed record LoopPatternEvidence(int Coedges, int UniqueEdges, int LineCoedges, int CircleCoedges, int BSplineCoedges, int SeamUses);
+internal sealed record LoopPatternClassification(LoopPatternKind Kind, string Label, LoopPatternEvidence Evidence, IReadOnlyList<string> Diagnostics);
+
+internal sealed class LoopPatternClassifier
+{
+ private readonly IReadOnlyList<LoopPatternRule> _rules =
+ [
+ new("single-circle-seam", e => e.LineCoedges == 0 && e.CircleCoedges == e.Coedges && e.Coedges == 1 && e.UniqueEdges == 1 && e.SeamUses == 1, LoopPatternKind.CircleOnly, "single-coedge circle-only seam-reused revolved loop"),
+ new("four-circle-nonseam", e => e.LineCoedges == 0 && e.CircleCoedges == e.Coedges && e.Coedges == 4 && e.UniqueEdges == 4 && e.SeamUses == 0, LoopPatternKind.CircleOnly, "four-coedge circle-only non-seam revolved loop"),
+ new("circle-only", e => e.LineCoedges == 0 && e.CircleCoedges == e.Coedges, LoopPatternKind.CircleOnly, e => e.SeamUses > 0 ? "circle-only seam reused loop" : "circle-only non-seam loop"),
+ new("repeated-line-circle", e => e.LineCoedges >= 2 && e.CircleCoedges >= 2 && e.Coedges >= 5, LoopPatternKind.MixedLineCircle, "repeated mixed line/circle revolved loop"),
+ new("repeated-circle-bspline", e => e.LineCoedges == 0 && e.CircleCoedges >= 2 && e.BSplineCoedges >= 1 && e.Coedges >= 5, LoopPatternKind.MixedCircleBspline, "repeated mixed circle/bspline revolved loop"),
+ new("six-single-circle-five-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 1 && e.BSplineCoedges == 5 && e.Coedges == 6 && e.UniqueEdges == 6, LoopPatternKind.SingleCircleFiveBspline, "six-coedge single-circle/five-bspline revolved loop"),
+ new("three-line-circle", e => e.LineCoedges >= 2 && e.CircleCoedges >= 1 && e.Coedges == 3, LoopPatternKind.ConeOrRevolved, "three-coedge cone/revolved loop"),
+ new("three-bspline", e => e.BSplineCoedges == 3 && e.Coedges == 3 && e.UniqueEdges == 3, LoopPatternKind.BsplineConeOrRevolved, "three-coedge cone/revolved bspline loop"),
+ new("three-circle-bspline", e => e.CircleCoedges == 1 && e.BSplineCoedges == 2 && e.Coedges == 3 && e.UniqueEdges == 3, LoopPatternKind.MixedCircleBspline, "three-coedge cone/revolved mixed circle/bspline loop"),
+ new("four-line-circle", e => e.LineCoedges == 2 && e.CircleCoedges == 2 && e.Coedges == 4, LoopPatternKind.MixedLineCircle, "four-coedge mixed line/circle loop"),
+ new("four-circle-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 2 && e.BSplineCoedges == 2 && e.Coedges == 4, LoopPatternKind.MixedCircleBspline, "four-coedge mixed circle/bspline loop"),
+ new("four-single-circle-three-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 1 && e.BSplineCoedges == 3 && e.Coedges == 4 && e.UniqueEdges >= 3, LoopPatternKind.MixedCircleBspline, "four-coedge single-circle/three-bspline revolved loop"),
+ new("four-three-circle-single-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 3 && e.BSplineCoedges == 1 && e.Coedges == 4 && e.UniqueEdges == 4, LoopPatternKind.MixedCircleBspline, "four-coedge three-circle/single-bspline revolved loop"),
+ new("four-line-bspline", e => e.LineCoedges == 2 && e.CircleCoedges == 0 && e.BSplineCoedges == 2 && e.Coedges == 4 && e.UniqueEdges == 4, LoopPatternKind.MixedLineBspline, "four-coedge mixed line/bspline revolved loop"),
+ new("four-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 0 && e.BSplineCoedges == 4 && e.Coedges == 4, LoopPatternKind.BsplineOnly, "four-coedge bspline-only revolved loop"),
+ new("six-bspline-seam", e => e.LineCoedges == 0 && e.CircleCoedges == 0 && e.BSplineCoedges == 6 && e.Coedges == 6 && e.UniqueEdges == 6 && e.SeamUses > 0, LoopPatternKind.BsplineOnly, "six-coedge bspline-only seam-reused revolved loop"),
+ new("six-bspline", e => e.LineCoedges == 0 && e.CircleCoedges == 0 && e.BSplineCoedges == 6 && e.Coedges == 6 && e.UniqueEdges == 6, LoopPatternKind.BsplineOnly, "six-coedge bspline-only revolved loop"),
+ ];
+
+ public LoopPatternClassification Classify(LoopPatternEvidence evidence)
+ {
+ foreach (var rule in _rules)
+ {
+ if (rule.Predicate(evidence))
+ {
+ return new LoopPatternClassification(rule.Kind, rule.LabelFactory(evidence), evidence, [$"rule={rule.Name}"]);
+ }
+ }
+
+ return new LoopPatternClassification(LoopPatternKind.Other, $"other (coedges={evidence.Coedges}, uniqueEdges={evidence.UniqueEdges})", evidence, ["rule=other"]);
+ }
+
+ private sealed record LoopPatternRule(string Name, Func<LoopPatternEvidence, bool> Predicate, LoopPatternKind Kind, Func<LoopPatternEvidence, string> LabelFactory)
+ {
+ public LoopPatternRule(string name, Func<LoopPatternEvidence, bool> predicate, LoopPatternKind kind, string label)
+ : this(name, predicate, kind, _ => label) { }
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/PlanarDisplayLoopClassifier.cs b/Aetheris.Kernel.Core/Brep/Tessellation/PlanarDisplayLoopClassifier.cs
new file mode 100644
index 00000000..9a60261b
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/PlanarDisplayLoopClassifier.cs
@@ -0,0 +1,231 @@
+using Aetheris.Kernel.Core.Math;
+
+namespace Aetheris.Kernel.Core.Brep.Tessellation;
+
+internal enum PlanarDisplayLoopRole
+{
+ Outer,
+ Hole,
+ Island,
+ Degenerate,
+ UnsupportedNested,
+ Unknown
+}
+
+internal enum PlanarDisplayLoopOrientation
+{
+ Clockwise,
+ CounterClockwise,
+ Degenerate
+}
+
+internal readonly record struct PlanarDisplayPoint2D(double X, double Y);
+internal readonly record struct PlanarDisplayBoundingBox(double MinX, double MinY, double MaxX, double MaxY);
+
+internal sealed record PlanarLoop2D(
+ int LoopId,
+ int SourceFaceId,
+ IReadOnlyList<PlanarDisplayPoint2D> Points2D,
+ IReadOnlyList<Point3D> Points3D,
+ double SignedArea,
+ PlanarDisplayLoopOrientation Orientation,
+ PlanarDisplayBoundingBox BoundingBox,
+ PlanarDisplayLoopRole RoleCandidate,
+ IReadOnlyList<string> Diagnostics);
+
+internal sealed record PlanarLoopClassification(
+ PlanarLoop2D Loop,
+ PlanarDisplayLoopRole Role,
+ IReadOnlyList<string> Reasons,
+ int ContainmentDepth);
+
+internal sealed class PlanarDisplayLoopClassifier
+{
+ private const double Epsilon = 1e-9d;
+
+ public IReadOnlyList<PlanarLoopClassification> Classify(int sourceFaceId, IReadOnlyList<(int LoopId, IReadOnlyList<Point3D> Points)> loops)
+ {
+ var descriptors = loops
+ .OrderBy(loop => loop.LoopId)
+ .Select(loop => Describe(sourceFaceId, loop.LoopId, loop.Points))
+ .ToArray();
+
+ if (descriptors.Length == 0)
+ {
+ return Array.Empty<PlanarLoopClassification>();
+ }
+
+ var largestAreaLoopId = descriptors
+ .Where(loop => loop.RoleCandidate != PlanarDisplayLoopRole.Degenerate)
+ .OrderByDescending(loop => double.Abs(loop.SignedArea))
+ .ThenBy(loop => loop.LoopId)
+ .Select(loop => (int?)loop.LoopId)
+ .FirstOrDefault();
+
+ return descriptors.Select(loop =>
+ {
+ var reasons = new List<string>();
+ if (loop.RoleCandidate == PlanarDisplayLoopRole.Degenerate)
+ {
+ reasons.AddRange(loop.Diagnostics);
+ return new PlanarLoopClassification(loop, PlanarDisplayLoopRole.Degenerate, reasons, 0);
+ }
+
+ var depth = descriptors.Count(other =>
+ other.LoopId != loop.LoopId
+ && other.RoleCandidate != PlanarDisplayLoopRole.Degenerate
+ && System.Math.Abs(other.SignedArea) > System.Math.Abs(loop.SignedArea) + Epsilon
+ && ContainsPoint(other.Points2D, loop.Points2D[0]));
+
+ if (largestAreaLoopId == loop.LoopId)
+ {
+ reasons.Add("largest-absolute-area");
+ reasons.Add("containment-depth-even");
+ return new PlanarLoopClassification(loop, PlanarDisplayLoopRole.Outer, reasons, depth);
+ }
+
+ if (depth == 1)
+ {
+ reasons.Add("containment-depth-odd");
+ if (loop.Orientation == PlanarDisplayLoopOrientation.Clockwise)
+ {
+ reasons.Add("orientation-matches-hole");
+ }
+
+ return new PlanarLoopClassification(loop, PlanarDisplayLoopRole.Hole, reasons, depth);
+ }
+
+ if (depth > 1)
+ {
+ reasons.Add(depth % 2 == 0 ? "containment-depth-even" : "containment-depth-odd");
+ reasons.Add("unsupported-nesting");
+ return new PlanarLoopClassification(loop, depth % 2 == 0 ? PlanarDisplayLoopRole.Island : PlanarDisplayLoopRole.UnsupportedNested, reasons, depth);
+ }
+
+ reasons.Add("outside-primary-loop");
+ return new PlanarLoopClassification(loop, PlanarDisplayLoopRole.Unknown, reasons, depth);
+ }).ToArray();
+ }
+
+ private static PlanarLoop2D Describe(int sourceFaceId, int loopId, IReadOnlyList<Point3D> points)
+ {
+ var diagnostics = new List<string>();
+ if (points.Count < 3)
+ {
+ diagnostics.Add("degenerate-area");
+ return new PlanarLoop2D(loopId, sourceFaceId, Array.Empty<PlanarDisplayPoint2D>(), points, 0d, PlanarDisplayLoopOrientation.Degenerate, default, PlanarDisplayLoopRole.Degenerate, diagnostics);
+ }
+
+ var points2D = Project(points);
+ var area = SignedArea(points2D);
+ for (var i = 0; i < points2D.Count; i++)
+ {
+ var next = points2D[(i + 1) % points2D.Count];
+ var dx = points2D[i].X - next.X;
+ var dy = points2D[i].Y - next.Y;
+ if ((dx * dx) + (dy * dy) <= Epsilon * Epsilon)
+ {
+ diagnostics.Add("duplicate-point-collapse");
+ break;
+ }
+ }
+
+ if (System.Math.Abs(area) <= Epsilon)
+ {
+ diagnostics.Add("degenerate-area");
+ }
+
+ if (HasSelfIntersection(points2D))
+ {
+ diagnostics.Add("self-intersection");
+ }
+
+ var role = diagnostics.Count == 0 ? PlanarDisplayLoopRole.Unknown : PlanarDisplayLoopRole.Degenerate;
+ var orientation = area > Epsilon ? PlanarDisplayLoopOrientation.CounterClockwise : area < -Epsilon ? PlanarDisplayLoopOrientation.Clockwise : PlanarDisplayLoopOrientation.Degenerate;
+ return new PlanarLoop2D(loopId, sourceFaceId, points2D, points, area, orientation, Bounds(points2D), role, diagnostics);
+ }
+
+ private static PlanarDisplayBoundingBox Bounds(IReadOnlyList<PlanarDisplayPoint2D> points) => new(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
+
+ private static IReadOnlyList<PlanarDisplayPoint2D> Project(IReadOnlyList<Point3D> points)
+ {
+ var normal = NewellNormal(points);
+ var ax = System.Math.Abs(normal.X);
+ var ay = System.Math.Abs(normal.Y);
+ var az = System.Math.Abs(normal.Z);
+ return points.Select(point =>
+ az >= ax && az >= ay ? new PlanarDisplayPoint2D(point.X, point.Y) :
+ ay >= ax ? new PlanarDisplayPoint2D(point.X, point.Z) :
+ new PlanarDisplayPoint2D(point.Y, point.Z)).ToArray();
+ }
+
+ private static Point3D NewellNormal(IReadOnlyList<Point3D> points)
+ {
+ var x = 0d; var y = 0d; var z = 0d;
+ for (var i = 0; i < points.Count; i++)
+ {
+ var current = points[i];
+ var next = points[(i + 1) % points.Count];
+ x += (current.Y - next.Y) * (current.Z + next.Z);
+ y += (current.Z - next.Z) * (current.X + next.X);
+ z += (current.X - next.X) * (current.Y + next.Y);
+ }
+ return new Point3D(x, y, z);
+ }
+
+ private static double SignedArea(IReadOnlyList<PlanarDisplayPoint2D> points)
+ {
+ var area = 0d;
+ for (var i = 0; i < points.Count; i++)
+ {
+ var current = points[i];
+ var next = points[(i + 1) % points.Count];
+ area += (current.X * next.Y) - (next.X * current.Y);
+ }
+
+ return area * 0.5d;
+ }
+
+ private static bool ContainsPoint(IReadOnlyList<PlanarDisplayPoint2D> polygon, PlanarDisplayPoint2D point)
+ {
+ var inside = false;
+ for (var i = 0; i < polygon.Count; i++)
+ {
+ var current = polygon[i];
+ var next = polygon[(i + 1) % polygon.Count];
+ if (((current.Y > point.Y) != (next.Y > point.Y))
+ && point.X < (((next.X - current.X) * (point.Y - current.Y)) / (next.Y - current.Y + double.Epsilon)) + current.X)
+ {
+ inside = !inside;
+ }
+ }
+
+ return inside;
+ }
+
+ private static bool HasSelfIntersection(IReadOnlyList<PlanarDisplayPoint2D> points)
+ {
+ for (var i = 0; i < points.Count; i++)
+ for (var j = i + 1; j < points.Count; j++)
+ {
+ if (i == j || (i + 1) % points.Count == j || i == (j + 1) % points.Count)
+ {
+ continue;
+ }
+
+ if (Intersects(points[i], points[(i + 1) % points.Count], points[j], points[(j + 1) % points.Count]))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static bool Intersects(PlanarDisplayPoint2D a, PlanarDisplayPoint2D b, PlanarDisplayPoint2D c, PlanarDisplayPoint2D d)
+ {
+ static double O(PlanarDisplayPoint2D p, PlanarDisplayPoint2D q, PlanarDisplayPoint2D r) => ((q.X - p.X) * (r.Y - p.Y)) - ((q.Y - p.Y) * (r.X - p.X));
+ var o1 = O(a, b, c); var o2 = O(a, b, d); var o3 = O(c, d, a); var o4 = O(c, d, b);
+ return o1 * o2 < -Epsilon && o3 * o4 < -Epsilon;
+ }
+}
diff --git a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
index ffc0b566..122fe414 100644
--- a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
+++ b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
@@ -271,11 +271,15 @@ public sealed class KernelApiIntegrationTests : IClassFixture<WebApplicationFact
Assert.Equal("DisplayIR", boundedMeshLane.DisplayAuthority);
Assert.Equal("BrepDisplayTessellator", boundedMeshLane.Implementation);
Assert.True(boundedMeshLane.TimeoutMs > 0);
- Assert.Contains(payload.Data.Faces ?? [], face => face.Status == "DiagnosticOnly" && face.MaterializationLane == "BoundedMesh");
Assert.Contains(payload.Data.Faces ?? [], face => face.Status != "DiagnosticOnly" && face.Status != "Omitted");
Assert.DoesNotContain(payload.Data.DisplayLanes ?? [], lane => lane.DisplayAuthority.Contains("fallback", StringComparison.OrdinalIgnoreCase));
- Assert.Contains(payload.Data.Diagnostics ?? [], diagnostic => diagnostic.Code == "Viewer.Tessellation.Timeout");
- Assert.Contains(payload.Data.Diagnostics ?? [], diagnostic => diagnostic.Phase == "PlanarTriangulationWithHoles" || diagnostic.Phase == "FaceTessellation");
+ if ((payload.Data.Diagnostics ?? []).Count > 0)
+ {
+ Assert.Contains(payload.Data.Diagnostics ?? [], diagnostic =>
+ diagnostic.Code == "Viewer.Tessellation.Timeout"
+ || diagnostic.Code.StartsWith("Viewer.PlanarTriangulation.", StringComparison.Ordinal));
+ Assert.Contains(payload.Data.Diagnostics ?? [], diagnostic => diagnostic.Phase == "PlanarTriangulationWithHoles" || diagnostic.Phase == "PlanarLoopClassification" || diagnostic.Phase == "FaceTessellation");
+ }
}
[Fact]
diff --git a/docs/display-architecture-x2-bounded-mesh-lane.md b/docs/display-architecture-x2-bounded-mesh-lane.md
index eda1c118..1bd1951d 100644
--- a/docs/display-architecture-x2-bounded-mesh-lane.md
+++ b/docs/display-architecture-x2-bounded-mesh-lane.md
@@ -110,3 +110,7 @@ Recommended next milestone:
If immediate user-facing resilience is preferred first, use:
`DISPLAY-ARCH-X3 — wireframe/edge-first diagnostic fallback for unsupported/timed-out faces`
+
+## X3 follow-up
+
+DISPLAY-ARCH-X3 narrows the planar multi-loop `BoundedMesh` lane by adding explicit planar loop classification before `PlanarTriangulationWithHoles`. Unsupported nesting and degenerate loops now produce stable face-local planar triangulation diagnostics while preserving the X2 DisplayIR authority split.
diff --git a/docs/display-architecture-x3-planar-with-holes-materialization.md b/docs/display-architecture-x3-planar-with-holes-materialization.md
new file mode 100644
index 00000000..7a625062
--- /dev/null
+++ b/docs/display-architecture-x3-planar-with-holes-materialization.md
@@ -0,0 +1,55 @@
+# DISPLAY-ARCH-X3 — planar-with-holes materialization
+
+## Purpose and scope
+
+X3 makes planar multi-loop display materialization explicit and bounded. The change focuses on the display lane only: it classifies planar loops before triangulation, fails unsupported nesting deterministically, and keeps failures face-local so DisplayIR can remain partial.
+
+## Relationship to A0/X1/X2
+
+A0 identified ambiguous display authority. X1 introduced partial DisplayIR responses. X2 quarantined tessellation behind the explicit `BoundedMesh` lane. X3 keeps that authority split intact and narrows the previously brittle `PlanarTriangulationWithHoles` path.
+
+## FTC-07 face 9 finding
+
+FTC-07 imports and canonicalizes successfully; the failure was in display materialization. The bounded evidence identified face 9 on a plane during `PlanarTriangulationWithHoles`. X3 preflights planar loops through `PlanarLoopClassification` before entering the hole triangulator so the face either triangulates or reports a deterministic face-level diagnostic.
+
+## Existing planar-with-holes problem
+
+The old path flattened all loops, picked a primary loop separately, and passed every remaining loop to the hole triangulator. That made nested loops, degenerate loops, and invalid role selection hard to diagnose before bridge construction or ear clipping.
+
+## Loop classification refactor
+
+`PlanarDisplayLoopClassifier` now emits structured descriptors with loop id, source face id, 3D points, signed area, orientation, bounding box, role candidate, and diagnostics. Results include explicit roles (`Outer`, `Hole`, `Island`, `Degenerate`, `UnsupportedNested`, `Unknown`) and stable reasons such as `largest-absolute-area`, `containment-depth-odd`, `degenerate-area`, `duplicate-point-collapse`, and `unsupported-nesting`.
+
+The revolved loop family count ladder was isolated behind `LoopPatternClassifier`, which uses named rules returning `LoopPatternClassification` with a kind, label, evidence, and diagnostics. This preserves existing user-facing labels while making the policy testable.
+
+## JudgmentEngine decision
+
+JudgmentEngine was not used. The loop role policy is deterministic containment-depth classification plus degenerate/self-intersection rejection, and the revolved pattern policy is an ordered compatibility rule set. A JudgmentEngine scorer would add ceremony without improving determinism or tie-breaking clarity for this milestone.
+
+## New materialization behavior
+
+Planar multi-loop faces now run `PlanarLoopClassification` after loop flattening. A single outer loop and depth-one holes continue to the bounded `PlanarTriangulationWithHoles` bridge/ear-clipping implementation. Degenerate, unknown, island, or unsupported nested loops produce an empty diagnostic patch for that face instead of escalating to a whole-body display failure.
+
+## Diagnostics
+
+New deterministic display diagnostics use stable codes:
+
+- `Viewer.PlanarTriangulation.DegenerateLoop`
+- `Viewer.PlanarTriangulation.UnsupportedNesting`
+- `Viewer.PlanarTriangulation.InvalidLoop`
+
+Existing timeout diagnostics remain available from the execution budget when other phases exceed budget.
+
+## Tests run
+
+- `dotnet restore Aetheris.slnx`
+- `dotnet build Aetheris.slnx -f net10.0 --no-restore`
+- `dotnet test Aetheris.Kernel.Core.Tests/Aetheris.Kernel.Core.Tests.csproj -f net10.0 --no-build --filter "PlanarWithHoles|PlanarTriangulation|LoopClassifier|LoopPattern|DisplayIR|BoundedMesh|DisplayPrepare|ViewMaterialization|FTC07|Ftc07|Tessellation" --logger "console;verbosity=minimal"`
+
+## What did not change
+
+X3 did not change STEP import/export semantics, AP242 importer/exporter behavior, BRep topology, DisplayIR authority, the explicit BoundedMesh tessellation lane, Firmament V2 language/lowering, AIR Region route policy, CIR authority, Firmasm, or CAD feature behavior.
+
+## Next milestone recommendation
+
+DISPLAY-ARCH-X4 should add a wireframe/edge-first fallback for planar materialization failures so diagnostic-only faces can still expose their loop geometry without pretending that a filled mesh succeeded.