GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / stars / library

Standalone (part 16)

A JavaScript module in the library folder of Stars that maps Renewable Energy Planning Database (REPD) master and heavy emitters UK, using SHA-256, and uses data from the GridAtlas repository.

700 lines of JavaScript from stars, in 1 file. Topic: Kuiper, cosmos and drawing engines. Section 1578 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Standalone geodesy · stars / library/standalone.mjs lines 11040–11739

Standalone

A JavaScript module in the library folder of Stars that maps Renewable Energy Planning Database (REPD) master and heavy emitters UK, using SHA-256, and uses data from the GridAtlas repository.

Set aside from the main view: A comment at the top of the file says a tool wrote it. (noise-generated, proposed by noise.py). All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line 2 comment: // Generated by the modular star 2026-12-05T23:26:43.596Z. Each export is one family's earliest-seen copy, unchanged; the comment links its source.

geodesystars / library/standalone.mjs · lines 11040–11739 of 12585 (continued from section 1562) · Entry point · pattern segmentConductors (shared by 2 files)

What it does
It maps REPD master, heavy emitters UK, notice and substations. Defines 1111 functions or classes, including f1586_invariant, f8767_representativePoint, f8768_voltagesKv, f8772_voltageOf, f8773_ratingsOf. Side effects: changes the web page (DOM); reads or writes files; makes network requests; uses storage (browser storage, DuckDB or Parquet).
Why it exists in the grid workflow
Domain terms in the code: substations, 750kV, 400kV, 275kV, 132kV, 66kV.
Inputs & outputs
In: data source: gridatlas data; JSON file repd_master.json; JSON file heavy_emitters_uk.json; JSON file notice.json; form fields (user input). Out: canvas drawing. Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid), WGS84 / EPSG:4326. Voltage levels named: 750kV, 400kV, 275kV, 132kV, 66kV, 33kV, 1.5kV, 1500V.
Downstream impact
Used directly by 4 files: Code (stars, https://ventusltd.github.io/stars/code.html); Proof (stars); Modular Star Workflow (stars); Testcode — Code Record Page (globalgrid2050, https://globalgrid2050.com/testcode/202609141754/code-record/). Reached from 383 other entry points, including Code Generator — Index Page (code-generator, https://ventusltd.github.io/code-generator/); Generate (code-generator, https://ventusltd.github.io/code-generator/); 404 (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/404.html).
What it achieves
It snaps coordinate (`snapCoordinate`), paints cursor (`paintCursor`) and sets plan (`setPlan`). Compiled library of self-contained JavaScript functions that appear in two or more places across Ventusltd code. Its code works with 33 kV, 132 kV and 275 kV. It responds to abort events.
Why it matters
Loaded by the Code page at https://ventusltd.github.io/stars/code.html and 1 other page. Run by Proof and Modular Star Workflow.
Application
stars · library · JavaScript module
VEDIC
MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
VEDIC
REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
VEDIC
VOLTAGE (GG2050-VEDIC-000003): GridAtlas / Geodesy · Computer science / Data normalisation. voltage_properties → kilovolt_list
Uses
GlobalGrid2050 — Renewable Energy Planning Database (REPD) Grid Atlas v8 Page (estate URL), Declared Connections (estate URL)
Used by
named by URL in Code (estate URL), run by Proof (script call), run by Modular Star Workflow (workflow run), named by URL in Testcode — Code Record Page (estate URL)
Produces
f1586_invariant, f8767_representativePoint, f8768_voltagesKv, f8772_voltageOf, f8773_ratingsOf, f8775_parametersOf, f5168_escapeHTML, f8321_suppliedArrivalFields, f8850__anonymous_, f8786_crossing, f8788_legality, f8789_startNodes
Defines here
f145227_toPlan, f145228_toWorld, f145229_headingOnPlan, f145231_formatDistance, f145233_planSize, f145244_niceBelow, f145246_batchBounds, f145248_planToPaper, f145254_bearingText, f145257_sheetDate, f145260_dateYear, f145265_inkFor, f145266_clipSegment, f145273_sheetFileName, p, f145284_save, f145303_frame, f145305_densify, f145306_finishedAtPoint, f145309_daylight, raw, f145324_jitter, f145368_siteLabel, f145373_bearingDeg, f145377_measuredShare, f145378_snapRing, f145420_sha256, f145426_hermite, f145429_captionAt, f145458_rotYaw
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
stars@030ebc202d35959fecd162327892f671d1d9a0cc library/standalone.mjs:11040-11739 · blob fc3d8c8b93e14d4a56b8a26da47071d60bc5bc4d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network, storage · domain stage: unknown · users: none · canonical: unknown
  return { severity, code, message, ...extra };
};

// Family #145227 · element #145227 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/plan-inset.mjs#L45-L47
export const f145227_toPlan = function toPlan(f, x, y) {
  return [f.w / 2 + (x - f.cx) * f.scale, f.h / 2 - (y - f.cy) * f.scale];
};

// Family #145228 · element #145228 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/plan-inset.mjs#L50-L52
export const f145228_toWorld = function toWorld(f, px, py) {
  return [f.cx + (px - f.w / 2) / f.scale, f.cy - (py - f.h / 2) / f.scale];
};

// Family #145229 · element #145229 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/plan-inset.mjs#L55-L57
export const f145229_headingOnPlan = function headingOnPlan(yaw) {
  return [Math.sin(yaw), -Math.cos(yaw)];
};

