Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Write all face traces again; shift periodic-edge traces by whole turns

Claudea0483747ffb8
diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
index 69d1e880..4cbcc597 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
@@ -1226,20 +1226,32 @@ 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)
- // 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)
+ || binding.SourceStepPcurveEntityId is not null))
.OrderBy(binding => binding.FaceId.Value)
.ThenBy(binding => binding.CoedgeId.Value)
.ToArray();
+ // A circle or ellipse is written untrimmed, so a reader derives its trim from the vertices and lands on
+ // its own turn, which may differ from the stored trim by whole turns (SO-101 stores [2pi, 5pi/2]). Analytic
+ // conic traces are periodic and survive that. Line, polyline and spline traces are not: SO-101 stores a
+ // straight UV trace on a B-spline face over [2pi, 2pi+0.43], which, read against [0, 0.43], started at
+ // U -14.7 on a [0, 1] surface. So those traces move by the same whole turns.
+ var periodShift = 0d;
+ if (edgeBinding.TrimInterval is { } storedTrim && curve.Kind is CurveGeometryKind.Circle3 or CurveGeometryKind.Ellipse3)
+ {
+ var readerTrim = curve.Kind == CurveGeometryKind.Circle3
+ ? Step242Importer.ComputeCircleTrim(curve.Circle3!.Value, startPoint, endPoint, emittedSameSense)
+ : Step242Importer.ComputeEllipseTrim(curve.Ellipse3!.Value, startPoint, endPoint, emittedSameSense);
+ if (readerTrim.IsSuccess)
+ periodShift = double.Round((readerTrim.Value.Start - storedTrim.Start) / (2d * double.Pi)) * 2d * double.Pi;
+ }
var pcurveIds = pcurveContextId is null
? []
: edgePcurveBindings
+ .Select(binding => periodShift != 0d && (binding.Pcurve.PolynomialCurve is not null
+ || binding.Pcurve.Kind is PcurveGeometryKind.Line or PcurveGeometryKind.Polyline)
+ ? binding with { Pcurve = ReparameterizeLinePcurve(binding.Pcurve,
+ new ParameterInterval(binding.Pcurve.Domain.Start + periodShift, binding.Pcurve.Domain.End + periodShift)) }
+ : binding)
.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 }
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 0fb831b7..c912294e 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -1891,7 +1891,7 @@ public static class Step242Importer
source)
]);
- private static KernelResult<ParameterInterval> ComputeEllipseTrim(Ellipse3Curve ellipse, Point3D startPoint, Point3D endPoint, bool edgeSameSense)
+ internal static KernelResult<ParameterInterval> ComputeEllipseTrim(Ellipse3Curve ellipse, Point3D startPoint, Point3D endPoint, bool edgeSameSense)
{
var tolerance = ComputeEllipseTrimTolerance(ellipse, startPoint, endPoint);
@@ -2055,6 +2055,10 @@ public static class Step242Importer
return KernelResult<ParameterInterval>.Success(new ParameterInterval(0d, 2d * double.Pi));
}
+ // A start on the seam reads as 2pi-e or +e depending on how the coordinates were rounded, so the trim
+ // would land a whole turn apart for the same file written twice. Keep it on the turn that starts at 0;
+ // face traces written against this trim (Step242Exporter's period shift) rely on that.
+ if (canonicalStart >= (2d * double.Pi) - angleTolerance) canonicalStart -= 2d * double.Pi;
var normalizedEnd = canonicalStart + span;
if (normalizedEnd <= canonicalStart)
{
diff --git a/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
index 3f314f7e..97bb0786 100644
--- a/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
+++ b/docs/development/reports/2026-11/TRIM-CURVE-AUDIT.md
@@ -45,10 +45,15 @@ stays unqualified.
- 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).
+- All traces are written to STEP again, tolerant and recovered alike. Excluding them hid one
+ bug, now fixed: circles and ellipses are written untrimmed, so the reader derives the trim
+ from the vertices and may land a whole turn away from the stored trim (SO-101 stores
+ [2π, 2π+0.43]; the reader gets [0, 0.43]). Conic traces are periodic and didn't care.
+ Line, polyline and spline traces aren't, and SO-101's straight trace on a B-spline face read
+ back from U −14.7 on a [0, 1] surface. The exporter now shifts those traces by the whole
+ turns the reader's trim will differ by. The reader also keeps a start that sits on the seam
+ on the turn that starts at 0: depending on how the vertex was rounded it used to read as
+ 2π−ε or +ε, so neither side could predict it.
- `BrepThroughHoleRevisionTests` expected the default CTC-01 import to leave trims missing;
tolerant edges now do by default what its explicit source-accuracy policy did.
diff --git a/testdata/step242/manifests/nist.v0.canonical-linux.json b/testdata/step242/manifests/nist.v0.canonical-linux.json
index 26bee280..8cd4fb32 100644
--- a/testdata/step242/manifests/nist.v0.canonical-linux.json
+++ b/testdata/step242/manifests/nist.v0.canonical-linux.json
@@ -1,5 +1,5 @@
{
- "testdata/step242/nist/CTC/nist_ctc_03_asme1_ap242-e2.stp": "85a88b7063e6d569b7a44e23c00fd18b573918220b8282d08cb976c90a620b5e",
- "testdata/step242/nist/FTC/nist_ftc_09_asme1_ap242-e1.stp": "c7e42e6a6e0aad2c48f646e03f6a5097429b7a4d9ed24468718512b1ff8088a6",
+ "testdata/step242/nist/CTC/nist_ctc_03_asme1_ap242-e2.stp": "eb2a3fc04352cb73a830e1393db93e4a9e211cd42651052dca90560a428b9e21",
+ "testdata/step242/nist/FTC/nist_ftc_09_asme1_ap242-e1.stp": "5579a8c21d2f642d5baf1d72b184e55ae567e768c92c34be8ecf06adc2e3d47b",
"testdata/step242/nist/STC/nist_stc_09_asme1_ap242-e3.stp": "b1b0532b01efb53e726adc1ae371ce41e0114698dcb63d9885a62d8758498f38"
}
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index 1d57b3f4..67cd1951 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": "8a1865e832511ec24aecbb61f7b306865d5bd032fe75178a6e6cdf5f60191a96"
+ "canonicalSha256": "f0a0da70f663e4c7bd829321ab9bcdefda29c8873b0dd7c919871149881db4bf"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_02_asme1_ap242-e2",
@@ -37,7 +37,7 @@
"edges": 1410,
"faces": 635
},
- "canonicalSha256": "3e4275a7c4025beb94735a16b4cd54d0c5b3fe17315afe23c9445c39274e2bd3"
+ "canonicalSha256": "c725ff7b31d3da76717365f70bd12767f74f102a462504343c4d590ca51ccf06"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_03_asme1_ap242-e2",
@@ -77,7 +77,7 @@
"edges": 1108,
"faces": 483
},
- "canonicalSha256": "14b748b514bb765f0bb1da4ea20ea45642d9e96441503ebbfbe9c847cf6c3e16"
+ "canonicalSha256": "e032d691278fea03e584041fa502e19290bbc0f36213502ac017ad5bc0f7ce5d"
},
{
"fileId": "testdata_step242_nist_CTC_nist_ctc_05_asme1_ap242-e1",
@@ -117,7 +117,7 @@
"edges": 476,
"faces": 187
},
- "canonicalSha256": "162258e5b935368b90b96780fab489210af2dbd83b473e357acf52bbc5b217d2"
+ "canonicalSha256": "b43cd5d2c63e72bc0281a370cc7f832d3da92627b3e87e26dfe55f036eeb7a28"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_07_asme1_ap242-e2",
@@ -137,7 +137,7 @@
"edges": 865,
"faces": 304
},
- "canonicalSha256": "7fef61e1a1781c28ba5399a805f48f478b5a78d445d85877f26d0bd1693b87b1"
+ "canonicalSha256": "4e5eda24fe9e16777e6a841a04dedb1c0b638340b6ac74c39768780cdf9dd38a"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e1-tg",
@@ -297,7 +297,7 @@
"edges": 705,
"faces": 270
},
- "canonicalSha256": "177d16dbb8ad0c53f42a3f2837ae0c050d7a484e9b0762f75e0d54602a11d8ea"
+ "canonicalSha256": "1c70df2622ff63e2efc6023bed96dcc9e88f94a0c0dc2b64d4fb027724b556a1"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_09_asme1_ap242-e3",