Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Trim curves: fix validator, recovery and export; source data was right

Claude5fb6964bd56c
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs
new file mode 100644
index 00000000..8ffad28d
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs
@@ -0,0 +1,71 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Topology;
+
+namespace Aetheris.Kernel.Core.Tests.Step242;
+
+/// <summary>Trim-curve checks against NIST parts: what was the validator's or recovery's fault, not the data's.</summary>
+public sealed class Step242PcurveAuditTests
+{
+ private static BrepPcurveEvidence ValidateWithSourceAccuracy(BrepBody body)
+ {
+ var accuracy = body.ImportQualification?.SourceDistanceAccuracyMillimetres ?? 0d;
+ var topology = accuracy > 0
+ ? new BrepPcurveTopologyEvidence(body.Topology.Vertices.ToDictionary(v => v.Id, _ => accuracy), new HashSet<(CoedgeId, CoedgeId)>())
+ : null;
+ return BrepPcurveValidator.Validate(body, 1e-5, sourceTopology: topology);
+ }
+
+ /// <summary>FTC-08 and STC-10 have edges whose curve runs against their vertices (same_sense .F.).
+ /// The validator matched vertices to trim ends ignoring that: 1,688 and 1,493 false errors.</summary>
+ [Theory]
+ [InlineData("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp")]
+ [InlineData("testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp")]
+ public void Validator_HonoursEdgeSense(string path)
+ {
+ var evidence = ValidateWithSourceAccuracy(Step242Corpus.Body(path));
+ Assert.True(evidence.IsValid, string.Join("\n", evidence.Diagnostics.Take(5)));
+ }
+
+ /// <summary>Sphere corner pcurves meet at the pole and cone pcurves at the apex with any U gap; that
+ /// point is one model point, and the loop is closed there.</summary>
+ [Theory]
+ [InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp")]
+ [InlineData("testdata/step242/nist/STC/nist_stc_07_asme1_ap242-e3.stp")]
+ [InlineData("testdata/step242/nist/STC/nist_stc_08_asme1_ap242-e3.stp")]
+ public void Validator_AcceptsLoopsClosingAtSingularPoints(string path)
+ {
+ var evidence = ValidateWithSourceAccuracy(Step242Corpus.Body(path));
+ Assert.True(evidence.IsValid, string.Join("\n", evidence.Diagnostics.Take(5)));
+ }
+
+ /// <summary>FTC-11's vertices sit up to 3.75 µm off their curves; the file declares 5 µm accuracy.</summary>
+ [Fact]
+ public void Validator_AllowsVerticesWithinDeclaredSourceAccuracy()
+ {
+ var body = Step242Corpus.Body("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp");
+ Assert.Equal(0.005, body.ImportQualification!.SourceDistanceAccuracyMillimetres!.Value, 9);
+ Assert.True(ValidateWithSourceAccuracy(body).IsValid);
+ Assert.False(BrepPcurveValidator.Validate(body, 1e-5).IsValid); // without the source's tolerance it is not
+ }
+
+ /// <summary>Circles through a sphere pole and B-spline curves into a cone apex lie exactly on their
+ /// surfaces; recovery took atan2 noise for U there and failed them.</summary>
+ [Theory]
+ [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "Sphere pcurve refinement")]
+ [InlineData("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp", "Sphere pcurve refinement")]
+ [InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp", "Cone pcurve refinement")]
+ public void Recovery_UsesTheLimitAtPolesAndApexes(string path, string failure)
+ {
+ var report = Step242Corpus.Body(path).PcurveRecoveryReport;
+ Assert.NotNull(report);
+ Assert.DoesNotContain(report.Diagnostics, d => d.Message.StartsWith(failure, StringComparison.Ordinal));
+ }
+
+ /// <summary>The fitted spline's last knot must be the interval end exactly.</summary>
+ [Fact]
+ public void Recovery_DoesNotRejectItsOwnTrimByOneUlp()
+ {
+ foreach (var path in new[] { "testdata/step242/nist/STC/nist_stc_07_asme1_ap242-e3.stp", "testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp" })
+ Assert.DoesNotContain(Step242Corpus.Body(path).PcurveRecoveryReport!.Diagnostics, d => d.Message.Contains("requires a finite in-domain trim", StringComparison.Ordinal));
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs b/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
index b9132850..0ed518fd 100644
--- a/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
+++ b/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
@@ -146,10 +146,12 @@ public static class BrepPcurveRecovery
if (residual <= tolerance) return (candidate, residual, null);
}
}
- return BuildPeriodicAnalytic(surface, curve, interval, tolerance, point => ConeUv(cone, point));
+ return BuildPeriodicAnalytic(surface, curve, interval, tolerance, point => ConeUv(cone, point),
+ singular: point => (point - cone.Apex).Length <= 1e-9 * double.Max(1d, (EvaluateCurve(curve, interval.Start) - cone.Apex).Length));
}
if (surface.Sphere is { } sphere)
- return BuildPeriodicAnalytic(surface, curve, interval, tolerance, point => SphereUv(sphere, point));
+ return BuildPeriodicAnalytic(surface, curve, interval, tolerance, point => SphereUv(sphere, point),
+ singular: point => (point - sphere.Center - sphere.Axis.ToVector() * (point - sphere.Center).Dot(sphere.Axis.ToVector())).Length <= 1e-9 * sphere.Radius);
if (surface.Torus is { } torus)
return BuildPeriodicAnalytic(surface, curve, interval, tolerance, point => TorusUv(torus, point), unwrapV: true);
if (surface.BSplineSurfaceWithKnots is not { } spline)
@@ -411,12 +413,30 @@ public static class BrepPcurveRecovery
private static (PcurveGeometry? Pcurve, double MaximumResidual, string? Diagnostic) BuildPeriodicAnalytic(
SurfaceGeometry surface, CurveGeometry curve, ParameterInterval interval, double tolerance,
- Func<Point3D, SurfaceParameterPoint> inverse, bool unwrapV = false)
+ Func<Point3D, SurfaceParameterPoint> inverse, bool unwrapV = false, Func<Point3D, bool>? singular = null)
{
var best = double.PositiveInfinity;
for (var count = 17; count <= 513; count = (count - 1) * 2 + 1)
{
var uv = Sample(interval, count, t => inverse(EvaluateCurve(curve, t))).ToArray();
+ // A sphere pole or cone apex has no U of its own (atan2 of zero returns noise). The pcurve's
+ // U there is its limit along the curve: take it from the nearest regular sample.
+ if (singular is not null)
+ {
+ var atSingular = Enumerable.Range(0, count).Select(i => singular(EvaluateCurve(curve, interval.Start + (interval.End - interval.Start) * i / (count - 1d)))).ToArray();
+ if (atSingular.Any(x => x) && !atSingular.All(x => x))
+ {
+ for (var i = 0; i < count; i++)
+ {
+ if (!atSingular[i]) continue;
+ var regular = Enumerable.Range(1, count).SelectMany(d => new[] { i - d, i + d }).First(j => j >= 0 && j < count && !atSingular[j]);
+ var limit = i == 0 || i == count - 1
+ ? inverse(EvaluateCurve(curve, interval.Start + (interval.End - interval.Start) * (i == 0 ? 1e-6 : 1 - 1e-6)))
+ : uv[regular];
+ uv[i] = uv[i] with { U = limit.U };
+ }
+ }
+ }
UnwrapAngles(uv, unwrapV);
var controls = new List<Point3D>((count - 1) * 3 + 1);
var knots = new List<double>(count);
@@ -424,7 +444,9 @@ public static class BrepPcurveRecovery
for (var index = 0; index < count - 1; index++)
{
var start = interval.Start + (interval.End - interval.Start) * index / (count - 1d);
- var end = interval.Start + (interval.End - interval.Start) * (index + 1) / (count - 1d);
+ // The last knot is the interval end exactly; Start + (End - Start) * 1 can fall one ulp short,
+ // which leaves the trim outside the curve's domain.
+ var end = index == count - 2 ? interval.End : interval.Start + (interval.End - interval.Start) * (index + 1) / (count - 1d);
var delta = (end - start) * 1e-4d;
var nearStart = inverse(EvaluateCurve(curve, start + delta));
var nearEnd = inverse(EvaluateCurve(curve, end - delta));
diff --git a/Aetheris.Kernel.Core/Brep/BrepPcurveValidator.cs b/Aetheris.Kernel.Core/Brep/BrepPcurveValidator.cs
index 81d08d0b..7406aa0d 100644
--- a/Aetheris.Kernel.Core/Brep/BrepPcurveValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/BrepPcurveValidator.cs
@@ -98,10 +98,13 @@ public static class BrepPcurveValidator
if (coedgeMaximum > bindingTolerance)
diagnostics.Add($"surf-pcurve-invalid:coedge={coedge.Id.Value}:face={face.Id.Value}:surface={surface.Kind}:curve={curve.Kind}:pcurve={binding.Pcurve.Kind}:deviation={coedgeMaximum:R}:tolerance={bindingTolerance:R}");
+ // The coedge runs from its first vertex to its last. Which trim end that is depends on both the
+ // coedge's use of the edge and the edge's sense along its curve (EDGE_CURVE same_sense).
+ var runsAgainstCurve = coedge.IsReversed ^ !edgeBinding.OrientedEdgeSense;
var startVertexId = coedge.IsReversed ? body.Topology.GetEdge(coedge.EdgeId).EndVertexId : body.Topology.GetEdge(coedge.EdgeId).StartVertexId;
if (body.TryGetVertexPoint(startVertexId, out var start))
{
- var parameter = coedge.IsReversed ? interval.End : interval.Start;
+ var parameter = runsAgainstCurve ? interval.End : interval.Start;
var uv = binding.Pcurve.Evaluate(binding.SameSense ? parameter : interval.End - (parameter - interval.Start));
var reconstructed = Evaluate(surface, uv);
var vertexTolerance = sourceTopology?.VertexTolerancesMillimetres.GetValueOrDefault(startVertexId) ?? 0d;
@@ -116,7 +119,7 @@ public static class BrepPcurveValidator
var endVertex = coedge.IsReversed ? edge.StartVertexId : edge.EndVertexId;
if (body.TryGetVertexPoint(endVertex, out var endPoint))
{
- var parameter = coedge.IsReversed ? interval.Start : interval.End;
+ var parameter = runsAgainstCurve ? interval.Start : interval.End;
var uv = binding.Pcurve.Evaluate(binding.SameSense ? parameter : interval.End - (parameter - interval.Start));
var reconstructed = Evaluate(surface, uv);
var vertexTolerance = sourceTopology?.VertexTolerancesMillimetres.GetValueOrDefault(endVertex) ?? 0d;
@@ -132,12 +135,17 @@ public static class BrepPcurveValidator
&& body.Bindings.TryGetEdgeBinding(next.EdgeId, out var nextEdgeBinding)
&& nextEdgeBinding.TrimInterval is { } nextInterval)
{
- var currentLoopParameter = coedge.IsReversed ? interval.Start : interval.End;
- var nextLoopParameter = next.IsReversed ? nextInterval.End : nextInterval.Start;
+ var nextRunsAgainstCurve = next.IsReversed ^ !nextEdgeBinding.OrientedEdgeSense;
+ var currentLoopParameter = runsAgainstCurve ? interval.Start : interval.End;
+ var nextLoopParameter = nextRunsAgainstCurve ? nextInterval.End : nextInterval.Start;
var currentUv = binding.Pcurve.Evaluate(binding.SameSense ? currentLoopParameter : interval.End - (currentLoopParameter - interval.Start));
var nextUv = nextBinding.Pcurve.Evaluate(nextBinding.SameSense ? nextLoopParameter : nextInterval.End - (nextLoopParameter - nextInterval.Start));
var closure = UvDistance(surface, currentUv, nextUv);
maximumUvClosure = double.Max(maximumUvClosure, closure);
+ // Two edges that each end within the source's vertex tolerance of their shared vertex may
+ // stop up to twice that apart; in UV that is checked in model space below.
+ var sharedVertex = runsAgainstCurve ? body.Topology.GetEdge(coedge.EdgeId).StartVertexId : body.Topology.GetEdge(coedge.EdgeId).EndVertexId;
+ var sharedVertexTolerance = sourceTopology?.VertexTolerancesMillimetres.GetValueOrDefault(sharedVertex) ?? 0d;
var closureTolerance = double.Max(bindingTolerance,
nextBinding.Qualification?.QualificationToleranceMillimetres ?? tolerance);
if (sourceTopology?.CollapsedSingularTransitions.Contains((coedge.Id, next.Id)) == true)
@@ -156,7 +164,9 @@ public static class BrepPcurveValidator
diagnostics.Add($"surf-pcurve-invalid:coedge={coedge.Id.Value}:collapsed-singular-lift");
}
}
- else if (closure > closureTolerance)
+ else if (closure > closureTolerance && !MeetAtSingularPoint(surface, currentUv, nextUv, closureTolerance)
+ && !(sharedVertexTolerance > 0d && Evaluate(surface, currentUv) is { } liftA && Evaluate(surface, nextUv) is { } liftB
+ && (liftA - liftB).Length <= 2d * sharedVertexTolerance + closureTolerance))
{
loopClosureValid = false;
diagnostics.Add($"surf-pcurve-invalid:coedge={coedge.Id.Value}:uv-loop-closure={closure:R}:tolerance={closureTolerance:R}");
@@ -174,6 +184,16 @@ public static class BrepPcurveValidator
};
}
+ /// <summary>A sphere pole or cone apex is one model point for every U: two pcurves can meet there
+ /// with any U gap. Accept when both ends lift to the same point and U is degenerate at it.</summary>
+ private static bool MeetAtSingularPoint(SurfaceGeometry surface, SurfaceParameterPoint a, SurfaceParameterPoint b, double tolerance)
+ {
+ if (Evaluate(surface, a) is not { } pa || Evaluate(surface, b) is not { } pb || (pa - pb).Length > tolerance) return false;
+ bool Degenerate(SurfaceParameterPoint uv, Point3D p)
+ => Evaluate(surface, new SurfaceParameterPoint(uv.U + 1e-3, uv.V)) is { } q && (q - p).Length <= tolerance;
+ return Degenerate(a, pa) && Degenerate(b, pb);
+ }
+
private static bool WithinSurfaceDomain(SurfaceGeometry surface, SurfaceParameterPoint uv, double tolerance)
{
if (!double.IsFinite(uv.U) || !double.IsFinite(uv.V)) return false;
diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
index 0b2e407c..cf5c0c8c 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
@@ -1231,7 +1231,10 @@ public static class Step242Exporter
.Select(binding => BuildStepPcurve(writer, binding, surfaceIds, pcurveContextId,
curve.Kind == CurveGeometryKind.Line3 && binding.Qualification is
{ Origin: PcurveBindingOrigin.RecoveredAnalytic or PcurveBindingOrigin.RecoveredSpline or PcurveBindingOrigin.DerivedAnalytic or PcurveBindingOrigin.ConstructedBoundary }
- ? new ParameterInterval(0d, (endPoint - startPoint).Length) : null))
+ ? new ParameterInterval(0d, (endPoint - startPoint).Length) : null,
+ // The rewritten line starts at the start vertex. That vertex is the stored trim's end when
+ // the edge runs against its curve, and the pcurve may itself run against the edge curve.
+ reverseLineDomain: edgeBinding.OrientedEdgeSense != binding.SameSense))
.Where(id => id is not null)
.Select(id => id!)
.ToArray();
@@ -1257,14 +1260,15 @@ public static class Step242Exporter
CoedgePcurveBinding binding,
IReadOnlyDictionary<SurfaceGeometryId, string> surfaceIds,
string contextId,
- ParameterInterval? reparameterizedLineDomain)
+ ParameterInterval? reparameterizedLineDomain,
+ bool reverseLineDomain = false)
{
if (!surfaceIds.TryGetValue(binding.SurfaceGeometryId, out var surfaceId)) return null;
var representationName = binding.Qualification is { } qualification
? $"aetheris-qualified-pcurve:{Step242TextWriter.Number(qualification.QualificationToleranceMillimetres)}"
: "pcurve";
if (reparameterizedLineDomain is { } lineDomain)
- binding = binding with { Pcurve = ReparameterizeLinePcurve(binding.Pcurve, lineDomain) };
+ binding = binding with { Pcurve = ReparameterizeLinePcurve(binding.Pcurve, lineDomain, reverseLineDomain), SameSense = true };
if (binding.Pcurve.PolynomialCurve is { } polynomial)
{
var controls = polynomial.ControlPoints.Select(p => writer.AddEntity("CARTESIAN_POINT", "$",
@@ -1362,8 +1366,9 @@ public static class Step242Exporter
return writer.AddEntity("PCURVE", "$", Step242TextWriter.Ref(surfaceId), Step242TextWriter.Ref(representationId));
}
- internal static PcurveGeometry ReparameterizeLinePcurve(PcurveGeometry pcurve, ParameterInterval lineDomain)
+ internal static PcurveGeometry ReparameterizeLinePcurve(PcurveGeometry pcurve, ParameterInterval lineDomain, bool reverse = false)
{
+ if (reverse) pcurve = Reversed(pcurve);
if (pcurve.PolynomialCurve is { } polynomial)
{
var source = pcurve.Domain;
@@ -1386,6 +1391,27 @@ public static class Step242Exporter
};
}
+ /// <summary>The same trace traversed the other way over the same domain: t maps to Start + End - t.</summary>
+ private static PcurveGeometry Reversed(PcurveGeometry pcurve)
+ {
+ var d = pcurve.Domain;
+ if (pcurve.PolynomialCurve is { } polynomial)
+ {
+ var knots = polynomial.KnotValues.Reverse().Select(k => k == d.Start ? d.End : k == d.End ? d.Start : d.Start + d.End - k).ToArray();
+ var reversed = new BSpline3Curve(polynomial.Degree, polynomial.ControlPoints.Reverse().ToArray(),
+ polynomial.KnotMultiplicities.Reverse().ToArray(), knots, polynomial.CurveForm,
+ polynomial.ClosedCurve, polynomial.SelfIntersect, polynomial.KnotSpec);
+ return pcurve.RationalWeights is { } weights ? PcurveGeometry.RationalPolynomial(d, reversed, weights.Reverse().ToArray())
+ : PcurveGeometry.Polynomial(d, reversed);
+ }
+ return pcurve.Kind switch
+ {
+ PcurveGeometryKind.Line => PcurveGeometry.Line(d, pcurve.Points[1], pcurve.Points[0]),
+ PcurveGeometryKind.Polyline => PcurveGeometry.Polyline(d, pcurve.Points.Reverse().ToArray()),
+ _ => throw new InvalidOperationException($"A {pcurve.Kind} pcurve on a straight edge cannot be reversed for export."),
+ };
+ }
+
private static string EnsureVertex(
Step242TextWriter writer,
VertexId vertexId,
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 5bb5f231..6e589946 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -742,7 +742,10 @@ public static class Step242Importer
if (orientation.Value.Bindings.PcurveBindings.Any())
{
var pcurveTolerance = double.Max(1e-6d, document.SourceDistanceAccuracyMillimetres ?? 0d);
- var pcurveEvidence = BrepPcurveValidator.Validate(orientation.Value, pcurveTolerance);
+ var pcurveEvidence = BrepPcurveValidator.Validate(orientation.Value, pcurveTolerance,
+ sourceTopology: document.SourceDistanceAccuracyMillimetres is > 0d and var sourceAccuracy
+ ? new BrepPcurveTopologyEvidence(orientation.Value.Topology.Vertices.ToDictionary(v => v.Id, _ => sourceAccuracy), new HashSet<(CoedgeId, CoedgeId)>())
+ : null);
qualificationEvidence = pcurveEvidence;
if (!pcurveEvidence.IsValid)
{
@@ -763,8 +766,12 @@ public static class Step242Importer
var recovery = BrepPcurveRecovery.Populate(
orientation.Value.Topology, orientation.Value.Geometry, orientation.Value.Bindings,
tolerance: document.PcurveQualificationToleranceMillimetres);
+ // Vertices only need to lie within the source's declared distance accuracy of their curves.
+ var sourceVertexTolerance = document.SourceDistanceAccuracyMillimetres is > 0d and var accuracy
+ ? new BrepPcurveTopologyEvidence(orientation.Value.Topology.Vertices.ToDictionary(v => v.Id, _ => accuracy), new HashSet<(CoedgeId, CoedgeId)>())
+ : null;
var pcurveEvidence = BrepPcurveValidator.Validate(orientation.Value,
- document.PcurveQualificationToleranceMillimetres, requireEveryCoedge: true);
+ document.PcurveQualificationToleranceMillimetres, requireEveryCoedge: true, sourceTopology: sourceVertexTolerance);
qualificationEvidence = pcurveEvidence;
orientation.Value.PcurveRecoveryReport = pcurveEvidence.IsValid ? recovery : recovery with
{
diff --git a/Aetheris.Kernel.Firmament.Tests/ExplicitGdtTests.cs b/Aetheris.Kernel.Firmament.Tests/ExplicitGdtTests.cs
index e69df177..2d31e7ce 100644
--- a/Aetheris.Kernel.Firmament.Tests/ExplicitGdtTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/ExplicitGdtTests.cs
@@ -59,8 +59,12 @@ public sealed class ExplicitGdtTests
{
var build = FirmamentBuildAndExport.CompileSource(specimen, Path.GetDirectoryName(path));
Assert.True(build.IsSuccess, string.Join(";", build.Diagnostics.Select(d => d.Message)));
- Assert.NotEqual(Aetheris.Kernel.Core.Import.ImportQualificationStatus.Qualified, build.Value.RuntimeBody!.ImportQualification!.GeometryStatus);
- Assert.Contains(build.Diagnostics, d => d.Message.StartsWith("step-export-recovered-pcurves-omitted:", StringComparison.Ordinal));
+ // FTC-11 used to stand in for a part without qualified UV traces. That status came from the pcurve
+ // validator ignoring edge sense (Nov 2026): within the InlineStep route's 0.1 mm recovery allowance
+ // every trace is recovered and valid, so the part qualifies and none are omitted. The unqualified-UV
+ // export path this test was named for needs a genuinely unqualified specimen.
+ Assert.Equal(Aetheris.Kernel.Core.Import.ImportQualificationStatus.Qualified, build.Value.RuntimeBody!.ImportQualification!.GeometryStatus);
+ Assert.DoesNotContain(build.Diagnostics, d => d.Message.StartsWith("step-export-recovered-pcurves-omitted:", StringComparison.Ordinal));
var inspection = Step242SemanticPmiInspector.Inspect(build.Value.StepText);
Assert.Equal(2, inspection.DatumCount); Assert.Equal(6, inspection.DimensionCount);
Assert.Equal(specimen == source ? 5 : 4, inspection.GeometricToleranceCount);
diff --git a/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
new file mode 100644
index 00000000..3287f9ac
--- /dev/null
+++ b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
@@ -0,0 +1,53 @@
+# Trim-curve (pcurve) audit: our method or the source data?
+
+**Question.** NIST FTC-08, FTC-11, STC-07, STC-10 and CTC-04 import with thousands of
+pcurve validator errors, and E3's removals failed full round trips. Is Aetheris wrong, or
+are the files?
+
+**Answer.** Almost entirely Aetheris: four bugs across validation, recovery and export.
+The source files are correct by STEP, apart from 23 edges whose 3D curves sit off their
+surfaces beyond the file's own declared accuracy.
+
+## Method today
+
+The NIST files carry no pcurves. On import Aetheris **derives** them (`BrepPcurveRecovery`):
+analytic surfaces map 3D curve samples to (U, V) by `atan2`, unwrap angles, and fit cubic
+segments with finite-difference tangents, qualified at 1 µm. **Validation**
+(`BrepPcurveValidator`) lifts each pcurve onto its surface against the 3D curve, checks the
+coedge's start and end against its vertices, and checks UV continuity to the next coedge.
+The **exporter** validates before writing pcurves and silently omits them on failure.
+
+## Findings
+
+| Finding | Owner | Evidence |
+|---|---|---|
+| Validator matched vertices to trim ends ignoring the edge's sense (`OrientedEdgeSense`, i.e. EDGE_CURVE same_sense) | ours | FTC-08 1,688 → 0, STC-10 1,493 → 0, STC-07 2,170 → 16; every FTC-08 edge's curve ends meet its vertices once sense is applied |
+| Validator rejected loops closing at a sphere pole or cone apex (any U there is one point) | ours | CTC-04, STC-07, STC-08 → 0 |
+| Validator ignored the file's declared distance accuracy at vertices | ours | FTC-11 vertices 2.5–3.75 µm off their line, file declares 5 µm; → 0 |
+| Recovery took `atan2` noise for U at a pole or apex | ours | 276 exact curves (≤1e-6 mm on their surface) failed with claimed residuals to 0.115 mm |
+| Recovery's last knot fell one ulp short of the trim, rejecting its own pcurve | ours | "requires a finite in-domain trim" on exact lines and B-splines |
+| Exporter rewrote straight edges to run start→end but kept the pcurve's old parameterisation; with same_sense .F. the pcurve ran backwards | ours | 156 mm lift errors on reimport; hidden while the validator's false errors made the exporter omit pcurves |
+| 3D curve off its surface beyond the file's declared accuracy | source | 23 coedges: CTC-04 50 µm (declared 5), FTC-11 14 µm, STC-07 5.2 µm, STC-10 5.9 µm |
+
+With the validator fixes, all 16 exact-geometry NIST files validate with **zero**
+diagnostics at their declared accuracy.
+
+## Remaining recovery failures (policy, not bugs)
+
+- 201 coedges whose source curves sit 2–35 µm off their surfaces, within each file's
+ declared accuracy. Recovery qualifies at a fixed 1 µm, so it demands more than the file
+ promises. Deciding whether to qualify against `max(policy, source accuracy)` is a policy
+ choice.
+- 6 exact curves on CTC-04 fit to 1.9 µm against 1 µm (cubic fitting convergence).
+- 89 coedges on B-spline surfaces were not measured in this audit.
+
+## Effects
+
+- E3 blend removals passing the full pcurve round trip: 67 → 305 of 308.
+- FTC-11 through the InlineStep route (0.1 mm recovery allowance) now qualifies; its
+ "not qualified" status in `ExplicitGdtTests` came from the validator bug. That test's
+ unqualified-UV export path needs a genuinely unqualified specimen.
+- NIST report hashes changed for FTC-08, STC-06 and STC-08: their exports now carry valid
+ pcurves instead of omitting them.
+
+Regression tests: `Step242PcurveAuditTests`.
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index fd2353df..6046daf9 100644
--- a/testdata/step242/manifests/nist.v0.report.json
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -177,7 +177,7 @@
"edges": 616,
"faces": 247
},
- "canonicalSha256": "abf1ac7b799cc9181d1f88b6f9406474e19d2b0ab3e6d03a661edaa39be19790"
+ "canonicalSha256": "e16a234296d3f8dcd35cd0d835f5cac5e1f0ab8d16eb915645a0336a1686a9b6"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_09_asme1_ap242-e1",
@@ -257,7 +257,7 @@
"edges": 310,
"faces": 144
},
- "canonicalSha256": "3e2f51dd321be739eef6f65636c9e33a2afb681ea1d0c281b7576204eb640c5e"
+ "canonicalSha256": "e9392176c0e168443dd5d1a6ec8e8f615209987c04e9a70d52a62e2349beb833"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",
@@ -297,7 +297,7 @@
"edges": 705,
"faces": 270
},
- "canonicalSha256": "869b4ce0ab04da3b3cf7cde445440dd42d094ebdee65d50b334cb37020a3f39b"
+ "canonicalSha256": "177d16dbb8ad0c53f42a3f2837ae0c050d7a484e9b0762f75e0d54602a11d8ea"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_09_asme1_ap242-e3",