// Family #145231 · element #145231 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/plan-inset.mjs#L70-L74
export const f145231_formatDistance = function formatDistance(m) {
  if (m >= 1000) return `${+(m / 1000).toFixed(2)} km`;
  if (m >= 1) return `${+m.toFixed(0)} m`;
  return `${+m.toFixed(2)} m`;
};

// Family #145233 · element #145233 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/plan-inset.mjs#L91-L95
export const f145233_planSize = function planSize(vw, vh, coarse) {
  const short = Math.min(vw, vh);
  const side = coarse ? Math.round(short * 0.36) : Math.round(short * 0.24);
  return Math.max(112, Math.min(coarse ? 180 : 200, side));
};

// Family #145244 · element #145244 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-layout.mjs#L46-L51
export const f145244_niceBelow = function niceBelow(v) {
  if (!(v > 0)) throw Error('niceBelow needs a positive value');
  const p = 10 ** Math.floor(Math.log10(v) + 1e-9);
  for (const f of [5, 2, 1]) if (f * p <= v * (1 + 1e-9)) return f * p;
  return p;
};

// Family #145246 · element #145246 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-layout.mjs#L63-L75
export const f145246_batchBounds = function batchBounds(batches) {
  let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
  for (const b of batches || []) {
    if (b.occluder || !b.positions) continue;
    const o = b.origin || [0, 0, 0], p = b.positions;
    for (let i = 0; i + 2 < p.length; i += 3) {
      const x = p[i] + o[0], y = p[i + 1] + o[1];
      if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
      if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y;
    }
  }
  return x0 <= x1 ? { x0, y0, x1, y1 } : null;
};

// Family #145248 · element #145248 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-layout.mjs#L92-L96
export const f145248_planToPaper = function planToPaper(frame, layout, x, y) {
  const d = layout.planDraw;
  return [d.x + d.w / 2 + (x - frame.centre[0]) / frame.mPerMM,
          d.y + d.h / 2 - (y - frame.centre[1]) / frame.mPerMM];
};

// Family #145254 · element #145254 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-layout.mjs#L158-L162
export const f145254_bearingText = function bearingText(yaw) {
  const deg = ((yaw * 180 / Math.PI) % 360 + 360) % 360;
  const names = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
  return `${names[Math.round(deg / 45) % 8]} (${deg.toFixed(0).padStart(3, '0')}°)`;
};

// Family #145257 · element #145257 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-sheet.mjs#L21-L26
export const f145257_sheetDate = function sheetDate(date) {
  const d = date instanceof Date ? date : new Date(date ?? Date.now());
  if (Number.isNaN(d.getTime())) throw Error('sheetDate needs a valid date');
  const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  return `${d.getUTCDate()} ${months[d.getUTCMonth()]} ${d.getUTCFullYear()}`;
};

// Family #145260 · element #145260 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-sheet.mjs#L130-L133
export const f145260_dateYear = function dateYear(date) {
  const d = date instanceof Date ? date : new Date(date ?? Date.now());
  return Number.isNaN(d.getTime()) ? undefined : d.getUTCFullYear();
};

// Family #145265 · element #145265 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-svg.mjs#L18-L22
export const f145265_inkFor = function inkFor(color) {
  const [r, g, b, a = 1] = color || [0.6, 0.6, 0.6, 1];
  const k = 0.55, hex = v => Math.round(Math.max(0, Math.min(1, v * k)) * 255).toString(16).padStart(2, '0');
  return { stroke: `#${hex(r)}${hex(g)}${hex(b)}`, opacity: Math.max(0.3, Math.min(1, a)) };
};

// Family #145266 · element #145266 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print-svg.mjs#L25-L34
export const f145266_clipSegment = function clipSegment(x0, y0, x1, y1, r) {
  let t0 = 0, t1 = 1;
  const dx = x1 - x0, dy = y1 - y0;
  for (const [p, q] of [[-dx, x0 - r.x], [dx, r.x + r.w - x0], [-dy, y0 - r.y], [dy, r.y + r.h - y0]]) {
    if (p === 0) { if (q < 0) return null; continue; }
    const t = q / p;
    if (p < 0) { if (t > t1) return null; if (t > t0) t0 = t; } else { if (t < t0) return null; if (t < t1) t1 = t; }
  }
  return [x0 + t0 * dx, y0 + t0 * dy, x0 + t1 * dx, y0 + t1 * dy];
};

// Family #145273 · element #145273 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/print.mjs#L38-L42
export const f145273_sheetFileName = function sheetFileName(paper, ext, date = new Date()) {
  const p = n => String(n).padStart(2, '0');
  const stamp = `${date.getFullYear()}${p(date.getMonth() + 1)}${p(date.getDate())}-${p(date.getHours())}${p(date.getMinutes())}`;
  return `site-world-${String(paper).toLowerCase()}-${stamp}.${ext}`;
};

// Family #145284 · element #145284 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/project-ui.mjs#L30-L34
export const f145284_save = function save(doc, name, text, type = 'application/json') {
  const url = URL.createObjectURL(new Blob([text], { type })), a = doc.createElement('a');
  a.href = url; a.download = name; doc.body.appendChild(a); a.click();
  setTimeout(() => { URL.revokeObjectURL(url); a.remove(); }, 30000);
};

// Family #145303 · element #145303 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/road-lines.mjs#L10-L17
export const f145303_frame = function frame(road) {
  const pts = road.path, segs = [];
  for (let i = 0; i < pts.length - 1; i++) {
    const [ax, ay] = pts[i], [bx, by] = pts[i + 1], len = Math.hypot(bx - ax, by - ay);
    segs.push({ dx: (bx - ax) / len, dy: (by - ay) / len, nx: -(by - ay) / len, ny: (bx - ax) / len });
  }
  return { pts, segs };
};

