Isoline chains: a closed ray loop is counted unterminated (rank above 0 at its own end); smoke gates against the first readings

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 01:22:25 +01:00
commit 7ee60870bb
3 changed files with 30 additions and 11 deletions

View file

@ -32,9 +32,17 @@ namespace Aetheria.EditorTools
{
const string Tag = "[IsolineExtractSmoke]";
const float SlopeEpsilon = 1e-3f;
// PROVISIONAL, set by the first reading: the chain bounds below.
const float EdgeBound = 1e-4f, PositionBound = 1e9f, JointBound = 1e9f;
const float RaySBound = 1e9f;
// Chain bounds, margin rule (readings of the run that set them, real zone at 256 x 256, 1920 x 1080 and 3840 x 2160 and the
// 60-well stress set; errors are fractions of the chain's length, mutants emulated on the CPU from the same segments).
// Position (s against the CPU arclength from the tail): shipped worst 1.6e-7; least claimed mutant, linking through the
// first segment found at a junction, 0.199 (J = 8 reads 0.853): bound 1.8e-4, separation 1.2e6.
// Joint (sB_i against sA of the next): shipped worst 2.0e-7; the mutant J = 8 reads 6.3e-3 (first-found does not move a
// joint the truth links: unclaimed here): bound 3.5e-5, separation 3.2e4.
// Edge, |sB - sA| against |b - a| over the edge's own scale: shipped worst 5.9e-8; the mutant sB = sA reads 1 by
// construction: bound 2.4e-4.
// Ray s on the log wells, ||sB - sA| - radial change| over the edge: shipped worst 9.9e-4; the mutant s from d / |grad d|
// (the curvature radius this cut deleted) reads 0.996: bound 0.0314, separation 1.0e3.
const float PositionBound = 1.8e-4f, JointBound = 3.5e-5f, EdgeBound = 2.4e-4f, RaySBound = 0.0314f;
const int Contours = 21;
// Margin rule (lodur:ruling:deterministic-bound-margin): a bound sits at the geometric mean of the shipped worst and
@ -245,7 +253,7 @@ namespace Aetheria.EditorTools
Array.Fill(truth, double.NaN);
Array.Fill(link, -1);
double Len(int i) => Math.Sqrt(Math.Pow((double)segs[i].b.x - segs[i].a.x, 2) + Math.Pow((double)segs[i].b.y - segs[i].a.y, 2));
int mixed = 0, longest = 0;
int mixed = 0, longest = 0, loops = 0, loopSegments = 0;
double jointJ8Worst = 0;
foreach (var chain in chains)
{
@ -254,6 +262,8 @@ namespace Aetheria.EditorTools
else if (chain.Rev.All(r => r)) order = chain.Seg.AsEnumerable().Reverse().ToList();
else { mixed++; continue; }
var n = order.Count;
// a closed loop of ray segments has no tail: the GPU ranks it as it can and counts its segments unterminated
if (n >= 2 && PointKey(segs[order[0]].a) == PointKey(segs[order[n - 1]].b)) { loops++; loopSegments += n; continue; }
longest = Math.Max(longest, n);
var prefix = new double[n + 1];
for (var k = 0; k < n; k++) prefix[k + 1] = prefix[k] + Len(order[k]);
@ -317,13 +327,13 @@ namespace Aetheria.EditorTools
_jointShipped = Math.Max(_jointShipped, jointShipped); _jointFirst = Math.Max(_jointFirst, jointFirst); _jointJ8 = Math.Max(_jointJ8, jointJ8Worst);
var stats = result.ChainStats;
Info($"chains {what}: {segs.Count(s => IsRay(s.key))} ray segments, {chains.Count} chains (longest {longest} segments), {mixed} mixed-direction; GPU stats heads {stats[0]} conflicts {stats[1]} unterminated {stats[2]} overflow {stats[3]}; "
Info($"chains {what}: {segs.Count(s => IsRay(s.key))} ray segments, {chains.Count} chains (longest {longest} segments), {loops} closed loops of {loopSegments} segments, {mixed} mixed-direction; GPU stats heads {stats[0]} conflicts {stats[1]} unterminated {stats[2]} overflow {stats[3]}; "
+ $"s error / chain length: position worst {positionShipped:G3} (mutants first-found {positionFirst:G3} on {firstWrong} segments, J = 8 {positionJ8:G3}), joint worst {jointShipped:G3} (mutants {jointFirst:G3}, {jointJ8Worst:G3}); |sB - sA| = |b - a| worst relative {edgeWorst:G3}");
if (compared < 100) Fail("chains", $"{what}: only {compared} ray segments compared, the check is vacuous");
if (mixed != 0) Fail("chains", $"{what}: {mixed} chains run both ways");
if (stats[0] != chains.Count) Fail("chains", $"{what}: the GPU counted {stats[0]} chain heads, the CPU {chains.Count} chains");
if (stats[0] != chains.Count - loops) Fail("chains", $"{what}: the GPU counted {stats[0]} chain heads, the CPU {chains.Count - loops} open chains");
if (stats[1] != rayConflicts) Fail("chains", $"{what}: the GPU counted {stats[1]} orientation conflicts, the CPU {rayConflicts}");
if (stats[2] != 0) Fail("chains", $"{what}: {stats[2]} segments are unterminated");
if (stats[2] != loopSegments) Fail("chains", $"{what}: the GPU counted {stats[2]} unterminated segments, the CPU {loopSegments} in closed loops");
if (stats[3] != 0) Fail("chains", $"{what}: the hash table overflowed {stats[3]} times");
if (edgeWorst > EdgeBound) Fail("chains", $"{what}: |sB - sA| is off |b - a| by {edgeWorst:G3} > {EdgeBound:G3}");
}

View file

@ -604,12 +604,13 @@ namespace Aetheria.EditorTools
// Dash run lengths along the ray chains: over every chain longer than 150 px, the 3 x 3 maximum of the frame's alpha sampled
// once per pixel along the chain, taken as on where it exceeds half the chain's peak; the lengths of the runs of on and
// of off, in px.
static List<double> DashRuns(Seg[] segs, List<Chain> chains, View view, Frame frame, float ppx)
static List<double> DashRuns(Seg[] segs, List<Chain> chains, View view, Frame frame, float ppx, bool withLoops = false)
{
var runs = new List<double>();
foreach (var chain in chains)
{
var e = EdgesOf(segs, chain);
if (!withLoops && IsClosed(e)) continue;
if (e.Sum(x => x.L) / ppx < 150f) continue;
var samples = new List<float>();
foreach (var edge in e)
@ -641,6 +642,11 @@ namespace Aetheria.EditorTools
return runs;
}
// A closed loop of ray segments (the iso-angle curve around a local extremum of the gradient angle) has no tail: the junction rule
// gives it no start for the ranking, so its s is not arclength and its dashes break at every joint. Dash runs are read along open
// chains; the loops are counted beside them.
static bool IsClosed(List<Edge> edges) => edges.Count >= 2 && PointKey(edges[0].P0) == PointKey(edges[edges.Count - 1].P1);
// The reference: the same segments with s replaced by the cumulative arclength along BuildChains' chain, from its first
// edge (the dash phase differs from the shipped one, the spacing does not).
static Seg[] WithChainArclength(Seg[] segs, List<Chain> chains)
@ -692,8 +698,9 @@ namespace Aetheria.EditorTools
var referenceFrame = Draw(view, reference, rayLook, false, levels: levels, pool: ShippedPool);
var shippedRuns = DashRuns(segs, chains, view, shippedFrame, ppx);
var referenceRuns = DashRuns(segs, chains, view, referenceFrame, ppx);
Info($"dashes {name} pose, loops included: run length px shipped {Pcts(DashRuns(segs, chains, view, shippedFrame, ppx, true))}; reference {Pcts(DashRuns(segs, chains, view, referenceFrame, ppx, true))}");
if (shippedRuns.Count < 40 || referenceRuns.Count < 40) { Fail("dashes", $"{name}: {shippedRuns.Count} and {referenceRuns.Count} dash runs, the check would be vacuous"); continue; }
Info($"dashes {name} pose: {segs.Count(s => ((s.key >> 8) & 1u) != 0)} ray segments, {chains.Count} chains; run length px shipped {Pcts(shippedRuns)} ({shippedRuns.Count} runs); reference (CPU arclength) {Pcts(referenceRuns)} ({referenceRuns.Count} runs)");
Info($"dashes {name} pose: {segs.Count(s => ((s.key >> 8) & 1u) != 0)} ray segments, {chains.Count} chains of which {chains.Count(c => IsClosed(EdgesOf(segs, c)))} closed loops of {chains.Where(c => IsClosed(EdgesOf(segs, c))).Sum(c => c.Seg.Count)} segments (not measured); run length px shipped {Pcts(shippedRuns)} ({shippedRuns.Count} runs); reference (CPU arclength) {Pcts(referenceRuns)} ({referenceRuns.Count} runs)");
foreach (var (label, q, bound) in new[] { ("p5", .05, DashP5Bound), ("p25", .25, DashP25Bound), ("p50", .5, DashP50Bound) })
{
var gap = Math.Abs(Math.Log(Pct(shippedRuns, q) / Pct(referenceRuns, q)));

View file

@ -340,7 +340,8 @@ void ChainJump(uint3 id : SV_DispatchThreadID)
}
// The ranked chain's s: sA = -rank, sB = sA + |b - a|, the arclength from the tail. A segment whose final next is not a tail
// (a chain longer than 2^J, or a cycle) is counted unterminated; its s stays as ranked.
// (a chain longer than 2^J, or a closed loop of ray segments) is counted unterminated; its s stays as ranked. A tail has rank
// exactly 0 and is its own next; a loop whose length divides 2^J also ends on itself but with a rank above 0.
[numthreads(64, 1, 1)]
void ChainEmit(uint3 id : SV_DispatchThreadID)
{
@ -349,7 +350,8 @@ void ChainEmit(uint3 id : SV_DispatchThreadID)
IsoSegment seg = _Segments[i];
if (IsoFamily(seg.key) != ISO_FAMILY_RAY) return;
uint2 link = _LinkIn[i];
if (_LinkIn[link.x].x != link.x) InterlockedAdd(_ChainStats[2], 1u);
uint2 last = _LinkIn[link.x];
if (last.x != link.x || last.y != 0u) InterlockedAdd(_ChainStats[2], 1u);
float rank = asfloat(link.y);
_Segments[i].sA = -rank;
_Segments[i].sB = -rank + length(seg.b - seg.a);