Isoline Emit orients each segment so the high corner of its first edge lies to its left (both families); smoke check 'orientation'

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 00:48:34 +01:00
commit 8fc0982e5f
2 changed files with 62 additions and 1 deletions

View file

@ -178,6 +178,42 @@ namespace Aetheria.EditorTools
static int LevelOf(uint key) => (int)(key & 0xFFu);
static float Length(IsolineExtractor.IsoSegment s) => (s.b - s.a).magnitude;
// ---- orientation ---------------------------------------------------------------------------------------------------
static (int, int) PointKey(Vector2 p) => (BitConverter.SingleToInt32Bits(p.x), BitConverter.SingleToInt32Bits(p.y));
// The orientation rule's outcome (cut isoline-chain-arclength): at every point shared by exactly two endpoints of one
// family, one is a start (a) and the other an end (b). Returns the endpoints that break it (two starts or two ends at one
// point, counted per endpoint, the unit of the GPU's ChainStats[1]) and the joints it judged. The mutant, the emit order
// as marched, reads ORIENTATION_MUTANT below. Bound: no conflict at all.
static (int conflicts, int joints) Orientation(string what, IsolineExtractor.IsoSegment[] segments)
{
int conflicts = 0, joints = 0, rayConflicts = 0;
foreach (var family in new[] { false, true })
{
var points = new Dictionary<(int, int), (int starts, int ends)>();
foreach (var s in segments.Where(s => IsRay(s.key) == family))
{
var a = PointKey(s.a);
var b = PointKey(s.b);
points.TryGetValue(a, out var pa); points[a] = (pa.starts + 1, pa.ends);
points.TryGetValue(b, out var pb); points[b] = (pb.starts, pb.ends + 1);
}
foreach (var (starts, ends) in points.Values)
{
if (starts + ends != 2) continue;
joints++;
if (starts == 1) continue;
conflicts += 2;
if (family) rayConflicts += 2;
}
}
Info($"orientation {what}: {joints} joints, {conflicts} endpoints at a joint with two starts or two ends ({rayConflicts} on rays)");
if (joints < 10) Fail("orientation", $"{what}: only {joints} joints, the check is vacuous");
if (conflicts != 0) Fail("orientation", $"{what}: {conflicts} endpoints sit at a joint that is not one end and one start");
return (rayConflicts, joints);
}
// ---- entry -------------------------------------------------------------------------------------------------------
public static void Run()
@ -329,6 +365,7 @@ namespace Aetheria.EditorTools
}
Info($"saddle: corners {string.Join(", ", corner.Select(c => c.ToString("G6")))} centre mean {mean:G6}");
SamplesMatchTheLaw("saddle", result, terms, origin, perTexel, new Vector2Int(n, n), null);
Orientation("saddle", result.Segments);
}
finally { Free(terms); }
}
@ -407,6 +444,7 @@ namespace Aetheria.EditorTools
EndpointAttributes(profile, result.Segments, centre, origin, perTexel, GridSize);
SamplesMatchTheLaw("radial " + profile.Name, result, terms, origin, perTexel, new Vector2Int(GridSize, GridSize), null);
Orientation("radial " + profile.Name, result.Segments);
Info($"ray segments per level, {profile.Name}: {string.Join(" ", Enumerable.Range(0, 12).Select(k => rays.Count(r => LevelOf(r.key) == k)))}");
Info($"along-line {profile.Name}: {contours.Length} contour / {rays.Length} ray segments; ray angle error worst {angleWorst:G4} rad (mutant levels half a step off {angleMutant:G4})");
if (angleWorst > RayAngleBound) Fail("rays", $"{profile.Name}: a ray endpoint's angle is off its level by {angleWorst:G4} rad > {RayAngleBound:G4}");
@ -633,6 +671,7 @@ namespace Aetheria.EditorTools
open++;
Info($"real zone: {open} contour endpoints off the border without exactly one partner");
CellBoxes("real zone", result.Segments, origin, perTexel, 256);
Orientation("real zone", result.Segments);
if (open != 0) Fail("contours close", $"{open} endpoints are not shared with exactly one other endpoint");
}