// Family #145305 · element #145305 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/road-lines.mjs#L43-L50
export const f145305_densify = function densify(line, every) {
  const out = [line[0]];
  for (let k = 1; k < line.length; k++) {
    const [ax, ay] = line[k - 1], [bx, by] = line[k], m = Math.max(1, Math.ceil(Math.hypot(bx - ax, by - ay) / every));
    for (let q = 1; q <= m; q++) out.push([ax + (bx - ax) * q / m, ay + (by - ay) * q / m]);
  }
  return out;
};

// Family #145306 · element #145306 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/road-lines.mjs#L53-L56
export const f145306_finishedAtPoint = (road, x, y) => {
  const p = road.locate(x, y), half = road.width / 2;
  return p ? road.finishedAt(p.s, Math.max(-half, Math.min(half, p.off))) : road.designLevel(0);
};

// Family #145309 · element #145309 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/road-lines.mjs#L76-L86
export const f145309_daylight = function daylight(road, x, y, ux, uy, zE, g) {
  const { fillSlope, cutSlope } = road, limit = road.reach - road.width / 2;
  const g0 = g(x, y);
  if (Math.abs(zE - g0) < 1e-6) return { d: 0, z: g0 };
  const fillSide = zE > g0, sgn = fillSide ? 1 : -1;
  const raw = (d) => (fillSide ? zE - d / fillSlope : zE + d / cutSlope) - g(x + ux * d, y + uy * d);
  let a = 0, b = 0.25;
  while (sgn * raw(b) > 0) { a = b; b += 0.25; if (b > limit) return null; }
  for (let k = 0; k < 30; k++) { const m = (a + b) / 2; if (sgn * raw(m) > 0) a = m; else b = m; }
  return { d: b, z: fillSide ? zE - b / fillSlope : zE + b / cutSlope };
};

// Family #145324 · element #145324 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/road.mjs#L300-L304
export const f145324_jitter = function jitter(i, j, k) {
  let h = Math.imul(i + 0x9e37, 0x85ebca6b) ^ Math.imul(j + 0x7f4a, 0xc2b2ae35) ^ Math.imul(k + 1, 0x27d4eb2f);
  h = Math.imul(h ^ (h >>> 15), 0x2c1b3c6d); h = Math.imul(h ^ (h >>> 12), 0x297a2d39); h ^= h >>> 15;
  return (h >>> 0) / 4294967296;
};

// Family #145368 · element #145368 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/sites-ui.mjs#L40-L44
export const f145368_siteLabel = function siteLabel(site, { relief = true } = {}) {
  const words = site.name.replace(/[-_]+/g, ' ').trim();
  const base = words.charAt(0).toUpperCase() + words.slice(1);
  return relief && Number.isFinite(site.relief_m) ? `${base} (${Math.round(site.relief_m)} m relief)` : base;
};

// Family #145373 · element #145373 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/snap.mjs#L27-L30
export const f145373_bearingDeg = function bearingDeg(a, b) {
  const deg = Math.atan2(b.e - a.e, b.n - a.n) * 180 / Math.PI;
  return (Math.round(deg) + 360) % 360;
};

// Family #145377 · element #145377 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/snap.mjs#L66-L77
export const f145377_measuredShare = function measuredShare(pts, measuredAt, step = 5) {
  let total = 0, known = 0;
  for (let i = 1; i < pts.length; i++) {
    const [ax, ay] = pts[i - 1], [bx, by] = pts[i], L = Math.hypot(bx - ax, by - ay), n = Math.max(1, Math.ceil(L / step));
    for (let k = 0; k < n; k++) {
      const f = (k + 0.5) / n;
      if (Number.isFinite(measuredAt(ax + (bx - ax) * f, ay + (by - ay) * f))) known += L / n;
    }
    total += L;
  }
  return { total, known };
};

// Family #145378 · element #145378 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/snap.mjs#L80-L88
export const f145378_snapRing = function snapRing([x, y, z], r = 3, h = 4) {
  const out = [];
  for (let k = 0; k < 8; k++) {
    const a0 = k * Math.PI / 4, a1 = (k + 1) * Math.PI / 4;
    out.push(x + r * Math.cos(a0), y + r * Math.sin(a0), z + 0.3, x + r * Math.cos(a1), y + r * Math.sin(a1), z + 0.3);
  }
  out.push(x, y, z, x, y, z + h);
  return out;
};

// Family #145420 · element #145420 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/tour.mjs#L106-L110
export const f145420_sha256 = async function sha256(text) {
  const bytes = new TextEncoder().encode(text);
  const digest = await globalThis.crypto.subtle.digest('SHA-256', bytes);
  return [...new Uint8Array(digest)].map(b => b.toString(16).padStart(2, '0')).join('');
};

// Family #145426 · element #145426 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/tour.mjs#L165-L168
export const f145426_hermite = function hermite(a, b, u, h, j) {
  const u2 = u * u, u3 = u2 * u;
  return (2 * u3 - 3 * u2 + 1) * a.v[j] + (u3 - 2 * u2 + u) * h * a.m[j] + (-2 * u3 + 3 * u2) * b.v[j] + (u3 - u2) * h * b.m[j];
};

// Family #145429 · element #145429 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/tour.mjs#L192-L201
export const f145429_captionAt = function captionAt(line, t, { showFor = 6 } = {}) {
  const cs = line.captions;
  for (let i = cs.length - 1; i >= 0; i--) {
    if (cs[i].t <= t) {
      const until = Math.min(cs[i + 1]?.t ?? Infinity, cs[i].t + showFor);
      return t < until ? { text: cs[i].text, index: i } : null;
    }
  }
  return null;
};

