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:
parent
b41edc6c84
commit
828baa27d0
2 changed files with 62 additions and 1 deletions
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,14 +69,36 @@ void Crossing(uint edge, float level, out float2 p, out float slope, out float d
|
|||
depth = lerp(gDepth[a], gDepth[b], t);
|
||||
}
|
||||
|
||||
// The high corner (gVal at or above the level) of the edge: an edge holds exactly one when it is crossed.
|
||||
float2 HighCorner(uint edge, float level)
|
||||
{
|
||||
uint2 k = kEdge[edge];
|
||||
return gVal[k.x] >= level ? gPos[k.x] : gPos[k.y];
|
||||
}
|
||||
|
||||
float Cross2(float2 u, float2 v) { return u.x * v.y - u.y * v.x; }
|
||||
|
||||
// One segment of one level. Orientation (cut isoline-chain-arclength): a runs to b with the high corner of the edge holding a
|
||||
// strictly to its left, cross(b - a, high - a) > 0, else the endpoints swap with their attributes. A crossing exactly on that
|
||||
// corner has no side (the cross is 0): then e1's high corner decides. The rule reads the edge's corners and the segment alone, so
|
||||
// the two cells sharing an edge, seeing the same corners and the same unwrapped difference, orient a chain the same way: each
|
||||
// degree-2 point has one end and one start. Both families.
|
||||
void Emit(uint e0, uint e1, float level, uint key)
|
||||
{
|
||||
IsoSegment seg;
|
||||
Crossing(e0, level, seg.a, seg.slopeA, seg.depthA);
|
||||
Crossing(e1, level, seg.b, seg.slopeB, seg.depthB);
|
||||
if (all(seg.a == seg.b)) return;
|
||||
float side = Cross2(seg.b - seg.a, HighCorner(e0, level) - seg.a);
|
||||
if (side == 0) side = Cross2(seg.b - seg.a, HighCorner(e1, level) - seg.a);
|
||||
if (!(side > 0))
|
||||
{
|
||||
float2 p = seg.a; seg.a = seg.b; seg.b = p;
|
||||
float v = seg.slopeA; seg.slopeA = seg.slopeB; seg.slopeB = v;
|
||||
v = seg.depthA; seg.depthA = seg.depthB; seg.depthB = v;
|
||||
}
|
||||
seg.sA = 0;
|
||||
seg.sB = 0;
|
||||
if (all(seg.a == seg.b)) return;
|
||||
seg.key = key;
|
||||
seg.cell = gCell;
|
||||
uint slot;
|
||||
|
|
|
|||
Loading…
Reference in a new issue