Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Tolerant edges: measure, record, don't repair

Claudec692426e3419
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepThroughHoleRevisionTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepThroughHoleRevisionTests.cs
index e8f457b3..39c1aa40 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepThroughHoleRevisionTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepThroughHoleRevisionTests.cs
@@ -82,7 +82,10 @@ public sealed class BrepThroughHoleRevisionTests
Assert.Equal(ImportQualificationStatus.Qualified, source.ImportQualification!.GeometryStatus);
Assert.Equal(636, source.Bindings.PcurveBindings.Count());
Assert.True(BrepPcurveValidator.Validate(source, .01, requireEveryCoedge: true, samples: 1025).IsValid);
- Assert.True(strict.ImportQualification!.MissingPcurves > 0);
+ // The default import now keeps edges whose curve lies off its surface within the declared accuracy as
+ // tolerant edges (measured, recorded, not repaired), so it no longer leaves trims missing.
+ Assert.Equal(0, strict.ImportQualification!.MissingPcurves);
+ Assert.Contains(strict.Bindings.PcurveBindings, b => b.Qualification?.RecoveryMethod.StartsWith(BrepPcurveRecovery.SourceTolerantMethod, StringComparison.Ordinal) == true);
Assert.Equal(JsonSerializer.Serialize(strict.Geometry.Curves), JsonSerializer.Serialize(source.Geometry.Curves));
Assert.Equal(JsonSerializer.Serialize(strict.Geometry.Surfaces), JsonSerializer.Serialize(source.Geometry.Surfaces));
var rejected = BrepThroughHoleRevision.Execute(source, Request with { ImportToleranceMillimetres = .001 });
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs
index 8ffad28d..081d7e2e 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAuditTests.cs
@@ -1,4 +1,5 @@
using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Step242;
using Aetheris.Kernel.Core.Topology;
namespace Aetheris.Kernel.Core.Tests.Step242;
@@ -69,3 +70,51 @@ public sealed class Step242PcurveAuditTests
Assert.DoesNotContain(Step242Corpus.Body(path).PcurveRecoveryReport!.Diagnostics, d => d.Message.Contains("requires a finite in-domain trim", StringComparison.Ordinal));
}
}
+
+/// <summary>Tolerant edges: an imported edge whose curve lies off its surface within the file's declared
+/// accuracy keeps its pcurve at its measured gap; nothing is repaired, and exports declare the gap.</summary>
+public sealed class Step242TolerantEdgeTests
+{
+ private static Aetheris.Kernel.Core.Brep.CoedgePcurveBinding[] Tolerant(Aetheris.Kernel.Core.Brep.BrepBody body) => body.Bindings.PcurveBindings
+ .Where(b => b.Qualification?.RecoveryMethod.StartsWith(BrepPcurveRecovery.SourceTolerantMethod, StringComparison.Ordinal) == true).ToArray();
+
+ [Theory]
+ [InlineData("testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp", 28)]
+ [InlineData("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp", 52)]
+ public void GapsWithinDeclaredAccuracy_Qualify_AtTheirMeasuredGap(string path, int expected)
+ {
+ var body = Step242Corpus.Body(path);
+ var tolerant = Tolerant(body);
+ Assert.Equal(expected, tolerant.Length);
+ var accuracy = body.ImportQualification!.SourceDistanceAccuracyMillimetres!.Value;
+ Assert.All(tolerant, b =>
+ {
+ Assert.True(b.Qualification!.MaximumLiftDeviationMillimetres <= accuracy);
+ Assert.True(b.Qualification.QualificationToleranceMillimetres < accuracy, "recorded at the measured gap, not the cap");
+ });
+ Assert.Equal(Aetheris.Kernel.Core.Import.ImportQualificationStatus.Qualified, body.ImportQualification.GeometryStatus);
+ }
+
+ /// <summary>FTC-11: three edges sit within the declared 5 µm and are kept; three sit 14 µm off and still fail.</summary>
+ [Fact]
+ public void GapsBeyondDeclaredAccuracy_StillFail()
+ {
+ var body = Step242Corpus.Body("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp");
+ Assert.Equal(3, Tolerant(body).Length);
+ Assert.False(body.PcurveRecoveryReport!.IsSuccess);
+ Assert.Equal(3, body.Topology.Coedges.Count(c => !body.Bindings.TryGetPcurveBinding(c.Id, out _)));
+ }
+
+ [Fact]
+ public void Export_DeclaresAtLeastTheWorstTolerantGap()
+ {
+ var body = Step242Corpus.Body("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp");
+ var worst = Tolerant(body).Max(b => b.Qualification!.QualificationToleranceMillimetres);
+ var step = Step242Exporter.ExportBody(body).Value;
+ var declared = double.Parse(System.Text.RegularExpressions.Regex.Match(step, @"UNCERTAINTY_MEASURE_WITH_UNIT\(LENGTH_MEASURE\(([0-9.Ee-]+)\)").Groups[1].Value,
+ System.Globalization.CultureInfo.InvariantCulture);
+ Assert.True(declared >= worst);
+ // A body without tolerant edges keeps its exact form and declares nothing.
+ Assert.DoesNotContain("UNCERTAINTY_MEASURE_WITH_UNIT", Step242Exporter.ExportBody(Step242Corpus.Body("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp")).Value);
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs b/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
index 0ed518fd..2987281c 100644
--- a/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
+++ b/Aetheris.Kernel.Core/Brep/BrepPcurveRecovery.cs
@@ -12,8 +12,14 @@ public sealed record BrepPcurveRecoveryDiagnostic(string Code, string Message, s
/// <summary>Builds deterministic face-local pcurves from edge and support geometry.</summary>
public static class BrepPcurveRecovery
{
+ /// <summary>Tag on qualifications accepted at the source's measured gap rather than the policy tolerance.</summary>
+ public const string SourceTolerantMethod = "SourceTolerant";
+
+ /// <param name="sourceTolerance">When set, an imported edge whose 3D curve lies off its surface by more than
+ /// <paramref name="tolerance"/> but no more than this is accepted as a tolerant edge: its pcurve is kept, its
+ /// measured gap becomes its qualification tolerance, and nothing is repaired.</param>
public static BrepPcurveRecoveryResult Populate(TopologyModel topology, BrepGeometryStore geometry, BrepBindingModel bindings,
- double tolerance = 1e-5, int sampleCount = 129)
+ double tolerance = 1e-5, int sampleCount = 129, double? sourceTolerance = null)
{
var diagnostics = new List<BrepPcurveRecoveryDiagnostic>();
var count = 0;
@@ -39,7 +45,20 @@ public static class BrepPcurveRecovery
maximum = double.Max(maximum, residual); count++; continue;
}
(PcurveGeometry? Pcurve, double MaximumResidual, string? Diagnostic) built;
- try { built = Build(surface, curve, interval, qualificationTolerance, sampleCount); }
+ var tolerant = false;
+ try
+ {
+ built = Build(surface, curve, interval, qualificationTolerance, sampleCount);
+ // Measure, record, don't repair: the gap is the source's, within what it declared.
+ if (built.Pcurve is null && sourceTolerance is { } cap && cap > qualificationTolerance
+ && double.IsFinite(built.MaximumResidual) && built.MaximumResidual <= cap)
+ {
+ var retry = Build(surface, curve, interval, cap, sampleCount);
+ // A looser fit must still be a trace on the surface: on a B-spline support it may not
+ // wander outside the parameter domain.
+ if (retry.Pcurve is not null && WithinDomain(surface, retry.Pcurve)) { built = retry; tolerant = true; qualificationTolerance = cap; }
+ }
+ }
catch (Exception exception) when (exception is ArgumentException or InvalidOperationException or NotSupportedException)
{
diagnostics.Add(new("surf-pcurve-invalid",
@@ -67,9 +86,11 @@ public static class BrepPcurveRecovery
&& (curve.Kind is CurveGeometryKind.Line3 or CurveGeometryKind.Circle3 || curve.BSpline3 is not null);
var origin = exactPlanarProjection ? PcurveBindingOrigin.DerivedAnalytic
: surface.BSplineSurfaceWithKnots is null ? PcurveBindingOrigin.RecoveredAnalytic : PcurveBindingOrigin.RecoveredSpline;
+ // A tolerant edge is qualified at its measured gap (with a little headroom), not at the cap.
+ var bindingTolerance = tolerant ? double.Min(qualificationTolerance, double.Max(tolerance, liftResidual * 1.01d)) : qualificationTolerance;
bindings.AddPcurveBinding(new(coedge.Id, face.Id, faceBinding.SurfaceGeometryId, built.Pcurve,
- Qualification: new(origin, liftResidual, qualificationTolerance, liftSamples,
- boundaryBounded ? "BezierBoundaryControlHull" : built.Pcurve.Kind.ToString(), surface.Kind.ToString())));
+ Qualification: new(origin, liftResidual, bindingTolerance, liftSamples,
+ tolerant ? $"{SourceTolerantMethod}:{built.Pcurve.Kind}" : boundaryBounded ? "BezierBoundaryControlHull" : built.Pcurve.Kind.ToString(), surface.Kind.ToString())));
maximum = double.Max(maximum, liftResidual);
count++;
}
@@ -77,6 +98,16 @@ public static class BrepPcurveRecovery
return new(diagnostics.Count == 0, count, maximum, diagnostics);
}
+ private static bool WithinDomain(SurfaceGeometry surface, PcurveGeometry pcurve)
+ {
+ if (surface.BSplineSurfaceWithKnots is not { } spline) return true;
+ const double slack = 1e-9;
+ return Enumerable.Range(0, 257).Select(i => pcurve.Evaluate(pcurve.Domain.Start + (pcurve.Domain.End - pcurve.Domain.Start) * i / 256d))
+ .All(uv => double.IsFinite(uv.U) && double.IsFinite(uv.V)
+ && uv.U >= spline.DomainStartU - slack && uv.U <= spline.DomainEndU + slack
+ && uv.V >= spline.DomainStartV - slack && uv.V <= spline.DomainEndV + slack);
+ }
+
private static double ResolveQualificationTolerance(SurfaceGeometry surface, CurveGeometry curve, double baseTolerance)
{
var curveRecovery = curve.RecoveryProvenance;
diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
index cf5c0c8c..69d1e880 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
@@ -193,7 +193,12 @@ public static class Step242Exporter
var planeAngleUnitId = writer.AddRawEntity("(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.))");
var solidAngleUnitId = writer.AddRawEntity("(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT())");
var uncertaintyContext = string.Empty;
- if (options.DistanceAccuracyMillimetres is { } accuracy)
+ // A body with tolerant edges must not claim more precision than its worst measured gap.
+ var tolerantFloor = body.Bindings.PcurveBindings
+ .Where(b => b.Qualification?.RecoveryMethod.StartsWith(BrepPcurveRecovery.SourceTolerantMethod, StringComparison.Ordinal) == true)
+ .Select(b => b.Qualification!.QualificationToleranceMillimetres).DefaultIfEmpty(0d).Max();
+ var declaredAccuracy = tolerantFloor > 0d ? double.Max(options.DistanceAccuracyMillimetres ?? 0d, tolerantFloor) : options.DistanceAccuracyMillimetres;
+ if (declaredAccuracy is { } accuracy)
{
if (!double.IsFinite(accuracy) || accuracy <= 0)
return Failure("DistanceAccuracyMillimetres must be positive and finite.", "Exporter.DistanceAccuracy");
@@ -1221,7 +1226,14 @@ public static class Step242Exporter
: body.Bindings.PcurveBindings
.Where(binding => model.GetCoedge(binding.CoedgeId).EdgeId == edgeId
&& (body.PcurveRecoveryReport is not { IsSuccess: false }
- || binding.SourceStepPcurveEntityId is not null))
+ || binding.SourceStepPcurveEntityId is not null)
+ // Tolerant traces stay internal: the reader re-derives them from the 3D curve, and the
+ // declared uncertainty below carries the gap. UV traces are optional STEP data.
+ && binding.Qualification?.RecoveryMethod.StartsWith(BrepPcurveRecovery.SourceTolerantMethod, StringComparison.Ordinal) != true
+ // Recovered traces on B-spline supports are not written either: written for SO-101 once its
+ // recovery succeeded, one came back outside the reread surface's domain (U -14.7). Known issue,
+ // see TRIM-CURVE-AUDIT.md; the reader re-derives them.
+ && binding.Qualification?.Origin != PcurveBindingOrigin.RecoveredSpline)
.OrderBy(binding => binding.FaceId.Value)
.ThenBy(binding => binding.CoedgeId.Value)
.ToArray();
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 6e589946..0fb831b7 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -763,9 +763,12 @@ public static class Step242Importer
!orientation.Value.Bindings.TryGetPcurveBinding(coedge.Id, out _)))
{
using var recoveryPhase = BuildPerfTrace.Phase("step.pcurve-recovery-and-qualification");
+ // Tolerant edges: accept a measured curve-surface gap up to the file's declared accuracy, or 10 µm
+ // when it declares none. Beyond that the source is wrong and the edge stays unqualified.
var recovery = BrepPcurveRecovery.Populate(
orientation.Value.Topology, orientation.Value.Geometry, orientation.Value.Bindings,
- tolerance: document.PcurveQualificationToleranceMillimetres);
+ tolerance: document.PcurveQualificationToleranceMillimetres,
+ sourceTolerance: document.SourceDistanceAccuracyMillimetres is > 0d and var declared ? declared : 0.01d);
// 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)>())
diff --git a/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
index 3287f9ac..3f314f7e 100644
--- a/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
+++ b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
@@ -32,14 +32,28 @@ The **exporter** validates before writing pcurves and silently omits them on fai
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.
+## Tolerant edges (follow-up, same day)
+
+Decision: **measure, record, don't repair.** When recovery cannot meet the 1 µm policy but
+the edge's measured curve-to-surface gap is within the file's declared distance accuracy
+(10 µm when the file declares none), the pcurve is kept and qualified at its measured gap,
+tagged `SourceTolerant`. Geometry is not touched. Beyond the declared accuracy the edge
+stays unqualified.
+
+- 9 of 16 exact NIST files now qualify fully (was 4). Recorded gaps: worst 34.6 µm on FTC-07
+ (declared 127 µm). The 23 edges beyond declared accuracy still fail.
+- Exports of a body with tolerant edges declare a distance uncertainty of at least its
+ worst gap, so Aetheris never claims more precision than it holds. Bodies without tolerant
+ edges declare nothing, as before.
+- Tolerant traces are not written to STEP; readers re-derive them. Recovered traces on
+ B-spline supports are not written either: once SO-101's recovery succeeded, one was
+ written and came back outside the reread surface's domain (U −14.7). **Known issue**,
+ not yet diagnosed (likely knot or parameter mapping between write and read).
+- `BrepThroughHoleRevisionTests` expected the default CTC-01 import to leave trims missing;
+ tolerant edges now do by default what its explicit source-accuracy policy did.
+
+Still open: 6 exact CTC-04 curves at the cubic fitter's 1.9 µm limit (now tolerant, within
+5 µm), and coedges on B-spline surfaces not measured in this audit.
## Effects
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index 6046daf9..1d57b3f4 100644
--- a/testdata/step242/manifests/nist.v0.report.json
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -17,7 +17,7 @@
"edges": 318,
"faces": 117
},
- "canonicalSha256": "34112db67f7d0e88e50804788de4284dfa7d5313374845fb75f690b5350bb2e2"
+ "canonicalSha256": "8a1865e832511ec24aecbb61f7b306865d5bd032fe75178a6e6cdf5f60191a96"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_02_asme1_ap242-e2",
@@ -37,7 +37,7 @@
"edges": 1410,
"faces": 635
},
- "canonicalSha256": "38d99195ba043ec9f98a6b319b35373745434772445f6fcf1d995949974c0df1"
+ "canonicalSha256": "3e4275a7c4025beb94735a16b4cd54d0c5b3fe17315afe23c9445c39274e2bd3"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_03_asme1_ap242-e2",
@@ -77,7 +77,7 @@
"edges": 1108,
"faces": 483
},
- "canonicalSha256": "b7365758fefec2411f8083dd123a524ffa68cb8a28556762050c15420d4307d5"
+ "canonicalSha256": "14b748b514bb765f0bb1da4ea20ea45642d9e96441503ebbfbe9c847cf6c3e16"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_05_asme1_ap242-e1",
@@ -97,7 +97,7 @@
"edges": 331,
"faces": 156
},
- "canonicalSha256": "12713bf95b7ca001684c2dbce72123f7b42c1399d19fa73e2573535b52740467"
+ "canonicalSha256": "cedca3b92fdd337542d09b1c1037f076aafbac25cce7332225c1e13f1ea11b74"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",
@@ -117,7 +117,7 @@
"edges": 476,
"faces": 187
},
- "canonicalSha256": "3a0543da81b49635c1499203c87f0f7fdf761cf571c08009a7c782f334b5f9de"
+ "canonicalSha256": "162258e5b935368b90b96780fab489210af2dbd83b473e357acf52bbc5b217d2"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_07_asme1_ap242-e2",
@@ -137,7 +137,7 @@
"edges": 865,
"faces": 304
},
- "canonicalSha256": "42fa13c37bf42f5516d4e31cf31fd9bcebc1f115eee1ea94e62c40391f2eb6a6"
+ "canonicalSha256": "7fef61e1a1781c28ba5399a805f48f478b5a78d445d85877f26d0bd1693b87b1"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e1-tg",
@@ -217,7 +217,7 @@
"edges": 799,
"faces": 264
},
- "canonicalSha256": "4d3ae6cae8c0cd3245c3929c40ded1e381f570e9113e0aa4edee003da3e06923"
+ "canonicalSha256": "3153a5f08c542d58cf602b1435f859f82ea25c4c3e66de163d11d94eff8ee109"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_11_asme1_ap242-e2",
@@ -237,7 +237,7 @@
"edges": 104,
"faces": 42
},
- "canonicalSha256": "14844407daef24f74d3121afee941a02a310cd5f31605ed03431d2a0b3ab32e1"
+ "canonicalSha256": "a85cc3381f92b7e484c2f7ebd4d02c0adc371ab0a9ef7150116be3564099689d"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3",
@@ -277,7 +277,7 @@
"edges": 865,
"faces": 304
},
- "canonicalSha256": "a3a92441ebe787a047c459a1bc01994c681cbf2b608e6d3c7704dc5be582f7fd"
+ "canonicalSha256": "14ee75c39f148370c3acdad57cc8511d08f6218e0c0887bef6df5a811630d2b2"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_08_asme1_ap242-e3",
@@ -337,6 +337,6 @@
"edges": 551,
"faces": 256
},
- "canonicalSha256": "b3fefea3aa7068984fa1e2beb809b3bfe8ebb9176a913ac967b2e9101a57319b"
+ "canonicalSha256": "b2f3bc168bd85c77cf6b4c0056a9b2b590c2e880524de86a64296746c57d11d9"
}
]