// Family #145458 · element #145458 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/xr-pose.mjs#L22-L25
export const f145458_rotYaw = function rotYaw(yaw, [x, y, z]) {
  const c = Math.cos(yaw), s = Math.sin(yaw);
  return [c * x + s * y, -s * x + c * y, z];
};

// Family #145459 · element #145459 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/xr-pose.mjs#L28-L31
export const f145459_rotate = function rotate([qx, qy, qz, qw], [vx, vy, vz]) {
  const tx = 2 * (qy * vz - qz * vy), ty = 2 * (qz * vx - qx * vz), tz = 2 * (qx * vy - qy * vx);
  return [vx + qw * tx + (qy * tz - qz * ty), vy + qw * ty + (qz * tx - qx * tz), vz + qw * tz + (qx * ty - qy * tx)];
};

// Family #145522 · element #145522 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L37-L45
export const f145522_box = function box(f, cu, cv, len, wid, z0, z1, extra) {
  const hl = len / 2, hw = wid / 2;
  const quad = [[cu - hl, cv - hw], [cu + hl, cv - hw], [cu + hl, cv + hw], [cu - hl, cv + hw]].map(([u, v]) => f.toXY(u, v));
  const xs = quad.map(q => q[0]), ys = quad.map(q => q[1]);
  return {
    min: [Math.min(...xs), Math.min(...ys), z0], max: [Math.max(...xs), Math.max(...ys), z1],
    center: f.toXY(cu, cv), size: [len, wid, z1 - z0], yaw: f.yaw, quad, ...extra
  };
};

// Family #145523 · element #145523 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L49-L61
export const f145523_intervalsAt = function intervalsAt(ringsUV, v) {
  const xs = [];
  for (const ring of ringsUV) {
    for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
      const [u1, v1] = ring[j], [u2, v2] = ring[i];
      if ((v1 <= v && v < v2) || (v2 <= v && v < v1)) xs.push(u1 + (v - v1) * (u2 - u1) / (v2 - v1));
    }
  }
  xs.sort((a, b) => a - b);
  const out = [];
  for (let i = 0; i + 1 < xs.length; i += 2) out.push([xs[i], xs[i + 1]]);
  return out;
};

// Family #145524 · element #145524 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L62-L69
export const f145524_intersect = function intersect(a, b) {
  const out = [];
  for (const [a0, a1] of a) for (const [b0, b1] of b) {
    const lo = Math.max(a0, b0), hi = Math.min(a1, b1);
    if (hi > lo) out.push([lo, hi]);
  }
  return out;
};

// Family #145526 · element #145526 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L97-L101
export const f145526_mountingFor = function mountingFor(gcr) {
  if (Math.abs(gcr - 0.75) < 0.05 || gcr > 0.7) return 'east_west_dome';
  if (gcr <= 0.4) return 'tracker';
  return 'fixed_tilt';
};

// Family #145528 · element #145528 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L103-L115
export const f145528_ringsOf = function ringsOf(geom, toLocal) {
  const conv = ring => {
    const pts = ring.map(c => toLocal(c[0], c[1]));
    if (pts.length > 1) {
      const a = pts[0], b = pts[pts.length - 1];
      if (a[0] === b[0] && a[1] === b[1]) pts.pop();
    }
    return pts;
  };
  if (geom.type === 'Polygon') return [geom.coordinates.map(conv)];
  if (geom.type === 'MultiPolygon') return geom.coordinates.map(p => p.map(conv));
  return [];
};

// Family #145529 · element #145529 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/design-import.mjs#L116-L120
export const f145529_polyLength = function polyLength(pts) {
  let s = 0;
  for (let i = 1; i < pts.length; i++) s += Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);
  return s;
};

// Family #145590 · element #145590 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L49-L56
export const f145590_ringArea = function ringArea(ring) {
  let s = 0;
  for (let i = 0; i < ring.length; i++) {
    const [x0, y0] = ring[i], [x1, y1] = ring[(i + 1) % ring.length];
    s += x0 * y1 - x1 * y0;
  }
  return s / 2;
};

// Family #145591 · element #145591 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L59-L70
export const f145591_prepare = function prepare(rings) {
  const edges = [];
  let y0 = Infinity, y1 = -Infinity, x0 = Infinity, x1 = -Infinity;
  for (const ring of rings || []) {
    for (let i = 0; i < ring.length; i++) {
      const a = ring[i], b = ring[(i + 1) % ring.length];
      if (a[1] !== b[1]) edges.push(a[1] < b[1] ? [a[0], a[1], b[0], b[1]] : [b[0], b[1], a[0], a[1]]);
      y0 = Math.min(y0, a[1]); y1 = Math.max(y1, a[1]); x0 = Math.min(x0, a[0]); x1 = Math.max(x1, a[0]);
    }
  }
  return { edges, y0, y1, x0, x1 };
};

// Family #145592 · element #145592 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L73-L81
export const f145592_intervalsAt = function intervalsAt(poly, y) {
  if (y < poly.y0 || y >= poly.y1) return [];
  const xs = [];
  for (const [ax, ay, bx, by] of poly.edges) if (ay <= y && y < by) xs.push(ax + (y - ay) * (bx - ax) / (by - ay));
  xs.sort((p, q) => p - q);
  const out = [];
  for (let i = 0; i + 1 < xs.length; i += 2) if (xs[i + 1] > xs[i]) out.push([xs[i], xs[i + 1]]);
  return out;
};

