Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

BUILD-PERF-M4 (pass 3): exact trim containment index; verdict-only enclosure check

Claudef339552b5ef1
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Tessellation/TrimContainmentIndexTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/TrimContainmentIndexTests.cs
new file mode 100644
index 00000000..b39a9160
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/TrimContainmentIndexTests.cs
@@ -0,0 +1,64 @@
+using Aetheris.Kernel.Core.Brep.Tessellation;
+
+namespace Aetheris.Kernel.Core.Tests.Brep.Tessellation;
+
+/// <summary>BUILD-PERF-M4: the bucketed trim containment index answers exactly like the reference loop.</summary>
+public sealed class TrimContainmentIndexTests
+{
+ public static TheoryData<string> Shapes() => new() { "rectangle", "star", "degenerate-segment", "comb" };
+
+ private static List<(double U, double V)> Polygon(string shape)
+ {
+ var points = new List<(double U, double V)>();
+ switch (shape)
+ {
+ case "rectangle":
+ // A densely sampled domain rectangle, as constructed SectionChain trims produce.
+ for (var i = 0; i < 40; i++) points.Add((i / 40d, 0d));
+ for (var i = 0; i < 40; i++) points.Add((1d, i / 40d));
+ for (var i = 40; i > 0; i--) points.Add((i / 40d, 1d));
+ for (var i = 40; i > 0; i--) points.Add((0d, i / 40d));
+ break;
+ case "star":
+ for (var i = 0; i < 64; i++)
+ {
+ var angle = 2d * double.Pi * i / 64d; var radius = i % 2 == 0 ? 1d : 0.37d;
+ points.Add((radius * double.Cos(angle), radius * double.Sin(angle)));
+ }
+ break;
+ case "degenerate-segment":
+ for (var i = 0; i < 48; i++) points.Add((double.Cos(2d * double.Pi * i / 48d), double.Sin(2d * double.Pi * i / 48d)));
+ points.Insert(10, points[10]);
+ break;
+ default:
+ for (var i = 0; i < 20; i++) { points.Add((i * 0.1, 0d)); points.Add((i * 0.1 + 0.05, 1d)); }
+ points.Add((2d, -0.5d)); points.Add((0d, -0.5d));
+ break;
+ }
+ return points;
+ }
+
+ [Theory]
+ [MemberData(nameof(Shapes))]
+ public void IndexedContainmentMatchesTheReferenceLoop(string shape)
+ {
+ var polygon = Polygon(shape);
+ var random = new Random(4242);
+ var probes = new List<(double U, double V)>();
+ // Vertices, edge midpoints, points just off edges, and random points across the bounds.
+ for (var i = 0; i < polygon.Count; i++)
+ {
+ var a = polygon[i]; var b = polygon[(i + 1) % polygon.Count];
+ probes.Add(a);
+ probes.Add(((a.U + b.U) / 2d, (a.V + b.V) / 2d));
+ foreach (var offset in new[] { 1e-10, 5e-10, 2e-9, 1e-6 })
+ probes.Add(((a.U + b.U) / 2d + offset, (a.V + b.V) / 2d - offset));
+ }
+ for (var i = 0; i < 4000; i++) probes.Add((random.NextDouble() * 3d - 1.5d, random.NextDouble() * 3d - 1.5d));
+ foreach (var probe in probes)
+ {
+ var (indexed, reference) = TrimmedSurfaceTessellator.ContainsPointBothWays(polygon, probe);
+ Assert.True(indexed == reference, $"{shape}: ({probe.U:R}, {probe.V:R}) indexed={indexed} reference={reference}");
+ }
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/TrimmedSurfaceTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/TrimmedSurfaceTessellator.cs
index e2f64aff..bb2fe619 100644
--- a/Aetheris.Kernel.Core/Brep/Tessellation/TrimmedSurfaceTessellator.cs
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/TrimmedSurfaceTessellator.cs
@@ -528,6 +528,10 @@ internal static class TrimmedSurfaceTessellator
return inside;
}
+ /// <summary>Test hook: the indexed containment answer and the reference loop's, for one point.</summary>
+ internal static (bool Indexed, bool Reference) ContainsPointBothWays(IReadOnlyList<(double U, double V)> polygon, (double U, double V) point)
+ => (PolygonIndex.Create(polygon) is { } index ? index.Contains(point) : ContainsPoint(polygon, point), ContainsPoint(polygon, point));
+
private static bool IsPointOnSegment((double U, double V) point, (double U, double V) a, (double U, double V) b)
{
var cross = ((point.U - a.U) * (b.V - a.V)) - ((point.V - a.V) * (b.U - a.U));
@@ -606,7 +610,7 @@ internal static class TrimmedSurfaceTessellator
{
var polygon = loops[i];
var bounds = ComputeBounds(polygon);
- loopData.Add(new TrimLoopData(i == outerLoopIndex, polygon, bounds));
+ loopData.Add(new TrimLoopData(i == outerLoopIndex, polygon, bounds, PolygonIndex.Create(polygon)));
}
var outer = loopData[outerLoopIndex];
@@ -654,7 +658,91 @@ internal static class TrimmedSurfaceTessellator
private readonly record struct TrimLoopData(
bool IsOuterLoop,
IReadOnlyList<(double U, double V)> Polygon,
- (double UMin, double UMax, double VMin, double VMax) Bounds);
+ (double UMin, double UMax, double VMin, double VMax) Bounds,
+ PolygonIndex? Index = null);
+
+ /// <summary>
+ /// BUILD-PERF-M4: answers <see cref="ContainsPoint(IReadOnlyList{ValueTuple{double, double}}, ValueTuple{double, double})"/>
+ /// exactly, visiting only the segments that can matter for a point. A segment can flip the
+ /// crossing parity only if the point's V lies in its V range, and can report the point "on
+ /// segment" only if the point lies within tol/length of it (|cross| = distance·length ≤ tol); every
+ /// other segment contributes nothing. Segments are bucketed by their V range widened by that
+ /// margin (×4, plus an absolute epsilon, for rounding), and a candidate is tested with the
+ /// original expressions, so the answer is identical. A zero-length segment makes every point
+ /// "on segment" in the original loop; such polygons, and polygons with non-finite coordinates,
+ /// answer the way the loop would without an index.
+ /// </summary>
+ private sealed class PolygonIndex
+ {
+ private readonly IReadOnlyList<(double U, double V)> polygon;
+ private readonly int[][] buckets;
+ private readonly double origin;
+ private readonly double width;
+ private readonly bool everyPointOnSegment;
+
+ private PolygonIndex(IReadOnlyList<(double U, double V)> polygon, int[][] buckets, double origin, double width, bool everyPointOnSegment)
+ {
+ this.polygon = polygon;
+ this.buckets = buckets;
+ this.origin = origin;
+ this.width = width;
+ this.everyPointOnSegment = everyPointOnSegment;
+ }
+
+ public static PolygonIndex? Create(IReadOnlyList<(double U, double V)> polygon)
+ {
+ var count = polygon.Count;
+ if (count < 32) return null;
+ var low = new double[count]; var high = new double[count];
+ var everyPointOnSegment = false;
+ for (var i = 0; i < count; i++)
+ {
+ var a = polygon[i]; var b = polygon[(i + 1) % count];
+ if (!double.IsFinite(a.U) || !double.IsFinite(a.V)) return null;
+ var du = b.U - a.U; var dv = b.V - a.V;
+ if (du == 0d && dv == 0d) everyPointOnSegment = true;
+ var length = double.Sqrt((du * du) + (dv * dv));
+ var margin = 4d * PointOnSegmentTolerance / double.Max(length, 1e-300) + 1e-12 * (1d + double.Abs(a.V) + double.Abs(b.V));
+ if (!double.IsFinite(margin)) margin = double.MaxValue;
+ low[i] = double.Min(a.V, b.V) - margin;
+ high[i] = double.Max(a.V, b.V) + margin;
+ }
+ var origin = low.Min(); var top = high.Max();
+ if (!double.IsFinite(origin) || !double.IsFinite(top) || top <= origin) return null;
+ var bucketCount = System.Math.Max(1, count / 4);
+ var width = (top - origin) / bucketCount;
+ if (!(width > 0d)) return null;
+ var lists = new List<int>[bucketCount];
+ for (var b = 0; b < bucketCount; b++) lists[b] = [];
+ for (var i = 0; i < count; i++)
+ for (var b = BucketOf(low[i], origin, width, bucketCount); b <= BucketOf(high[i], origin, width, bucketCount); b++) lists[b].Add(i);
+ return new(polygon, lists.Select(list => list.ToArray()).ToArray(), origin, width, everyPointOnSegment);
+ }
+
+ // Monotone in v (IEEE subtraction and division by a positive constant are), so a value inside
+ // a segment's range always falls in a bucket between its range's end buckets.
+ private static int BucketOf(double v, double origin, double width, int bucketCount) =>
+ (int)System.Math.Clamp(double.Floor((v - origin) / width), 0d, bucketCount - 1d);
+
+ private int Bucket(double v) => BucketOf(v, origin, width, buckets.Length);
+
+ public bool Contains((double U, double V) point)
+ {
+ if (everyPointOnSegment || !double.IsFinite(point.U) || !double.IsFinite(point.V)) return ContainsPoint(polygon, point);
+ var candidates = buckets[Bucket(point.V)];
+ var inside = false;
+ foreach (var i in candidates)
+ {
+ var a = polygon[i];
+ var b = polygon[(i + 1) % polygon.Count];
+ if (IsPointOnSegment(point, a, b)) return true;
+ var crosses = ((a.V > point.V) != (b.V > point.V))
+ && (point.U < (((b.U - a.U) * (point.V - a.V)) / (b.V - a.V)) + a.U);
+ if (crosses) inside = !inside;
+ }
+ return inside;
+ }
+ }
private readonly record struct UvPointCacheKey(ulong UBits, ulong VBits)
{
@@ -675,7 +763,7 @@ internal static class TrimmedSurfaceTessellator
}
metrics?.IncrementContainsPointEvaluations();
- return ContainsPoint(loop.Polygon, point);
+ return loop.Index is { } index ? index.Contains(point) : ContainsPoint(loop.Polygon, point);
}
private static bool IsWithinBounds((double UMin, double UMax, double VMin, double VMax) bounds, (double U, double V) point)
diff --git a/Aetheris.Kernel.Core/Brep/Verification/BrepMassProperties.cs b/Aetheris.Kernel.Core/Brep/Verification/BrepMassProperties.cs
index 24e91967..0814fab7 100644
--- a/Aetheris.Kernel.Core/Brep/Verification/BrepMassProperties.cs
+++ b/Aetheris.Kernel.Core/Brep/Verification/BrepMassProperties.cs
@@ -179,6 +179,38 @@ public static class BrepMassProperties
diagnostics);
}
+ /// <summary>
+ /// BUILD-PERF-M4: the closure verdict only (<see cref="BrepMassPropertiesResult.IsEnclosed"/> and
+ /// <see cref="BrepMassPropertiesResult.IsOrientationConsistent"/>), for construction checks that do
+ /// not use volume, area or centroid. Enclosure and face-sense consistency are topological; the only
+ /// geometric part of the verdict is "the enclosed volume is not degenerate" (|V| above the linear
+ /// tolerance cubed), which one coarse boundary integration answers. <see cref="Evaluate"/> integrates
+ /// at two resolutions to bound volume and centroid; the verdict differs only for a body whose
+ /// coarse and refined volumes fall on opposite sides of that degeneracy threshold. Volume fields
+ /// of the result are the coarse estimate and must not be used as measurements.
+ /// </summary>
+ public static BrepMassPropertiesResult EvaluateEnclosure(BrepBody body, BrepMassPropertiesOptions? options = null)
+ {
+ ArgumentNullException.ThrowIfNull(body);
+ var effective = options ?? BrepMassPropertiesOptions.Default;
+ var topology = ValidateTopology(body);
+ if (!topology.IsEnclosed)
+ return Unavailable(effective, topology, "Mass properties require a closed, orientable material boundary.");
+ if (TryEvaluateExactSphereCylinderSeamBody(body, effective, topology, out var exact)
+ || TryEvaluateExactVerticalLineArcPrism(body, effective, topology, out exact)
+ || TryEvaluateExactAxisAlignedBoxQuarterCylinderFillet(body, effective, topology, out exact))
+ return exact;
+ var coarse = EvaluateAtResolution(body, effective, refinement: 1);
+ if (coarse.Error is not null) return Unavailable(effective, topology, coarse.Error);
+ var tolerance = effective.LinearTolerance;
+ var orientationConsistent = topology.IsOrientationConsistent && System.Math.Abs(coarse.SignedVolume) > tolerance * tolerance * tolerance;
+ var diagnostics = new List<string>(topology.Messages) { $"Enclosure check only; coarseVolume={coarse.SignedVolume:G17} (not a measurement)." };
+ if (!orientationConsistent) diagnostics.Add("Face senses or signed enclosure orientation are inconsistent; absolute volume remains a magnitude only.");
+ return new BrepMassPropertiesResult(BrepMassPropertiesStatus.NumericalWithBound, coarse.SignedVolume, System.Math.Abs(coarse.SignedVolume),
+ coarse.SurfaceArea, null, topology.IsEnclosed, orientationConsistent, coarse.Contributions, "EnclosureCheckCoarseBoundaryIntegral",
+ null, effective, topology with { IsOrientationConsistent = orientationConsistent }, diagnostics);
+ }
+
private static BrepMassPropertiesResult Unavailable(BrepMassPropertiesOptions options, BrepMassPropertiesTopologyDiagnostics topology, string reason)
=> new(BrepMassPropertiesStatus.Unavailable, 0d, 0d, 0d, null, topology.IsEnclosed, topology.IsOrientationConsistent, [], "DeterministicTrimmedFaceTriangulationBoundaryIntegral", null, options, topology, topology.Messages.Append(reason).ToArray());
diff --git a/Aetheris.Kernel.Firmament/Materializer/HexBoltThreadComposition.cs b/Aetheris.Kernel.Firmament/Materializer/HexBoltThreadComposition.cs
index 844e1cd7..f8054b29 100644
--- a/Aetheris.Kernel.Firmament/Materializer/HexBoltThreadComposition.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/HexBoltThreadComposition.cs
@@ -42,7 +42,7 @@ internal static class HexBoltThreadComposition
var nonManifold = body.Topology.Coedges.GroupBy(x => x.EdgeId).Where(x => x.Count() != 2).ToArray();
if (nonManifold.Length != 0)
throw new InvalidOperationException($"Maker mark shell has {nonManifold.Length} non-manifold edges.");
- var mass = BrepMassProperties.Evaluate(body);
+ var mass = BrepMassProperties.EvaluateEnclosure(body);
if (!mass.IsEnclosed || !mass.IsOrientationConsistent)
throw new InvalidOperationException("Maker mark shell is not enclosed and oriented: " + string.Join(" | ", mass.Diagnostics));
var cap = patchCopy.Faces.Values.Single(face => shared.Values.All(edge =>
@@ -106,7 +106,7 @@ internal static class HexBoltThreadComposition
throw new InvalidOperationException("HexBolt thread composition failed BRep preflight: " + string.Join(" | ",
preflight.Diagnostics.Where(item => item.Severity == BrepExportPreflightSeverity.Error)
.Take(8).Select(item => item.Code + ": " + item.Message)));
- var mass = BrepMassProperties.Evaluate(body);
+ var mass = BrepMassProperties.EvaluateEnclosure(body);
if (!mass.IsEnclosed || !mass.IsOrientationConsistent)
throw new InvalidOperationException("HexBolt thread composition did not produce an enclosed, consistently oriented body: "
+ string.Join(" | ", mass.Diagnostics));
diff --git a/Aetheris.Web.Perf/build-perf-budgets.json b/Aetheris.Web.Perf/build-perf-budgets.json
index e61e9f34..93242b90 100644
--- a/Aetheris.Web.Perf/build-perf-budgets.json
+++ b/Aetheris.Web.Perf/build-perf-budgets.json
@@ -2,30 +2,30 @@
"schema": "aetheris/build-perf-budgets/m0",
"note": "Machine-independent fields always gate; *Milliseconds fields gate only with --check-time on the recorded machine.",
"recordedOn": "vm \u00B7 2 CPU \u00B7 Unix 6.18.44.114",
- "recordedCommit": "c85f61bbec71",
+ "recordedCommit": "73c2be2b40a8",
"projects": {
"bracket": {
"stepDataSha256": "c3323aa5717fbd198c6148ab082623f0f5920c42487c6dd5f398da4abd2d4170",
"meshSha256": "b0ec1fb0d1d40af0e6b13fe9fa1ddd38167ebde5f3f3fd946eeaac4ba97509f9",
"rebuildMatchesCold": true,
"cold": {
- "invokeMilliseconds": 687.1,
- "responseBytes": 29422,
- "allocatedBytes": 4874664
+ "invokeMilliseconds": 804,
+ "responseBytes": 29420,
+ "allocatedBytes": 4968608
},
"warm": {
- "invokeMilliseconds": 5,
- "responseBytes": 29142,
- "allocatedBytes": 679256
+ "invokeMilliseconds": 4.9,
+ "responseBytes": 29141,
+ "allocatedBytes": 580896
},
"noChangeRebuild": {
- "invokeMilliseconds": 4.8,
- "responseBytes": 29066,
- "allocatedBytes": 577656
+ "invokeMilliseconds": 3.5,
+ "responseBytes": 29070,
+ "allocatedBytes": 577664
},
"rootCommentEdit": {
- "invokeMilliseconds": 5,
- "responseBytes": 29101,
+ "invokeMilliseconds": 4.3,
+ "responseBytes": 29098,
"allocatedBytes": 630768
}
},
@@ -34,29 +34,29 @@
"meshSha256": "aa9262734e2c79801a33b60f318d646b7a81aebda0b2bea9c0e711b775f835a6",
"rebuildMatchesCold": true,
"cold": {
- "invokeMilliseconds": 5423.4,
- "responseBytes": 6952201,
- "allocatedBytes": 962555120
+ "invokeMilliseconds": 4847.9,
+ "responseBytes": 6951685,
+ "allocatedBytes": 698835440
},
"warm": {
- "invokeMilliseconds": 1974.9,
- "responseBytes": 6952173,
- "allocatedBytes": 885422368
+ "invokeMilliseconds": 1997,
+ "responseBytes": 6951673,
+ "allocatedBytes": 631247616
},
"noChangeRebuild": {
- "invokeMilliseconds": 1849.8,
- "responseBytes": 6952121,
- "allocatedBytes": 885176208
+ "invokeMilliseconds": 1611.8,
+ "responseBytes": 6951611,
+ "allocatedBytes": 630995008
},
"leafCommentEdit": {
- "invokeMilliseconds": 1539.7,
- "responseBytes": 6952121,
- "allocatedBytes": 882143264
+ "invokeMilliseconds": 1347.4,
+ "responseBytes": 6951612,
+ "allocatedBytes": 630797280
},
"rootCommentEdit": {
- "invokeMilliseconds": 1590.5,
- "responseBytes": 6952154,
- "allocatedBytes": 882245952
+ "invokeMilliseconds": 1049,
+ "responseBytes": 6951636,
+ "allocatedBytes": 627991888
}
},
"atlas": {
@@ -64,33 +64,33 @@
"meshSha256": "027b4e5076983ac736cad3aa72543127150ef1fd5d78d78a841842ff4afd179b",
"rebuildMatchesCold": true,
"cold": {
- "invokeMilliseconds": 4496.6,
- "responseBytes": 1771510,
- "allocatedBytes": 361823128,
+ "invokeMilliseconds": 4756.7,
+ "responseBytes": 1771496,
+ "allocatedBytes": 360284960,
"reusedDefinitions": 0
},
"warm": {
- "invokeMilliseconds": 2184.1,
- "responseBytes": 1771425,
- "allocatedBytes": 350792672,
+ "invokeMilliseconds": 1810.5,
+ "responseBytes": 1771445,
+ "allocatedBytes": 350275160,
"reusedDefinitions": 0
},
"noChangeRebuild": {
- "invokeMilliseconds": 61.1,
- "responseBytes": 1728469,
- "allocatedBytes": 25563688,
+ "invokeMilliseconds": 75.6,
+ "responseBytes": 1728477,
+ "allocatedBytes": 25538104,
"reusedDefinitions": 24
},
"leafCommentEdit": {
- "invokeMilliseconds": 146.3,
- "responseBytes": 1728487,
- "allocatedBytes": 25787352,
+ "invokeMilliseconds": 170.4,
+ "responseBytes": 1728490,
+ "allocatedBytes": 25761736,
"reusedDefinitions": 24
},
"rootCommentEdit": {
- "invokeMilliseconds": 62.5,
- "responseBytes": 1728513,
- "allocatedBytes": 25583552,
+ "invokeMilliseconds": 77.2,
+ "responseBytes": 1728511,
+ "allocatedBytes": 25516192,
"reusedDefinitions": 24
}
},
@@ -99,39 +99,39 @@
"meshSha256": "6758e0452b56318e0c7e40071cb0579f143edf2215c104e182fa9c055f59e867",
"rebuildMatchesCold": true,
"cold": {
- "invokeMilliseconds": 9816,
- "responseBytes": 9100194,
- "allocatedBytes": 1230367672,
+ "invokeMilliseconds": 11380.1,
+ "responseBytes": 9100211,
+ "allocatedBytes": 1246967784,
"reusedDefinitions": 0
},
"warm": {
- "invokeMilliseconds": 3882.5,
- "responseBytes": 9099938,
- "allocatedBytes": 1170225960,
+ "invokeMilliseconds": 3787,
+ "responseBytes": 9099966,
+ "allocatedBytes": 1191341192,
"reusedDefinitions": 0
},
"noChangeRebuild": {
- "invokeMilliseconds": 337,
- "responseBytes": 9014029,
- "allocatedBytes": 91973440,
+ "invokeMilliseconds": 261.2,
+ "responseBytes": 9014023,
+ "allocatedBytes": 91972704,
"reusedDefinitions": 56
},
"leafValueEdit": {
- "invokeMilliseconds": 349.5,
- "responseBytes": 9016050,
- "allocatedBytes": 123110832,
+ "invokeMilliseconds": 377.1,
+ "responseBytes": 9016047,
+ "allocatedBytes": 123101944,
"reusedDefinitions": 54
},
"leafCommentEdit": {
- "invokeMilliseconds": 636.6,
+ "invokeMilliseconds": 513.6,
"responseBytes": 9015234,
- "allocatedBytes": 238374320,
+ "allocatedBytes": 241161824,
"reusedDefinitions": 55
},
"rootCommentEdit": {
- "invokeMilliseconds": 250.6,
+ "invokeMilliseconds": 200.4,
"responseBytes": 9014054,
- "allocatedBytes": 91630288,
+ "allocatedBytes": 91629360,
"reusedDefinitions": 56
}
},
@@ -140,29 +140,29 @@
"meshSha256": "ce00e129709c10a86151b4bea6f000947cf1c51e0bb4a226b67aea8f3d54a15a",
"rebuildMatchesCold": true,
"cold": {
- "invokeMilliseconds": 2723.2,
- "responseBytes": 2711177,
- "allocatedBytes": 332010280
+ "invokeMilliseconds": 3457,
+ "responseBytes": 2711207,
+ "allocatedBytes": 337892440
},
"warm": {
- "invokeMilliseconds": 1488.3,
- "responseBytes": 2711090,
- "allocatedBytes": 324710896
+ "invokeMilliseconds": 1561.9,
+ "responseBytes": 2711110,
+ "allocatedBytes": 324725520
},
"noChangeRebuild": {
- "invokeMilliseconds": 163.8,
- "responseBytes": 2640585,
- "allocatedBytes": 38407000
+ "invokeMilliseconds": 148.8,
+ "responseBytes": 2640566,
+ "allocatedBytes": 38404256
},
"leafCommentEdit": {
- "invokeMilliseconds": 139,
- "responseBytes": 2640576,
- "allocatedBytes": 38410992
+ "invokeMilliseconds": 142.3,
+ "responseBytes": 2640573,
+ "allocatedBytes": 38407336
},
"rootCommentEdit": {
- "invokeMilliseconds": 162,
- "responseBytes": 2640598,
- "allocatedBytes": 38391040
+ "invokeMilliseconds": 169.8,
+ "responseBytes": 2640625,
+ "allocatedBytes": 38322960
}
}
}
diff --git a/docs/release/BUILD-PERF-M4.md b/docs/release/BUILD-PERF-M4.md
index 4b7046bc..8a5de1a7 100644
--- a/docs/release/BUILD-PERF-M4.md
+++ b/docs/release/BUILD-PERF-M4.md
@@ -70,13 +70,39 @@ second one deliberately takes the new guitar/ATLAS hashes). Full lane 4585/4585.
(guitar, all ATLAS documents) and `verify-bridge` pass. AOT browser numbers to be re-measured on the
author's machine.
+## Third pass: the two checks named at the end of pass 2
+
+6. **Reimport orientation: trim containment index (bit-exact).** Reimport resolves face orientation
+ with a signed volume from a display tessellation, and that tessellation spent most of its time
+ classifying candidate triangles against the trim loop. Each point-in-polygon test scanned every
+ segment of a densely sampled loop. A per-loop index now buckets segments by V range, widened by
+ the on-segment tolerance margin. A point visits only the segments that can flip its crossing
+ parity or report it on-segment, using the original expressions, so answers are identical
+ (`TrimContainmentIndexTests` compares both on vertices, midpoints, near-edge offsets inside and
+ outside the tolerance, and 4,000 random points, including a zero-length segment). This helps every
+ trimmed-face tessellation, display included. Reimporting CarvedMaple's tessellation halves.
+ The orientation step itself is kept. The importer's rule, that source `same_sense` is evidence and
+ never authority, still holds even for our own files.
+7. **Bolt enclosure checks (verdict-only evaluation).** `HexBoltThreadComposition` called
+ `BrepMassProperties.Evaluate` twice, which integrates the whole threaded body at two resolutions,
+ and used only `IsEnclosed` and `IsOrientationConsistent`. Both are topological, apart from a
+ "volume is not degenerate" guard. The new `BrepMassProperties.EvaluateEnclosure` computes exactly
+ the verdict: topology, the exact recognizers, and one coarse boundary integral for the
+ non-degeneracy guard. It can disagree with `Evaluate` only for a body whose coarse and refined
+ volumes straddle (linear tolerance)³; such a body is degenerate either way. Bolt root edit
+ 1.57 → 1.05 s; output hashes unchanged.
+
+Native after pass 3 (median of 3): guitar warm 3.79 s, `CarvedMaple` edit 0.51 s, bolt root edit
+1.05 s, bolt cold 4.85 s. Full lane 4589/4589; showcase hashes unchanged by pass 3; baseline rewritten.
+
## What remains, with evidence
-- **Reimport orientation check.** Reimporting our own canonical STEP still resolves face
- orientation by tessellating the body (580 of 667 ms for CarvedMaple). Like the trims, the exporter
- already knows the orientation. The next authoring-time candidate.
+- **Reimport orientation, authority question.** Skipping the orientation solve for our own
+ canonical STEP would mean trusting the source's face senses. The importer deliberately does not
+ (doctrine: source `same_sense` is cross-check evidence only). Pass 3 made the solve cheaper instead.
+ Removing it is a doctrine decision, not an optimization.
- **Other recovered trims**: analytic surfaces (cylinders, cones, tori via `BuildPeriodicAnalytic`)
and approximated ruled patches still go through recovery. They were not hot in the showcase.
-- **Bolt**: two `BrepMassProperties.Evaluate` enclosure checks (thread composition and maker-mark
- imprint, ~2.3 s together, tessellation-based) are now the bulk of every bolt rebuild.
+- **Bolt**: the rest of a rebuild is the thread/head composition and display tessellation; a single
+ part is still one definition, so any edit rebuilds it.
- **Datum-seat validation** on cold builds (guitar 1.2 s): tessellates every placed body once.