From dd4fb549b543d6a47e0e8310f7f46c6da53b23ca Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 03:49:22 +0100 Subject: [PATCH] Validate fractal domain graphs --- .../Debug/FractalDebugDump.cs | 1 + .../Grammar/FractalDomainGraph.cs | 85 +++++++++++++++++++ .../Grammar/FractalOwnershipTree.cs | 6 +- state/evidence.jsonl | 1 + state/map.yaml | 1 + .../FractalDebugDumpTests.cs | 1 + .../FractalDslCompilerTests.cs | 30 +++++++ 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/Aquarium.Engine.Fractal/Grammar/FractalDomainGraph.cs diff --git a/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs b/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs index 06b0ebd..2648cb5 100644 --- a/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs +++ b/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs @@ -22,6 +22,7 @@ public static class FractalDebugDump builder.AppendLine($"domain {domain.Key} kind={domain.Kind} parent={domain.ParentKey}"); } + builder.AppendLine($"domain-path {string.Join(" -> ", tree.DomainGraph.GetPath(tree.Domain.Key).Select(domain => domain.Key.ToString()))}"); builder.AppendLine($"nodes {tree.Nodes.Count} claims {tree.Claims.Count} summaries {summaries.Count} cut {selectedCut.Count}"); foreach (var node in tree.Nodes) { diff --git a/src/Aquarium.Engine.Fractal/Grammar/FractalDomainGraph.cs b/src/Aquarium.Engine.Fractal/Grammar/FractalDomainGraph.cs new file mode 100644 index 0000000..4e94e3a --- /dev/null +++ b/src/Aquarium.Engine.Fractal/Grammar/FractalDomainGraph.cs @@ -0,0 +1,85 @@ +using Aquarium.Engine.Fractal; + +namespace Aquarium.Engine.Fractal.Grammar; + +public sealed class FractalDomainGraph +{ + private readonly Dictionary indices; + + public FractalDomainGraph(IReadOnlyList domains) + { + ArgumentNullException.ThrowIfNull(domains); + if (domains.Count == 0) + { + throw new FormatException("Fractal domain graph must contain at least one domain."); + } + + indices = new Dictionary(domains.Count); + for (var index = 0; index < domains.Count; index++) + { + var domain = domains[index]; + if (domain.Key.Value is null) + { + throw new FormatException($"Fractal domain at index {index} has no key."); + } + + if (!indices.TryAdd(domain.Key, index)) + { + throw new FormatException($"Duplicate fractal domain key `{domain.Key}`."); + } + } + + Domains = domains.ToArray(); + ValidateParents(); + } + + public IReadOnlyList Domains { get; } + + public bool Contains(AquariumFractalKey key) + { + return key.Value is not null && indices.ContainsKey(key); + } + + public AquariumFractalDomain GetRequired(AquariumFractalKey key) + { + if (key.Value is null || !indices.TryGetValue(key, out var index)) + { + throw new FormatException($"Unknown fractal domain `{key}`."); + } + + return Domains[index]; + } + + public IReadOnlyList GetPath(AquariumFractalKey leafKey) + { + var path = new List(); + var seen = new HashSet(); + var current = GetRequired(leafKey); + while (true) + { + if (!seen.Add(current.Key)) + { + throw new FormatException($"Fractal domain graph contains a parent cycle at `{current.Key}`."); + } + + path.Add(current); + if (current.ParentKey.Value is null) + { + break; + } + + current = GetRequired(current.ParentKey); + } + + path.Reverse(); + return path; + } + + private void ValidateParents() + { + foreach (var domain in Domains) + { + _ = GetPath(domain.Key); + } + } +} diff --git a/src/Aquarium.Engine.Fractal/Grammar/FractalOwnershipTree.cs b/src/Aquarium.Engine.Fractal/Grammar/FractalOwnershipTree.cs index 9b261cc..4828972 100644 --- a/src/Aquarium.Engine.Fractal/Grammar/FractalOwnershipTree.cs +++ b/src/Aquarium.Engine.Fractal/Grammar/FractalOwnershipTree.cs @@ -19,7 +19,9 @@ public sealed class FractalOwnershipTree IReadOnlyList claims) { Domain = domain; - Domains = domains; + DomainGraph = new FractalDomainGraph(domains); + DomainGraph.GetRequired(domain.Key); + Domains = DomainGraph.Domains; Nodes = nodes; Claims = claims; } @@ -28,6 +30,8 @@ public sealed class FractalOwnershipTree public IReadOnlyList Domains { get; } + public FractalDomainGraph DomainGraph { get; } + public IReadOnlyList Nodes { get; } public IReadOnlyList Claims { get; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index a7c887d..99232ee 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -136,3 +136,4 @@ {"timestamp":"2026-05-18T06:43:00+01:00","topic":"height-brush-table-sixteen","lesson":"The fixed D3D12 height-field brush table now carries 16 brushes, so Zyphos can render its 12-claim DSL terrain without silent truncation. This is still a bounded interim table, not the final streaming brush backend; before raising recursive density further, move height brush packets to a structured buffer or selected-cut page stream.","files":["src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs","src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"follow-up after detecting the fixed eight-brush table clipped the first Zyphos DSL terrain"} {"timestamp":"2026-05-18T06:58:00+01:00","topic":"aquageo-world-patch-files","lesson":"Aquarium fractal world DSL patches should be authored as `.aquageo` content files, copied into the client output, and loaded from disk at runtime. Zyphos' first terrain proof now loads `Worlds/zyphos-first-fractal-terrain.aquageo`; do not keep demo grammars embedded as fallback strings because that hides asset pipeline failures.","files":["src/Aquarium.Zyphos/Worlds/zyphos-first-fractal-terrain.aquageo","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/Aquarium.Zyphos.csproj","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"user asked to load the world DSL patch via file and call it .aquageo"} {"timestamp":"2026-05-18T07:16:00+01:00","topic":"zyphos-nested-domains-and-umbros-authority","lesson":"Zyphos' `.aquageo` patch now declares solar, orbital, planetary, and lat/long domains before terrain tiles, giving fractal DSL nodes explicit nested reference frames. The Zyphos/Umbros binary constants live in `ZyphosUmbrosSystem`: Umbros is a fixed-sky 0.9-radius twin at 8 Zyphos radii, while the dim primary star phase moves through the Zyphos-local frame for first-pass eclipse cadence. Do not reintroduce moon language or hidden orbital constants in shader files.","files":["src/Aquarium.Zyphos/Worlds/zyphos-first-fractal-terrain.aquageo","src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosUmbros.hlsl","tests/Aquarium.Engine.Fractal.Tests/ZyphosUmbrosSystemTests.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"user asked to express nested solar/orbital/planetary/lat-long domains and verify Zyphos/Umbros/parent-star modeling against worldbuilding docs"} +{"timestamp":"2026-05-18T07:31:00+01:00","topic":"fractal-domain-graph-validation","lesson":"Nested fractal domains are now validated by `FractalDomainGraph`, which owns duplicate-key checks, parent existence, cycle detection, and root-to-leaf path queries. Keep domain topology in this grammar-layer boundary until real transform math exists; do not scatter parent lookup or reference-frame assumptions through render code.","files":["src/Aquarium.Engine.Fractal/Grammar/FractalDomainGraph.cs","src/Aquarium.Engine.Fractal/Grammar/FractalOwnershipTree.cs","src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs","tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs","tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs"],"source":"follow-up slice after `.aquageo` gained solar/orbital/planetary/lat-long domains"} diff --git a/state/map.yaml b/state/map.yaml index ff77eef..27ac5b6 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -111,6 +111,7 @@ renderer_state: - Zyphos simulates the neighboring Eusocial Interbeing setting; the vault at E:\Projects\Eusocial Interbeing owns canon, while Aquarium owns demo rendering constraints and feeds worldbuilding questions back through the vault's Zyphos Simulation Brief. - Future planetary terrain and fractal body detail should use a cube-sphere/QSC-family address space: six quadtree cube faces projected to the sphere with a measured low-distortion warp, avoiding lat-long pole singularities. - Fractal world patches can declare nested semantic domains before terrain tiles. The first .aquageo patch declares solar, orbital, planetary, and lat/long domains for Zyphos so DSL nodes can attach to explicit reference frames before backend lowering. + - The fractal grammar layer validates nested domain topology through FractalDomainGraph: duplicate keys, missing parents, cycles, and root-to-leaf paths are grammar concerns, not renderer folklore. - Future multiscale terrain and agent/body detail should come from bounded IFS brush grammars using shared shaped anisotropic envelopes; texture/material detail can be abundant, but traced SDF form detail must be proxy-bounded, LOD-gated, and measured. - The IFS brush grammar should preserve a semantic ownership tree before backend lowering: local frames, deterministic seeds, named fields/captures, tags, payload bindings, LOD/cost tiers, and boolean-style union/subtract/common nodes should survive even if the first renderer path flattens them into fixed brush tables or SDF shader code. - IFS LOD should be driven by cached node contribution summaries: each node carries bounds, projected error/material delta, coverage, cost, estimator state, residency, and summary/child payload handles so traversal can choose a stable hierarchy cut and render parent summaries while child details stream or fade in. diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs index 1e608c5..8b661ec 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs @@ -22,6 +22,7 @@ public sealed class FractalDebugDumpTests var dump = FractalDebugDump.Build(tree, summaries, cut); Assert.Contains("domain cube/PositiveZ/L00/0/0:debug/world", dump); + Assert.Contains("domain-path cube/PositiveZ/L00/0/0:debug/world", dump); Assert.Contains("claim cube/PositiveZ/L00/0/0:debug/world/root/claim/0000/ridge", dump); Assert.Contains("summary cube/PositiveZ/L00/0/0:debug/world/root", dump); Assert.Contains("cut cube/PositiveZ/L00/0/0:debug/world/root", dump); diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs index 2d16bbb..d7f2390 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs @@ -24,6 +24,9 @@ public sealed class FractalDslCompilerTests Assert.Equal(5, tree.Domains.Count); Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.Solar && domain.Key.Value == "demo/star"); Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.LatLong && domain.ParentKey.Value == "demo/planet"); + Assert.Equal( + ["demo/star", "demo/orbit", "demo/planet", "demo/latlong", "cube/PositiveZ/L00/0/0:zyphos/terrain"], + tree.DomainGraph.GetPath(tree.Domain.Key).Select(domain => domain.Key.Value).ToArray()); Assert.Equal(2, tree.Claims.Count); Assert.Equal("cube/PositiveZ/L00/0/0:zyphos/terrain/root/claim/0001/ridge", tree.Claims[1].Key.Value); Assert.Equal(0.06f, tree.Claims[1].Amplitude); @@ -67,4 +70,31 @@ public sealed class FractalDslCompilerTests Assert.Throws(() => FractalDslCompiler.Compile(source)); } + + [Fact] + public void DslRejectsMissingDomainParents() + { + const string source = """ + domain Planetary demo/planet demo/missing 1 0.56 0 0 + tile PositiveZ 0 0 0 zyphos/terrain demo/planet + height basin 0 0 30 30 0 3 1 -0.18 7 basin + """; + + var ex = Assert.Throws(() => FractalDslCompiler.Compile(source)); + Assert.Contains("demo/missing", ex.Message, StringComparison.Ordinal); + } + + [Fact] + public void DslRejectsDuplicateDomainKeys() + { + const string source = """ + domain Planetary demo/planet - 1 0.56 0 0 + domain LatLong demo/planet - -90 90 -180 180 + tile PositiveZ 0 0 0 zyphos/terrain demo/planet + height basin 0 0 30 30 0 3 1 -0.18 7 basin + """; + + var ex = Assert.Throws(() => FractalDslCompiler.Compile(source)); + Assert.Contains("Duplicate", ex.Message, StringComparison.Ordinal); + } }