// Family #145593 · element #145593 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L83-L91
export const f145593_intersect = function intersect(A, B) {
  const out = [];
  for (let i = 0, j = 0; i < A.length && j < B.length;) {
    const lo = Math.max(A[i][0], B[j][0]), hi = Math.min(A[i][1], B[j][1]);
    if (hi > lo) out.push([lo, hi]);
    if (A[i][1] < B[j][1]) i++; else j++;
  }
  return out;
};

// Family #145594 · element #145594 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L93-L106
export const f145594_subtract = function subtract(A, B) {
  const out = [];
  for (const [a0, a1] of A) {
    let s = a0;
    for (const [b0, b1] of B) {
      if (b1 <= s || b0 >= a1) continue;
      if (b0 > s) out.push([s, b0]);
      s = Math.max(s, b1);
      if (s >= a1) break;
    }
    if (s < a1) out.push([s, a1]);
  }
  return out;
};

// Family #145595 · element #145595 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L110-L119
export const f145595_pointInRings = function pointInRings(rings, x, y) {
  let inside = false;
  for (const ring of rings) {
    for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
      const [xi, yi] = ring[i], [xj, yj] = ring[j];
      if ((yi > y) !== (yj > y) && x < xi + (y - yi) * (xj - xi) / (yj - yi)) inside = !inside;
    }
  }
  return inside;
};

// Family #145597 · element #145597 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L171-L177
export const f145597_panelSplit = function panelSplit(areaM2, { pitch, tableWidth, excludedFraction = 0 } = {}) {
  if (!(pitch > 0) || !(tableWidth > 0)) throw new Error('land: row pitch and table width must be positive');
  if (tableWidth > pitch) throw new Error('land: table width cannot exceed the row pitch');
  if (!(excludedFraction >= 0 && excludedFraction < 1)) throw new Error('land: excluded fraction must be 0 to <1');
  const gcr = tableWidth / pitch, excluded = areaM2 * excludedFraction, arrayM2 = areaM2 - excluded;
  return { gcr, excludedM2: excluded, arrayM2, underPanelsM2: arrayM2 * gcr, betweenRowsM2: arrayM2 * (1 - gcr) };
};

// Family #145599 · element #145599 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/land.mjs#L199-L203
export const f145599_cellRing = function cellRing(e, n, { side, area, orientation = 'flat' } = {}) {
  if (!(side > 0)) { const h = Math.sqrt(area) / 2; return [[e - h, n - h], [e + h, n - h], [e + h, n + h], [e - h, n + h]]; }
  const a0 = orientation === 'pointy' ? 30 : 0;
  return Array.from({ length: 6 }, (_, k) => { const a = (a0 + 60 * k) * Math.PI / 180; return [e + side * Math.cos(a), n + side * Math.sin(a)]; });
};

// Family #145682 · element #145682 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/layers/grid.mjs#L81-L88
export const f145682_parseNationalIndex = function parseNationalIndex(j) {
  if (!j || typeof j !== 'object' || !Array.isArray(j.tiles)) throw Error('substation index has no tiles list');
  if (!j.licence) throw Error('substation index has no licence');
  const tileM = Number(j.tile_m) > 0 ? Number(j.tile_m) : 20000;
  const tiles = j.tiles.filter(t => Array.isArray(t) && Number.isFinite(t[0]) && Number.isFinite(t[1]) && /^[0-9a-f]{64}$/.test(t[3]))
    .map(([e0, n0, count, sha256]) => ({ key: `${e0 / 1000}_${n0 / 1000}`, e0, n0, count, sha256, file: `tiles/${e0 / 1000}_${n0 / 1000}.odbl.json` }));
  return { tileM, tiles };
};

// Family #145719 · element #145719 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/measure.mjs#L357-L369
export const f145719_coverAchieved = function coverAchieved(section, odMm = null) {
  const required = Number(section.cover_to_top_m);
  const duct = Number(section.duct_od_mm) > 0 ? Number(section.duct_od_mm) : null;
  const unit = duct ?? (Number(odMm) > 0 ? Number(odMm) : Number(section.phase_spacing_mm) > 0 ? Number(section.phase_spacing_mm) : null);
  if (unit == null) return { cover: required, required, ok: true, basis: 'section cover as stated' };
  const trefoil = /trefoil/i.test(section.formation || '');
  const height = trefoil ? unit * (1 + Math.sqrt(3) / 2) : unit;
  const bed = Number(section.bedding?.thickness_mm) || 0;
  const cover = section.trench_depth_m - bed / 1000 - height / 1000;
  const what = duct ? `${duct} mm duct` : Number(odMm) > 0 ? `${unit} mm cable` : `${unit} mm cable (section's assumed size)`;
  return { cover, required, ok: cover >= required - 5e-4,
    basis: `${section.trench_depth_m} m deep, less ${bed} mm bed, less ${Math.round(height)} mm ${trefoil ? 'trefoil' : 'layer'} of ${what}` };
};

