In this section
- Buffers transform · globalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/layers/buffers.mjs lines 1–115
- Ground ingest · globalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs lines 1–261
- Links ingest · globalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/links.mjs lines 1–100
- Measure Format transform · globalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/measure-format.mjs lines 1–86
Buffers
A JavaScript module in the layers folder of GlobalGrid2050 that works with dash ring (`dashRing`) and drape pieces (`drapePieces`) and calculates planar distances.
transformglobalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/layers/buffers.mjs · lines 1–115 of 115 · version 2026-09-27 00:05 · Not reached from any entry point (candidate for review) · pattern finite (shared by 43 files)
- What it does
- It calculates its inputs. Defines 6 functions or classes, including finite, dashRing, drapePieces, createBuffers, say.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 2 files: Overhead Line (OHL) UI (globalgrid2050); Overhead Line (OHL) UI (globalgrid2050).
- What it achieves
- It is built from the finite step (`finite`), the dash ring helper (`dashRing`) and the drape pieces helper (`drapePieces`). Offset zones around features (overhead lines, watercourses, roads, trees, hedges, drawn items) drawn as dashed outlines on the ground, and a small cross wherever a drawn item enters a zone.
- Why it matters
- Imported by Overhead Line (OHL) UI.
- Application
- globalgrid2050 · solar-design-studio/202609270005-site-world-v3/world/layers · JavaScript module
- Uses
- none found
- Used by
- imported by Overhead Line (OHL) UI (import), imported by Overhead Line (OHL) UI (import)
- Produces
- DASH_M, COLORS, dashRing, drapePieces, createBuffers
- Defines here
- finite, dashRing, drapePieces, createBuffers, say, describe
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270005-site-world-v3/world/layers/buffers.mjs:1-115 · blob fe2da1f9c7589831b0f6c68df20185b943e1bb30 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unreached_review
// Layer: buffers. Offset zones around features (overhead lines, watercourses, roads, trees, hedges, drawn items)
// drawn as dashed outlines on the ground, and a small cross wherever a drawn item enters a zone.
// Off by default: until setEnabled(true) (or api.config.enabled) it draws nothing.
// Self-contained: no imports (it runs from a blob URL). The zones are worked out by web/world/buffers.mjs on the
// page and handed in with setZones(zones); clashes from checkClashes with setClashes(list). Zone rings are local
// metres from the site origin: [{ id, layer, rule, kind, rings: [[[x, y], ...], ...] }]. Nothing is fetched.
//
// Dashes run continuously round each ring (the pattern carries across corners), are split to STEP_M so they
// follow banks and ditches, and sit LIFT_M above the ground. Batches are rebuilt only on new zones or new ground.
export const DASH_M = 2, GAP_M = 1.5, STEP_M = 1, LIFT_M = 0.08, CROSS_M = 1.2;
// Quiet colours on the dark background, by source layer; drawn-item clearances in white, clashes in red.
export const COLORS = {
overhead: [1.00, 0.78, 0.40, 0.70],
water: [0.45, 0.70, 1.00, 0.70],
roads: [0.78, 0.78, 0.78, 0.60],
trees: [0.55, 0.88, 0.55, 0.65],
hedges: [0.55, 0.88, 0.55, 0.65],
drawn: [1.00, 1.00, 1.00, 0.60],
clash: [1.00, 0.35, 0.35, 0.95]
};
const OTHER = [0.80, 0.80, 0.80, 0.55];
const finite = h => (Number.isFinite(h) ? h : 0);
// Pure: the dashes of one closed ring as [[x0, y0, x1, y1], ...], each at most `step` long. The pattern starts
// at the first vertex and carries on round the corners, so a dash may bend round one.
export function dashRing(ring, { dash = DASH_M, gap = GAP_M, step = STEP_M } = {}) {
const out = [], n = ring.length, period = dash + gap;
if (n < 2 || !(dash > 0) || !(gap >= 0)) return out;
let s = 0; // distance round the ring so far
for (let i = 0; i < n; i++) {
const a = ring[i], b = ring[(i + 1) % n], L = Math.hypot(b[0] - a[0], b[1] - a[1]);
if (!(L > 0)) continue;
let t = 0;
while (t < L - 1e-12) {
const ph = (s + t) % period, inDash = ph < dash - 1e-12;
const run = Math.min(L - t, inDash ? dash - ph : period - ph, inDash ? step : Infinity);
if (inDash) out.push([a[0] + (b[0] - a[0]) * t / L, a[1] + (b[1] - a[1]) * t / L,
a[0] + (b[0] - a[0]) * (t + run) / L, a[1] + (b[1] - a[1]) * (t + run) / L]);
t += run;
}
s += L;
}
return out;
}
// Pure: draped xyz pairs for 2D pieces, relative to origin o, lift metres above heightAt. A piece with an end where
// known(x, y) is false (no surveyed ground) is left out rather than drawn at a guessed height.
export function drapePieces(pieces, heightAt, lift = LIFT_M, o = [0, 0, 0], known = () => true) {
const out = [];
for (const [x0, y0, x1, y1] of pieces) {
if (!known(x0, y0) || !known(x1, y1)) continue;
out.push(x0 - o[0], y0 - o[1], finite(heightAt(x0, y0)) + lift - o[2], x1 - o[0], y1 - o[1], finite(heightAt(x1, y1)) + lift - o[2]);
}
return new Float32Array(out);
}
export function createBuffers() {
let api = null, enabled = false, zones = [], clashes = [], version = 0;
let cache = { key: null, batches: [] };
const say = s => { layer.status = s; };
const describe = () => (enabled ? `${zones.length} zones, ${clashes.length} clashes` : 'off');
const layer = {
id: 'buffers',
status: 'waiting for init',
init(a) {
api = a;
if (a.config?.enabled) enabled = true;
say(describe());
},
setEnabled(on) { enabled = !!on; say(describe()); api?.invalidate({ ground: false }); return enabled; },
get enabled() { return enabled; },
// zones: [{ id, layer, rule, kind, rings }] in local metres. Anything without rings is ignored.
setZones(list) {
zones = (Array.isArray(list) ? list : []).filter(z => z && Array.isArray(z.rings))
.map(z => ({ id: String(z.id), layer: z.layer, rule: z.rule, kind: z.kind, rings: z.rings.filter(r => Array.isArray(r) && r.length > 2) }));
version++; say(describe()); api?.invalidate({ ground: false });
return zones.length;
},
// clashes: [{ zone, item, at: [x, y] }] from checkClashes.
setClashes(list) {
clashes = (Array.isArray(list) ? list : []).filter(c => c && Array.isArray(c.at) && Number.isFinite(c.at[0]) && Number.isFinite(c.at[1]));
version++; say(describe()); api?.invalidate({ ground: false });
return clashes.length;
},
// ctx: { pos, heightAt, groundVersion }
lines(ctx) {
if (!enabled || (!zones.length && !clashes.length)) return [];
const known = typeof ctx.known === 'function' ? ctx.known : undefined;
const key = `buffers@${version}@${ctx.groundVersion || 0}`;
if (cache.key === key && cache.heightAt === ctx.heightAt) return cache.batches;
const batches = [];
for (const z of zones) {
const pieces = z.rings.flatMap(r => dashRing(r));
if (!pieces.length) continue;
const [x, y] = z.rings[0][0], o = [x, y, finite(ctx.heightAt(x, y))];
batches.push({ key: `buffers/zone/${z.id}`, version: key, origin: o, color: COLORS[z.layer] || OTHER,
positions: drapePieces(pieces, ctx.heightAt, LIFT_M, o, known) });
}
if (clashes.length) {
const [x, y] = clashes[0].at, o = [x, y, finite(ctx.heightAt(x, y))], c = CROSS_M / 2;
const pieces = clashes.flatMap(({ at: [px, py] }) => [[px - c, py - c, px + c, py + c], [px - c, py + c, px + c, py - c]]);
batches.push({ key: 'buffers/clashes', version: key, origin: o, color: COLORS.clash, positions: drapePieces(pieces, ctx.heightAt, LIFT_M * 2, o, known) });
}
cache = { key, heightAt: ctx.heightAt, batches };
return batches;
},
// For tests and the console.
debug: () => ({ enabled, zones: zones.length, clashes: clashes.length, version })
};
return layer;
}
export default createBuffers();Ground
A JavaScript module in the layers folder of GlobalGrid2050 that works with dist to line (`distToLine`) and along route (`alongRoute`) and calculates planar distances, using SHA-256 and point in polygon.
ingestglobalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs · lines 1–261 of 261 · version 2026-09-27 00:05 · pattern distToLine (shared by 2 files)
- What it does
- It lists and searches its content. Defines 30 functions or classes, including isPt, ringsOf, inside, bbox, areaItem.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid).
- Downstream impact
- Used directly by 1 file: Cmd Run (globalgrid2050). Reached from 2 other entry points, including Solar Design Studio — Site World Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609271853-site-world/); Substrate (globalgrid2050).
- What it achieves
- It parses ground file (`parseGroundFile`) and is built from the is pt helper (`isPt`) and the rings of helper (`ringsOf`). A desktop study of what lies under the site, from a per-site file (`ground.json`) written by the LiDAR pipeline from public geological, mining and groundwater sources.
- Why it matters
- Imported by Cmd Run.
- Application
- globalgrid2050 · solar-design-studio/202609270005-site-world-v3/world/layers · JavaScript module
- Uses
- none found
- Used by
- imported by Cmd Run (import), mentioned in Standalone (comment link)
- Produces
- COLORS, STICK_M, KEYS, ringsOf, inside, sourcesOf, parseGroundFile, at, distToLine, crossings, alongRoute, drapeRings
- Defines here
- isPt, ringsOf, inside, bbox, areaItem, text, sourcesOf, parseGroundFile, list, unit, point, hit, at, pick, distToLine, cuts, crossings, add, alongRoute, within, drapeRings, P, buildGround, local, push, groundStatus, n, createGround, load, origin
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs:1-261 · blob 22d641855b44d9bce3f4f519b7ccca047e1d4de2 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
// Layer: ground. A desktop study of what lies under the site, from a per-site file (ground.json) written by the
// lidar pipeline from public geological, mining and groundwater sources. Self-contained: no imports (it runs from a
// blob URL). Off by default: it is switched on in the Layers panel (Planning group, "Ground").
//
// Config (manifest): { path, sha256 } of the site file, fetched through the substrate's hash check. File shape
// (British National Grid metres; a polygon is a list of [e, n] rings, or a list of such polygons):
// { sources: [{ id, title, licence, attribution, limitations?, scans?: { link_only } }] (or { <key>: {...} }),
// bedrock: [{ polygon, code, name, status }], superficial: [same],
// boreholes: [{ e, n, id, drilled_length_m?, log_url? }], mining: [{ polygon, type }], mine_entries: [{ e, n, type }],
// aquifers: [{ polygon, name|type|designation }], spz: [{ polygon, zone|name|type }],
// thermal?: [{ polygon? | e, n, conductivity, conductivity_unit, status, source, ... }] (soil repo contract) }
// null means not imported and stays missing: the layer says "not in this file", never "none". [] means queried, none.
// Items may name their source (item.source = a source id); otherwise the source is matched by its id.
//
// Drawn quietly on the ground: superficial and bedrock boundaries as faint lines, boreholes as short sticks, mining
// areas as dashed outlines, mine entries as small rings. It measures nothing; the readout is a desktop study only.
export const COLORS = {
superficial: [0.86, 0.76, 0.52, 0.34],
bedrock: [0.66, 0.60, 0.92, 0.30],
borehole: [0.88, 0.90, 0.82, 0.70],
mining: [1.00, 0.58, 0.36, 0.55],
entry: [1.00, 0.46, 0.36, 0.70],
};
export const STICK_M = 3, RING_M = 4, DRAPE_M = 8, LIFT_M = 0.15, DASH = [6, 4];
export const KEYS = ['bedrock', 'superficial', 'boreholes', 'mining', 'mine_entries', 'aquifers', 'spz', 'thermal'];
const isPt = p => Array.isArray(p) && p.length >= 2 && Number.isFinite(p[0]) && Number.isFinite(p[1]);
// Pure: any polygon shape (one ring, rings, or a multipolygon) -> flat list of rings of at least 3 points.
export function ringsOf(poly) {
if (!Array.isArray(poly) || !poly.length) return [];
if (isPt(poly[0])) { const r = poly.filter(isPt); return r.length >= 3 ? [r] : []; }
return poly.flatMap(ringsOf);
}
// Pure: even-odd point in polygon over all rings (holes and multipolygons both come out right).
export function inside(rings, e, n) {
let c = false;
for (const r of rings) {
for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
const [xi, yi] = r[i], [xj, yj] = r[j];
if ((yi > n) !== (yj > n) && e < (xj - xi) * (n - yi) / (yj - yi) + xi) c = !c;
}
}
return c;
}
const bbox = rings => {
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
for (const r of rings) for (const [x, y] of r) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
return [x0, y0, x1, y1];
};
const areaItem = (it, label) => { const rings = ringsOf(it?.polygon); return rings.length ? { ...it, rings, box: bbox(rings), label: label(it) } : null; };
const text = (...v) => v.find(s => typeof s === 'string' && s.trim()) || '';
// Which source ids feed which list, when the items do not say: matched on the source id.
const MATCH = { bedrock: /bedrock/, superficial: /superficial/, boreholes: /borehole|sobi/, mining: /coal|mining|high-risk/,
mine_entries: /entr/, aquifers: /aquifer/, spz: /spz|source-protection/, thermal: /thermal/ };
// Pure: the sources block as { <list key>: source } (bedrock, superficial, boreholes, mining, ...).
export function sourcesOf(j) {
const s = j?.sources, byId = {}, out = {};
if (Array.isArray(s)) { for (const x of s) if (x && (x.id || x.key)) byId[x.id || x.key] = x; }
else if (s && typeof s === 'object') Object.assign(byId, s);
for (const k of KEYS) {
const named = Array.isArray(j?.[k]) ? j[k].find(it => it && byId[it.source])?.source : null;
const id = named || (k in byId ? k : Object.keys(byId).find(i => MATCH[k].test(i) && !(k === 'mining' && /entr/.test(i))));
if (id && byId[id]) out[k] = byId[id];
}
return out;
}
// Pure: the file -> model. Each list is null when the file does not carry it (missing stays missing).
export function parseGroundFile(j) {
if (!j || typeof j !== 'object' || Array.isArray(j)) throw Error('ground file is not an object');
if (!KEYS.some(k => Array.isArray(j[k]))) throw Error('ground file has none of ' + KEYS.join(', '));
const list = (k, f) => (Array.isArray(j[k]) ? j[k].map(f).filter(Boolean) : null);
const unit = it => text(it.name, it.code, 'unnamed unit');
const point = it => (it && Number.isFinite(it.e) && Number.isFinite(it.n) ? it : null);
return {
sources: sourcesOf(j),
bedrock: list('bedrock', it => areaItem(it, unit)),
superficial: list('superficial', it => areaItem(it, unit)),
boreholes: list('boreholes', point),
mining: list('mining', it => areaItem(it, x => text(x.type, x.name, 'mining area'))),
mine_entries: list('mine_entries', point),
aquifers: list('aquifers', it => areaItem(it, x => text(x.designation, x.name, x.type, 'aquifer'))),
spz: list('spz', it => areaItem(it, x => text(x.zone != null ? `SPZ ${x.zone}` : '', x.name, x.type, 'source protection zone'))),
thermal: list('thermal', it => (it && (ringsOf(it.polygon).length || point(it)) ? { ...it, rings: ringsOf(it.polygon) } : null)),
};
}
const hit = (a, e, n) => e >= a.box[0] && e <= a.box[2] && n >= a.box[1] && n <= a.box[3] && inside(a.rings, e, n);
// Pure: what is mapped at (e, n). Each entry is null when the file has no such list, [] when nothing is mapped there.
export function at(model, e, n) {
const pick = k => (model[k] ? model[k].filter(a => hit(a, e, n)) : null);
return { superficial: pick('superficial'), bedrock: pick('bedrock'), mining: pick('mining'), aquifers: pick('aquifers'), spz: pick('spz') };
}
// Pure: distance from (e, n) to a polyline [[e, n], ...].
export function distToLine(path, e, n) {
if (path.length === 1) return Math.hypot(e - path[0][0], n - path[0][1]);
let best = Infinity;
for (let k = 0; k + 1 < path.length; k++) {
const [ax, ay] = path[k], [bx, by] = path[k + 1], dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy;
const f = L2 ? Math.min(1, Math.max(0, ((e - ax) * dx + (n - ay) * dy) / L2)) : 0;
best = Math.min(best, Math.hypot(ax + dx * f - e, ay + dy * f - n));
}
return best;
}
// Pure: parameters (0..1) where segment a->b crosses the edges of the rings.
function cuts(rings, a, b) {
const out = [], rx = b[0] - a[0], ry = b[1] - a[1];
for (const r of rings) for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
const [px, py] = r[j], sx = r[i][0] - px, sy = r[i][1] - py, den = rx * sy - ry * sx;
if (!den) continue;
const t = ((px - a[0]) * sy - (py - a[1]) * sx) / den, u = ((px - a[0]) * ry - (py - a[1]) * rx) / den;
if (t > 0 && t < 1 && u >= 0 && u <= 1) out.push(t);
}
return out;
}
// Pure: lengths of the route (plan metres) within each area of a list, keyed by label, in route order.
// Where no area of the list covers a stretch, its length goes to `gap` (e.g. "not mapped"). null if the list is missing.
export function crossings(areas, path, gap = 'not mapped') {
if (!areas) return null;
if (!areas.length) return []; // queried, none mapped
const out = new Map();
const add = (k, d) => out.set(k, (out.get(k) || 0) + d);
for (let k = 0; k + 1 < path.length; k++) {
const a = path[k], b = path[k + 1], L = Math.hypot(b[0] - a[0], b[1] - a[1]);
if (!L) continue;
const ts = [0, 1, ...areas.flatMap(x => cuts(x.rings, a, b))].sort((p, q) => p - q);
for (let i = 0; i + 1 < ts.length; i++) {
const d = (ts[i + 1] - ts[i]) * L;
if (d < 1e-9) continue;
const m = (ts[i] + ts[i + 1]) / 2, e = a[0] + (b[0] - a[0]) * m, n = a[1] + (b[1] - a[1]) * m;
const found = areas.filter(x => hit(x, e, n));
if (!found.length) add(gap, d); else for (const x of found) add(x.label, d);
}
}
return [...out].map(([label, length]) => ({ label, length }));
}
// Pure: everything the route readout needs, for a route in national-grid metres. near: search radius, metres.
export function alongRoute(model, path, near = 250) {
const pts = path.filter(isPt);
if (!pts.length) return null;
const within = list => (list ? list.map(p => ({ ...p, distance: distToLine(pts, p.e, p.n) })).filter(p => p.distance <= near)
.sort((a, b) => a.distance - b.distance) : null);
const thermal = model.thermal ? model.thermal.filter(t => (t.rings.length ? pts.some(([e, n]) => inside(t.rings, e, n))
: distToLine(pts, t.e, t.n) <= near)) : null;
return {
superficial: crossings(model.superficial, pts, 'no superficial deposit mapped'),
bedrock: crossings(model.bedrock, pts),
mining: crossings(model.mining, pts)?.filter(c => c.label !== 'not mapped') ?? null,
aquifers: crossings(model.aquifers, pts)?.filter(c => c.label !== 'not mapped') ?? null,
spz: crossings(model.spz, pts)?.filter(c => c.label !== 'not mapped') ?? null,
boreholes: within(model.boreholes), mine_entries: within(model.mine_entries), thermal, near,
};
}
// ---- drawing ------------------------------------------------------------------------------------------
// Pure: line pairs for every ring, draped on heightAt every DRAPE_M or less, relative to o; dash: [on, off] or null.
export function drapeRings(rings, local, heightAt, o, dash = null) {
const out = [];
const P = (x, y) => [x - o[0], y - o[1], heightAt(x, y) + LIFT_M - o[2]];
for (const r of rings) for (let i = 0; i < r.length; i++) {
const [ax, ay] = local(r[i][0], r[i][1]), [bx, by] = local(r[(i + 1) % r.length][0], r[(i + 1) % r.length][1]);
const L = Math.hypot(bx - ax, by - ay);
if (!L) continue;
const marks = [];
if (dash) { for (let s = 0; s < L; s += dash[0] + dash[1]) marks.push([s, Math.min(L, s + dash[0])]); }
else marks.push([0, L]);
for (const [s0, s1] of marks) {
const m = Math.max(1, Math.ceil((s1 - s0) / DRAPE_M));
for (let k = 0; k < m; k++) {
const f0 = (s0 + (s1 - s0) * k / m) / L, f1 = (s0 + (s1 - s0) * (k + 1) / m) / L;
out.push(...P(ax + (bx - ax) * f0, ay + (by - ay) * f0), ...P(ax + (bx - ax) * f1, ay + (by - ay) * f1));
}
}
}
return out;
}
// Pure: every batch for the model at the given origin and ground.
export function buildGround(model, origin, heightAt) {
const local = (e, n) => [e - origin.e, n - origin.n], batches = [];
const o = [0, 0, Number.isFinite(heightAt(0, 0)) ? heightAt(0, 0) : 0];
const push = (key, color, pos) => { if (pos.length >= 6) batches.push({ key: `ground/${key}`, origin: o, color, positions: new Float32Array(pos) }); };
for (const k of ['bedrock', 'superficial']) push(k, COLORS[k], (model[k] || []).flatMap(a => drapeRings(a.rings, local, heightAt, o)));
push('mining', COLORS.mining, (model.mining || []).flatMap(a => drapeRings(a.rings, local, heightAt, o, DASH)));
const sticks = [];
for (const b of model.boreholes || []) {
const [x, y] = local(b.e, b.n), z = heightAt(x, y) - o[2];
sticks.push(x - o[0], y - o[1], z, x - o[0], y - o[1], z + STICK_M);
}
push('boreholes', COLORS.borehole, sticks);
const rings = [];
for (const m of model.mine_entries || []) {
const ring = [];
for (let k = 0; k < 16; k++) { const a = k / 16 * 2 * Math.PI; ring.push([m.e + RING_M * Math.cos(a), m.n + RING_M * Math.sin(a)]); }
rings.push(...drapeRings([ring], local, heightAt, o));
}
push('entries', COLORS.entry, rings);
return batches;
}
// Pure: the status line.
export function groundStatus(model) {
const n = k => (model[k] ? String(model[k].length) : 'not in file');
return `ground: ${n('superficial')} superficial, ${n('bedrock')} bedrock, ${n('boreholes')} boreholes, ` +
`${n('mining')} mining areas, ${n('mine_entries')} mine entries; desktop study only`;
}
export function createGround() {
let api = null, model = null, state = 'idle'; // idle | loading | ready | failed
let built = { version: null, batches: [] };
function load() {
if (state !== 'idle' || !api) return;
const path = api.config?.path, sha = api.config?.sha256;
if (!path || !sha) { state = 'failed'; layer.status = 'no ground file configured (config.path and config.sha256)'; return; }
state = 'loading'; layer.status = 'loading ' + path;
Promise.resolve().then(() => api.fetchJSON(path, sha)).then(j => {
model = parseGroundFile(j); state = 'ready'; layer.status = groundStatus(model);
api.invalidate({ ground: false });
}).catch(e => { state = 'failed'; layer.status = 'ground file failed: ' + e.message; });
}
const origin = () => (api && typeof api.origin === 'function' ? api.origin() : { e: 0, n: 0, id: 0 });
const layer = {
id: 'ground',
status: 'off until switched on',
// Nothing is fetched at start: the file loads the first time the layer is drawn (switched on).
init(a) { api = a; },
lines(ctx) {
if (!api) return [];
if (state === 'idle') load();
if (state !== 'ready') return [];
const o = origin(), heightAt = typeof ctx.heightAt === 'function' ? ctx.heightAt : () => 0;
const version = `${o.e},${o.n},${o.id}@${ctx.groundVersion ?? 0}`;
if (built.version === version) return built.batches;
try { built = { version, batches: buildGround(model, o, heightAt).map(b => ({ ...b, version })) }; }
catch (e) { built = { version, batches: [] }; layer.status = 'ground build failed: ' + e.message; }
return built.batches;
},
ready: () => state === 'ready',
// National-grid (e, n) -> what is mapped there, with the sources; null until the file has loaded.
underfoot: (e, n) => (model ? { ...at(model, e, n), sources: model.sources } : null),
// Route [[e, n], ...] in national-grid metres -> crossings, boreholes, mining; null until loaded.
alongRoute: (path, near) => (model ? { ...alongRoute(model, path, near), sources: model.sources } : null),
debug: () => ({ state, model, version: built.version })
};
return layer;
}
export default createGround();Links
A JavaScript module in the world folder of GlobalGrid2050 that uses Helmert using data from the GridAtlas repository.
ingestglobalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/links.mjs · lines 1–100 of 100 · version 2026-09-27 00:05 · Entry point · pattern onGrid (shared by 3 files)
- What it does
- Defines 8 functions or classes, including round, onGrid, inBritain, strip, gridAtlasUrl.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid).
- Downstream impact
- Used directly by 6 files: Solar Design Studio — Site World V3 Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609270402-site-world-v3/); Substrate (globalgrid2050); Solar Design Studio — Site World Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609271853-site-world/); Build Mount (globalgrid2050); and 2 more. Reached from 2 other entry points, including Graphics Engines Open Source — Versions Page (graphics-engines-open-source, https://ventusltd.github.io/graphics-engines-open-source/web/versions/); Versions — Site World Page (graphics-engines-open-source, https://ventusltd.github.io/graphics-engines-open-source/web/versions/202609262227-site-world/).
- What it achieves
- It parses world URL (`parseWorldUrl`) and is built from the round step (`round`) and the on grid helper (`onGrid`). Links out of the world and back in.
- Why it matters
- Loaded by the Site World V3 page at https://globalgrid2050.com/solar-design-studio/202609270402-site-world-v3/ and 1 other page. Also imported by 4 files, including Substrate and Build Mount, from Graphics Engines Open Source.
- Application
- globalgrid2050 · solar-design-studio/202609270005-site-world-v3/world · JavaScript module
- Uses
- Bng (import), Origin (import), GridAtlas — Atlas Page (estate URL), GlobalGrid2050 — Renewable Energy Planning Database (REPD) Grid Atlas v8 Page (estate URL)
- Used by
- preloaded by Solar Design Studio — Site World V3 Page (modulepreload), imported by Substrate (import), preloaded by Solar Design Studio — Site World Page (modulepreload), imported by Build Mount (import), imported by Substrate (import), imported by Substrate (import)
- Produces
- GRIDATLAS_RECEIVER, DEFAULT_ZOOM, WORLD_VIEWS, gridAtlasUrl, worldUrl, parseWorldUrl
- Defines here
- round, onGrid, inBritain, strip, gridAtlasUrl, worldUrl, parseWorldUrl, num
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270005-site-world-v3/world/links.mjs:1-100 · blob e2e7839cdfc762174b0c0b720b40d2199e0f515b · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
// Links out of the world and back in. Pure: no DOM, no fetch; only bng.mjs and origin.mjs.
//
// OUT: gridAtlasUrl opens GridAtlas at the spot the viewer stands. It carries only latitude,
// longitude and zoom, the location half of the MAP-button contract
// (ventus-grid-engine deeplink/contract.js PARAMS). It never sends repd_ref: the world does not
// know which project, if any, the viewer stands on, and an invented identity is worse than none.
// IN: worldUrl / parseWorldUrl are the world's own landing link, so GridAtlas (or anyone) can
// send a reader back to stand on the same ground. lat/lon win over e/n when both are present.
//
// Coordinates are rounded to 6 decimal places (about 0.11 m north-south), finer than the 3-5 m the
// Helmert transform in bng.mjs is good for against the real National Grid. A round trip therefore
// closes to about 0.1 m, which proves the pair are consistent, not that either spot is surveyed.
import { bngToWgs84, wgs84ToBng } from './bng.mjs';
import { toBng } from './origin.mjs';
// Same value as CANONICAL_RECEIVER in ventus-grid-engine deeplink/contract.js. Copied, not imported,
// because the two repos do not import each other; tests/links.test.mjs pins the string.
export const GRIDATLAS_RECEIVER = 'https://ventusltd.github.io/gridatlas/atlas/';
const RETIRED = ['https://globalgrid2050.com/repd_grid_atlasv8'];
export const DEFAULT_ZOOM = 15;
export const WORLD_VIEWS = Object.freeze(['standing', 'aerial']);
const round = (v, dp) => { const k = 10 ** dp; const r = Math.round(v * k) / k; return r === 0 ? 0 : r; };
const onGrid = (e, n) => Number.isFinite(e) && Number.isFinite(n) && e >= 0 && e < 700000 && n >= 0 && n < 1300000;
// Great Britain and its waters, generously. Anything outside is a broken number, not a place.
const inBritain = (lat, lon) => lat >= 49 && lat <= 61.5 && lon >= -9.5 && lon <= 2.5;
const strip = s => String(s).split('?')[0].split('#')[0].replace(/\/+$/, '');
/**
* The GridAtlas link for where the viewer stands, or null when the world is not placed.
* origin: { e, n } British National Grid metres; pos: local [x, y, ...] metres from it.
* Returns null (never a link to the sea off Scilly) when no site has set the origin (0, 0),
* or when the point is off the National Grid.
*/
export function gridAtlasUrl({ origin, pos, zoom = DEFAULT_ZOOM, base = GRIDATLAS_RECEIVER } = {}) {
if (!origin || !Array.isArray(pos)) return null;
if (origin.e === 0 && origin.n === 0) return null; // the unplaced world: 0, 0 is the grid's false origin
if (RETIRED.includes(strip(base))) throw new Error(`gridAtlasUrl: ${base} is a retired receiver`);
const { e, n } = toBng(origin, pos[0], pos[1]);
if (!onGrid(e, n)) return null;
const { lat, lon } = bngToWgs84(e, n);
const z = Number.isFinite(zoom) ? Math.min(22, Math.max(0, zoom)) : DEFAULT_ZOOM;
const url = new URL(base);
url.search = '';
url.searchParams.set('latitude', String(round(lat, 6)));
url.searchParams.set('longitude', String(round(lon, 6)));
url.searchParams.set('zoom', String(round(z, 2)));
return url.href;
}
/**
* The world's landing link. base: the world page URL. yaw in radians (as state.yaw), written as
* degrees 0-360 to 1 dp; alt: metres above the ground, drone only, 1 dp; gen: the world generation.
* Absent or non-finite fields are left out rather than written as NaN.
*/
export function worldUrl(base, { lat, lon, view, yaw, alt, gen } = {}) {
if (!Number.isFinite(lat) || !Number.isFinite(lon)) throw new Error('worldUrl needs finite lat and lon');
const url = new URL(base);
url.search = '';
url.searchParams.set('lat', String(round(lat, 6)));
url.searchParams.set('lon', String(round(lon, 6)));
if (WORLD_VIEWS.includes(view)) url.searchParams.set('view', view);
if (Number.isFinite(yaw)) {
const deg = ((yaw * 180 / Math.PI) % 360 + 360) % 360;
url.searchParams.set('yaw', String(round(deg, 1) % 360));
}
if (Number.isFinite(alt) && view === 'aerial') url.searchParams.set('alt', String(round(Math.max(0, alt), 1)));
if (gen != null && gen !== '') url.searchParams.set('gen', String(gen));
return url.href;
}
/**
* Read a landing link's query string ('?lat=..' or 'lat=..' or a URLSearchParams).
* Returns null when it names no usable place. Otherwise { lat, lon, e, n, view, yaw, alt, gen }:
* both coordinate pairs are always filled, from lat/lon when those are valid, else from e/n.
* yaw comes back in radians; view, yaw, alt and gen are null when absent or unusable.
*/
export function parseWorldUrl(search) {
const q = search instanceof URLSearchParams ? search : new URLSearchParams(String(search ?? ''));
const num = k => { const s = q.get(k); if (s === null || s.trim() === '') return NaN; return Number(s); };
let lat = num('lat'), lon = num('lon'), e, n;
if (Number.isFinite(lat) && Number.isFinite(lon) && inBritain(lat, lon)) {
({ e, n } = wgs84ToBng(lat, lon));
if (!onGrid(e, n)) return null;
} else {
e = num('e'); n = num('n');
if (!onGrid(e, n)) return null;
({ lat, lon } = bngToWgs84(e, n));
}
const view = WORLD_VIEWS.includes(q.get('view')) ? q.get('view') : null;
const yawDeg = num('yaw'), altM = num('alt');
return {
lat: round(lat, 6), lon: round(lon, 6), e, n, view,
yaw: Number.isFinite(yawDeg) ? ((yawDeg % 360 + 360) % 360) * Math.PI / 180 : null,
alt: Number.isFinite(altM) && altM >= 0 ? altM : null,
gen: q.get('gen') || null
};
}Measure Format
A JavaScript module in the world folder of GlobalGrid2050 that works with cables. It formats number (`formatNumber`), formats length (`formatLength`) and formats area (`formatArea`).
transformglobalgrid2050 / solar-design-studio/202609270005-site-world-v3/world/measure-format.mjs · lines 1–86 of 86 · version 2026-09-27 00:05 · pattern formatPlatformLine (shared by 4 files)
- What it does
- It calculates cables. Defines 11 functions or classes, including formatNumber, formatLength, formatArea, formatVolume, formatGradient.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables.
- Downstream impact
- Used directly by 9 files: Cable Checks UI (globalgrid2050); Ground Readout (globalgrid2050); Design Earthworks (globalgrid2050); Design Ground (globalgrid2050); and 5 more. Reached from 3 other entry points, including Graphics Engines Open Source — Versions Page (graphics-engines-open-source, https://ventusltd.github.io/graphics-engines-open-source/web/versions/); Versions — Site World Page (graphics-engines-open-source, https://ventusltd.github.io/graphics-engines-open-source/web/versions/202609262227-site-world/); Substrate (graphics-engines-open-source).
- What it achieves
- Plain British English lines from the numbers `measure.mjs` returns.
- Why it matters
- Imported by 9 files, including Cable Checks UI, Ground Readout and Design Earthworks, from Graphics Engines Open Source.
- Application
- globalgrid2050 · solar-design-studio/202609270005-site-world-v3/world · JavaScript module
- Uses
- none found
- Used by
- imported by Cable Checks UI (import), imported by Ground Readout (import), imported by Design Earthworks (import), imported by Design Ground (import), imported by Design UI (import), imported by Plant UI (import), imported by Block UI (import), imported by Design Sections (import), and 1 more, mentioned in Standalone (comment link)
- Produces
- formatNumber, formatLength, formatArea, formatVolume, formatGradient, formatTrenchLine, formatCableLine, formatPlatformLine, formatProfileLine
- Defines here
- formatNumber, formatLength, formatArea, formatVolume, formatGradient, plural, belowPhrase, formatTrenchLine, formatCableLine, formatPlatformLine, formatProfileLine
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270005-site-world-v3/world/measure-format.mjs:1-86 · blob 17588d576f572365d5f5abe8bbc4683e522bd2f1 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
// measure-format.mjs: plain British English lines from the numbers measure.mjs
// returns. Pure: no imports, no DOM. Parts are joined with " · ", for example
// "Trench 124.6 m (3D 125.1 m) · spoil 98.4 m³ · 1 bend below 1.05 m"
// Inputs are the summary objects from measure.mjs (trenchSummary, cableSummary,
// cutFillForPlatform, profile); nothing is recomputed here.
const SEP = ' · ';
/** 1234.56 -> "1,234.6" (comma thousands, point decimal). */
export function formatNumber(x, dp = 1) {
if (x == null || !Number.isFinite(x)) return 'n/a';
const v = Math.abs(x) < 0.5 * 10 ** -dp ? 0 : x; // no "-0.0"
const [i, f] = Math.abs(v).toFixed(dp).split('.');
const grouped = i.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return (v < 0 ? '-' : '') + grouped + (f ? '.' + f : '');
}
export const formatLength = (m, dp = 1) => `${formatNumber(m, dp)} m`;
export const formatArea = (m2, dp = 1) => `${formatNumber(m2, dp)} m²`;
export const formatVolume = (m3, dp = 1) => `${formatNumber(m3, dp)} m³`;
/** 0.05 -> "5.0 % (1 in 20)"; 0 -> "level". */
export function formatGradient(g, dp = 1) {
if (g == null || !Number.isFinite(g)) return 'n/a';
if (Math.abs(g) < 1e-6) return 'level';
return `${formatNumber(g * 100, dp)} % (1 in ${formatNumber(1 / Math.abs(g), 0)})`;
}
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
// "1 bend below 1.05 m", "no bends below 1.05 m", or "" when no rule applies.
function belowPhrase(cs) {
if (!cs || cs.required.radius == null) return '';
const r = formatNumber(cs.required.radius, 2);
return cs.below.length ? `${plural(cs.below.length, 'bend', 'bends')} below ${r} m` : `no bends below ${r} m`;
}
/**
* "Trench 124.6 m (3D 125.1 m) · spoil 98.4 m³ · 1 bend below 1.05 m"
* ts from trenchSummary; cs (optional) from cableSummary for the cable it carries.
*/
export function formatTrenchLine(ts, cs = null) {
let head = `Trench ${formatLength(ts.length2d)}`;
if (ts.length3d != null) head += ` (3D ${formatLength(ts.length3d)})`;
const parts = [head];
if (ts.spoil != null) parts.push(`spoil ${formatVolume(ts.spoil)}`);
const b = belowPhrase(cs);
if (b) parts.push(b);
return parts.join(SEP);
}
/** "Cable 132.4 m (3D 133.0 m) · final radius 0.77 m (15 × OD 51.5 mm) · no bends below 0.77 m" */
export function formatCableLine(cs) {
const parts = [`Cable ${formatLength(cs.length2d)} (3D ${formatLength(cs.length3d)})`];
const r = cs.required;
if (r.radius == null) {
parts.push(`no ${r.when} bend rule for this cable`);
} else {
let od = `OD ${formatNumber(cs.cable.odMm, 1)} mm`;
if (cs.cable.odStatus === 'estimated') od += ' estimated';
parts.push(`${r.when} radius ${formatNumber(r.radius, 2)} m (${formatNumber(r.multiple, 3).replace(/\.?0+$/, '')} × ${od})`);
parts.push(belowPhrase(cs));
}
return parts.join(SEP);
}
/** "Platform 600.0 m² at 12.30 m · cut 410.2 m³ · fill 388.9 m³ · net 21.3 m³ cut" */
export function formatPlatformLine(cf) {
const net = cf.cut - cf.fill;
const netText = Math.abs(net) < 0.05 ? 'balanced' : `net ${formatVolume(Math.abs(net))} ${net > 0 ? 'cut' : 'fill'}`;
return [
`Platform ${formatArea(cf.area)} at ${formatNumber(cf.level, 2)} m`,
`cut ${formatVolume(cf.cut)}`,
`fill ${formatVolume(cf.fill)}`,
netText,
].join(SEP);
}
/** "Profile 100.0 m (3D 100.1 m) · ground 0.00 to 5.00 m · steepest 5.0 % (1 in 20)" */
export function formatProfileLine(p) {
return [
`Profile ${formatLength(p.length2d)} (3D ${formatLength(p.length3d)})`,
`ground ${formatNumber(p.min, 2)} to ${formatNumber(p.max, 2)} m`,
`steepest ${formatGradient(p.gradient.max)}`,
].join(SEP);
}