nx_inter_layer_coherence.nx
buildroot/runtime/nx_inter_layer_coherence.nx
about
nx_inter_layer_coherence.nx -- cross-layer constraint checker.
Per honest audit 2026-05-16: per-layer graders can each be S-class
while the OVERALL composition is nonsense -- river flowing uphill,
forest in a desert biome, town built on a cliff edge, castle in a
swamp. This primitive grades the INTER-LAYER CONSTRAINTS that
must hold for a coherent world.
Four constraints scored individually + composed:
1. RIVER_DRAINAGE: rivers should flow downhill. For each polyline
segment, sample heightmap at both endpoints; score = fraction
of segments where h_end < h_start.
2. FOREST_BIOME_MATCH: forests should sit in biomes that support
forests (BOREAL_FOREST / TEMPERATE_FOREST / TROPICAL_RAINFOREST
or GRASSLAND). Score = fraction of forest positions in valid
biomes.
3. TOWN_FLATNESS: towns should be on relatively flat ground. Sample
local heightmap stddev within town radius; score = inverse of
normalised stddev.
4. CASTLE_DEFENSIVE: castles benefit from elevation advantage.
Score = fraction of castles whose centre elevation exceeds the
mean elevation in a surrounding band of 2x radius.
Each function returns Q14 [0, Q]; nx_inter_layer_coherence_grade
composes them into a LAYER_VERDICT (kind = NX_LAYER_KIND_READABILITY,
refine = NX_LAYER_REFINE_FIX_COHERENCE).
genealogy_id: world_design_coherence_canon +
leopold_wolman_1957_drainage +
medieval_settlement_geography_canon
lineage_id: nx_inter_layer_coherence_4axis_v1
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_tier.nxnx_layer_verdict.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 47 | const NX_ILC_Q: nx_int = 16384 |
| 50 | const NX_ILC_AXIS_RIVER: nx_int = 0 |
| 51 | const NX_ILC_AXIS_FOREST_BIOME: nx_int = 1 |
| 52 | const NX_ILC_AXIS_TOWN_FLAT: nx_int = 2 |
| 53 | const NX_ILC_AXIS_CASTLE_HIGH: nx_int = 3 |
| 55 | const NX_ILC_AXIS_COUNT: nx_int = 4 |
functions
| 58 | func _ilc_h_at( |
| 74 | func nx_coherence_river_drainage( |
| 109 | func nx_coherence_forest_in_biome( |
| 134 | func nx_coherence_town_on_flatland( |
| 205 | func nx_coherence_castle_on_high( |
| 252 | func nx_inter_layer_coherence_grade( |
| 267 | func main() -> i64 |