// Family #145799 · element #145799 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/sites-ui.mjs#L68-L90
export const f145799_mountSiteSelect = function mountSiteSelect(doc, parent, chooser) {
  const label = doc.createElement('label');
  label.className = 'site-select';
  label.appendChild(doc.createTextNode('Site '));
  const select = doc.createElement('select');
  select.setAttribute('aria-label', 'Site');
  const opts = chooser.options();
  // The placeholder is always there, so after leaving a site (Find) the select can show "Choose a site" again.
  const ph = doc.createElement('option');
  ph.value = ''; ph.textContent = opts.length ? 'Choose a site' : 'No sites staged';
  ph.disabled = true; ph.selected = !opts.some(o => o.selected);
  select.appendChild(ph);
  for (const o of opts) {
    const el = doc.createElement('option');
    el.value = o.value; el.textContent = o.label; el.selected = o.selected;
    select.appendChild(el);
  }
  select.disabled = opts.length === 0;
  select.addEventListener('change', () => chooser.choose(select.value));
  label.appendChild(select);
  parent.appendChild(label);
  return select;
};

// Family #145804 · element #145804 · 11 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270056-site-world-v3/world/snap.mjs#L42-L46
export const f145804_tierOf = function tierOf(a) {
  if (a?.tier === 'transmission' || a?.tier === 'distribution') return a.tier;
  const kv = Number(a?.kv);
  return kv >= 200 ? 'transmission' : kv > 0 ? 'distribution' : null;
};

// Family #145952 · element #145952 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/first-showing.mjs#L23-L28
export const f145952_pinBatch = function pinBatch(x, y, z, version) {
  const r = 6, h = 40;
  const v = [0, 0, 0, 0, 0, h, -r, 0, 0, 0, r, 0, 0, r, 0, r, 0, 0, r, 0, 0, 0, -r, 0, 0, -r, 0, -r, 0, 0,
    0, 0, h, -3, 0, h - 6, 0, 0, h, 3, 0, h - 6];
  return { key: 'place-pin', version, positions: new Float32Array(v), color: [1, 0.45, 0.85, 1], origin: [x, y, z] };
};

// Family #145959 · element #145959 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/labels.mjs#L16-L23
export const f145959_basis = function basis(s) {
  const id = String(s.id || '');
  if (/-dno/.test(id)) return /agricultural/.test(id) ? 'farmland (network operator spec)' : '(network operator spec)';
  if (/-owner/.test(id)) return `(owner rule, ${s.cover_to_top_m} m cover)`;
  if (/-agri/.test(id)) return 'farmland';
  if (/duct/i.test(s.formation || '')) return s.cover_to_top_m >= 1.2 ? `in ducts, ${s.cover_to_top_m} m cover` : 'in ducts';
  return '';
};

// Family #146010 · element #146010 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/layers/national.mjs#L51-L59
export const f146010_clipToCircle = function clipToCircle(ax, ay, bx, by, cx, cy, r) {
  const dx = bx - ax, dy = by - ay, fx = ax - cx, fy = ay - cy;
  const A = dx * dx + dy * dy, B = 2 * (fx * dx + fy * dy), C = fx * fx + fy * fy - r * r;
  if (A === 0) return C <= 0 ? [0, 1] : null;
  const disc = B * B - 4 * A * C;
  if (disc < 0) return null;
  const s = Math.sqrt(disc), lo = Math.max(0, (-B - s) / (2 * A)), hi = Math.min(1, (-B + s) / (2 * A));
  return lo < hi ? [lo, hi] : null;
};

// Family #146061 · element #146061 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/ohl-ui.mjs#L14-L24
export const f146061_readout = function readout(spans, result, height) {
  if (!spans.length) return 'Overhead line zones: no overhead line conductors drawn near here yet.';
  const n = f => result.flags.filter(x => x.flag === f).length;
  const items = new Set(result.flags.filter(f => f.flag !== 'height').map(f => f.item)).size;
  const parts = [`Overhead line zones round ${spans.length} span${spans.length === 1 ? '' : 's'}`,
    items ? `${items} design item${items === 1 ? '' : 's'} inside a zone (${n('crosses')} crossing under)` : 'no design item flagged (not assessed beyond the zones)',
    result.goalposts.length ? `${result.goalposts.length / 2} goalpost crossing${result.goalposts.length === 2 ? '' : 's'} suggested` : '',
    height > 0 ? `plant ${height} m tall (user-set) reaches an exclusion distance at ${n('height')} item${n('height') === 1 ? '' : 's'}` : '',
    result.unmeasured ? `${result.unmeasured} points not assessed: no measured ground` : ''];
  return parts.filter(Boolean).join(' · ') + '.';
};

// Family #146062 · element #146062 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/ohl-ui.mjs#L27-L33
export const f146062_boqItems = function boqItems(result) {
  const by = new Map();
  const get = id => { if (!by.has(id)) by.set(id, { id: `ohl-${id}`, kind: 'ohlZone', zone: 0, height: 0, goalposts: 0 }); return by.get(id); };
  for (const f of result.flags) get(f.item)[f.flag === 'height' ? 'height' : 'zone']++;
  for (const g of result.goalposts) get(g.item).goalposts++;
  return [...by.values()];
};

// Family #146077 · element #146077 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/ohl-zones.mjs#L89-L92
export const f146077_cross2 = (a, b, c, d) => {
  const o = (p, q, r) => Math.sign((q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]));
  return o(a, b, c) * o(a, b, d) < 0 && o(c, d, a) * o(c, d, b) < 0;
};

// Family #146079 · element #146079 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/ohl-zones.mjs#L104-L113
export const f146079_pointAtChainage = function pointAtChainage(pts, s) {
  let run = 0;
  for (let i = 1; i < pts.length; i++) {
    const L = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);
    if (run + L >= s || i === pts.length - 1) { const f = L > 0 ? Math.min(1, Math.max(0, (s - run) / L)) : 0;
      return [pts[i - 1][0] + (pts[i][0] - pts[i - 1][0]) * f, pts[i - 1][1] + (pts[i][1] - pts[i - 1][1]) * f]; }
    run += L;
  }
  return pts[0];
};

// Family #146084 · element #146084 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/ohl-zones.mjs#L187-L197
export const f146084_designItems = function designItems(design, origin) {
  const L = path => (path || []).filter(p => Number.isFinite(p?.e) && Number.isFinite(p?.n)).map(p => [p.e - origin.e, p.n - origin.n]);
  const out = [];
  (design?.trenches || []).forEach((t, i) => out.push({ id: `trench-${i + 1}`, kind: 'trench', pts: L(t.path) }));
  (design?.cables || []).forEach((c, i) => out.push({ id: `cable-${i + 1}`, kind: 'cable', pts: L(c.path) }));
  (design?.works || []).forEach((w, i) => {
    const pts = L(w.path), id = `${w.kind}-${i + 1}`;
    out.push({ id, kind: w.kind, pts, area: w.kind === 'pad' && pts.length > 2, closed: w.kind === 'fence' });
  });
  return out.filter(it => it.pts.length >= 1);
};

// Family #146109 · element #146109 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/route-tool.mjs#L79-L95
export const f146109_describeControls = function describeControls({ touch = false } = {}) {
  return touch
    ? [
        ['Tap', 'the ground to add a point'],
        ['Undo', 'removes the last point'],
        ['Done', 'completes the route (two points or more)'],
        ['Clear', 'removes the route and starts again'],
        ['Snap', 'a cable point within 25 m of a substation or pylon moves onto it (ringed)']
      ]
    : [
        ['Click', 'the ground to add a point'],
        ['Backspace', 'removes the last point'],
        ['Enter', 'completes the route (two points or more)'],
        ['Esc', 'removes the route and starts again'],
        ['Snap', 'a cable point within 25 m of a substation or pylon moves onto it (ringed)']
      ];
};

// Family #146170 · element #146170 · 10 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270145-site-world-v3/world/sun-day.mjs#L55-L64
export const f146170_horizonFunction = function horizonFunction(profile) {
  if (!profile || !profile.length) return () => 0;
  const n = profile.length;
  return az => {
    const f = ((az % 360) + 360) % 360 / (360 / n), k0 = Math.floor(f) % n, k1 = (k0 + 1) % n, w = f - Math.floor(f);
    const a = profile[k0], b = profile[k1];
    if (!Number.isFinite(a) || !Number.isFinite(b)) return Number.isFinite(a) ? a : Number.isFinite(b) ? b : 0;
    return a * (1 - w) + b * w;
  };
};

// Family #146355 · element #146355 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/block-sequence.mjs#L48-L67
export const f146355_partial = function partial(points, f) {
  if (f >= 1) return points;
  if (f <= 0 || points.length < 2) return [points[0]];
  let total = 0;
  const seg = [];
  for (let i = 1; i < points.length; i++) {
    const a = points[i - 1], b = points[i], l = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
    seg.push(l); total += l;
  }
  let want = f * total;
  const out = [points[0]];
  for (let i = 1; i < points.length; i++) {
    const a = points[i - 1], b = points[i], l = seg[i - 1];
    if (want >= l) { out.push(b); want -= l; continue; }
    const k = l > 0 ? want / l : 0;
    out.push([a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k]);
    break;
  }
  return out;
};

// Family #146361 · element #146361 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/block-ui.mjs#L74-L81
export const f146361_cableGroup = function cableGroup(list, by) {
    const v = [], marks = [], base = list[0].points[0];
    list.forEach((c, i) => {
      for (let k = 1; k < c.points.length; k++) for (const p of [c.points[k - 1], c.points[k]]) v.push(p[0] - base[0], p[1] - base[1], p[2] - base[2]);
      if (!by || i === list.length - 1 || list[i + 1][by] !== c[by]) marks.push(v.length / 3);
    });
    return { base, v: new Float32Array(v), marks, items: by ? [...new Set(list.map(c => c[by]))].map(k => list.filter(c => c[by] === k)) : list.map(c => [c]) };
  };

// Family #146383 · element #146383 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/design-options.mjs#L36-L42
export const f146383_readFile = async function readFile(input, parse) {
    const f = input.files && input.files[0];
    if (!f) return null;
    const json = JSON.parse(await f.text());
    input.value = '';                                                  // the same file can be chosen again
    return parse(json);
  };

// Family #146518 · element #146518 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/search-ui.mjs#L128-L131
export const f146518_mergeRows = function mergeRows(postcodeRows, projectRows, placeRows = []) {
  const rest = [...(placeRows || []).map((r) => ({ r, k: r.score ?? 0 })), ...(projectRows || []).map((r) => ({ r, k: r.rank ?? 0 }))];
  return [...(postcodeRows || []), ...rest.map((x, i) => ({ ...x, i })).sort((a, b) => b.k - a.k || a.i - b.i).map((x) => x.r)];
};

// Family #146519 · element #146519 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/search-ui.mjs#L135-L143
export const f146519_statusLine = function statusLine({ postcodes = undefined, places = undefined, projects = null, projectRows = 0 } = {}) {
  const parts = [];
  if (postcodes === null) parts.push('Looking up postcode...');
  else if (postcodes !== undefined) parts.push(postcodes ? `${postcodes} ${postcodes === 1 ? 'postcode' : 'postcodes'}` : 'No postcode matches');
  if (places === null) parts.push('Looking up places...');
  else if (places) parts.push(`${places} ${places === 1 ? 'place' : 'places'}`);
  if (projects && (projectRows > 0 || !parts.length)) parts.push(projects);
  return parts.join(' · ');
};

// Family #146588 · element #146588 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/trench-section.mjs#L18-L24
export const f146588_formationOf = function formationOf(section) {
  const f = String(section.formation || '').toLowerCase();
  const ducted = Number(section.duct_od_mm) > 0 || /duct/.test(f);
  const kind = /trefoil/.test(f) ? 'trefoil' : /side by side|flat/.test(f) && !/trefoil/.test(f) ? 'flat' : 'trefoil';
  const perCircuit = /ducts side by side|duct groups/.test(f) ? 'group' : 'three';
  return { kind, ducted, perCircuit, circuits: Math.max(1, Number(section.circuits) || 1) };
};

// Family #146592 · element #146592 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/trench-section.mjs#L76-L114
export const f146592_sectionLines = function sectionLines({ trench, groundAt, cs, eye, near = 25, spacing = 2, ringSides = 16 }) {
  const v = [];
  const push = (a, b) => v.push(a[0], a[1], a[2], b[0], b[1], b[2]);
  const L = trench.length2d, count = Math.max(1, Math.floor(L / spacing));
  const slices = [];
  for (let k = 0; k <= count; k++) {
    const s = Math.min(L, k * spacing);
    const [cx, cy] = trench.pointAt(s);
    if (Math.hypot(cx - eye[0], cy - eye[1]) > near) { slices.push(null); continue; }
    const a = trench.pointAt(Math.max(0, s - 0.1)), b = trench.pointAt(Math.min(L, s + 0.1));
    const len = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1, nx = -(b[1] - a[1]) / len, ny = (b[0] - a[0]) / len;
    const g0 = groundAt(cx, cy);
    slices.push(([u, z]) => [cx + nx * u, cy + ny * u, g0 + z]);
  }
  const rails = [];                                   // points repeated on every slice, joined along the trench
  const rail = (key, uz) => rails.push([key, uz]);
  for (const layer of cs.layers) if (layer.z1 < 0) { rail(layer.name + 'L', [-cs.halfAt(layer.z1), layer.z1]); rail(layer.name + 'R', [cs.halfAt(layer.z1), layer.z1]); }
  for (const m of cs.markers) { rail(m.kind + 'L', [m.u0, m.z]); rail(m.kind + 'R', [m.u1, m.z]); }
  slices.forEach((P, k) => {
    if (!P) return;
    for (let i = 1; i < cs.outline.length; i++) push(P(cs.outline[i - 1]), P(cs.outline[i]));
    for (const layer of cs.layers) if (layer.z1 < 0) push(P([-cs.halfAt(layer.z1), layer.z1]), P([cs.halfAt(layer.z1), layer.z1]));
    for (const m of cs.markers) {
      push(P([m.u0, m.z]), P([m.u1, m.z]));
      if (m.kind === 'tile') { push(P([m.u0, m.z + 0.05]), P([m.u1, m.z + 0.05])); push(P([m.u0, m.z]), P([m.u0, m.z + 0.05])); push(P([m.u1, m.z]), P([m.u1, m.z + 0.05])); }
    }
    for (const it of cs.items) {
      const n = it.kind === 'duct' ? ringSides : Math.max(8, ringSides / 2);
      for (let j = 0; j < n; j++) {
        const t0 = 2 * Math.PI * j / n, t1 = 2 * Math.PI * (j + 1) / n;
        push(P([it.u + it.r * Math.cos(t0), it.z + it.r * Math.sin(t0)]), P([it.u + it.r * Math.cos(t1), it.z + it.r * Math.sin(t1)]));
      }
    }
    for (const sp of cs.supports) push(P([sp.u, sp.z0]), P([sp.u, sp.z1]));
    const Q = slices[k + 1];
    if (Q) for (const [, uz] of rails) push(P(uz), Q(uz));
  });
  return new Float32Array(v);
};

// Family #146594 · element #146594 · 9 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/trench-section.mjs#L121-L148
export const f146594_tubeLines = function tubeLines(polyline, od, { eye = null, near = 20, every = 1, sides = 8 } = {}) {
  const r = od / 2, v = [], n = polyline.length;
  if (n < 2) return new Float32Array(0);
  const frame = i => {
    const a = polyline[Math.max(0, i - 1)], b = polyline[Math.min(n - 1, i + 1)];
    const dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1;
    return [-dy / l, dx / l];
  };
  const off = (p, [nx, ny], du, dz) => [p[0] + nx * du, p[1] + ny * du, p[2] + dz];
  const sides4 = [[r, 0], [-r, 0], [0, r], [0, -r]];
  let last = -Infinity, s = 0;
  for (let i = 0; i < n; i++) {
    const p = polyline[i], f = frame(i);
    if (i) {
      const q = polyline[i - 1], g = frame(i - 1);
      s += Math.hypot(p[0] - q[0], p[1] - q[1]);
      for (const [du, dz] of sides4) { const a = off(q, g, du, dz), b = off(p, f, du, dz); v.push(...a, ...b); }
    }
    if (eye && s - last >= every && Math.hypot(p[0] - eye[0], p[1] - eye[1], p[2] - eye[2]) <= near) {
      last = s;
      for (let j = 0; j < sides; j++) {
        const t0 = 2 * Math.PI * j / sides, t1 = 2 * Math.PI * (j + 1) / sides;
        v.push(...off(p, f, r * Math.cos(t0), r * Math.sin(t0)), ...off(p, f, r * Math.cos(t1), r * Math.sin(t1)));
      }
    }
  }
  return new Float32Array(v);
};