GLOBALGRID2050 / EXPLORE CODE

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

Standalone (part 15)

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 1577 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 10340–11039

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 10340–11039 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
shown, guard, f31935__anonymous_, f172453_originalLink, f172454_headlineSummaryV923, f172455_shortHeadlineV923, f172456_latestTime, f172645_selectRecords, f144681__anonymous_, f144683_planLength, f144684_bendCount, f144698_cell, f144700_worldFrom, f144701_drawnItems, local, f144705_voltageClass, f144709_stemDiameterMm, f144726_closestOnSeg, f144727_segsCross, o, f144728_segsOf, f144731_crossing, f144733_chainage, f144734_pointAt, f144743_batch, f144754_sha256Hex, f144769_b64url, f144770_unb64url, f144771_pump, f144774_pickStorage
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:10340-11039 · 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
      if (t.indexOf('sr') === 0) return s.over_volts ? 2 : 1;  /* the array's voltage */
      /* THE DC RUN CARRIES BOTH CURRENT VERDICTS, and it is OR rather than a
         precedence on purpose: the renderer has one alarm value, so nesting
         them would give identical output by a longer road - and that road is
         where a later edit hides the loser. The fuse belongs here because
         design_a is what cable and protection are sized to, which is what
         these pieces depict; a fuse rating is not a property of the array. */
      if (t.indexOf('dc') === 0)
        return (s.over_string || s.over_fuse) ? 2 : 0.9;
      return 0.55;
    });
  }

  var BOXES = [
    { key:'module_class', label:'module class', kind:'choice',
      choices:Object.keys(BINS).map(function (k) { return [k, BINS[k].label]; }) },
    { key:'modules_in_series', label:'modules in series', unit:'',
      kind:'number', min:20, max:34, step:1 },
    { key:'rear_gain_pct', label:'rear gain', unit:'%',
      kind:'number', min:0, max:30, step:1 },
    { key:'site_min_c', label:'assessment temperature', unit:'C',
      kind:'number', min:-20, max:0, step:1 },
    { key:'routing', label:'string routing', kind:'choice',
      choices:[['leapfrog', 'leapfrog, go and return alongside each other'],
               ['one-after-another', 'one after another, return down the row']] }
  ];


  /* THE GUARD. Written the way the sibling string program writes one: a value
     the engine cannot hold is refused in words, never defaulted.
     DEFAULTING IS WORSE THAN REFUSING, and not as a matter of taste. A typed
     word where a number belongs becomes NaN, and every verdict below was
     written `v > limit`. NaN > 1500 is false, so the garbage came back as
     "inside the 1500 V rating by NaN V" - a PASS, in the voice of an answer.
     A refusal is read; a default is obeyed. */
  var NUMS = { modules_in_series:'modules in series',
               rear_gain_pct:'rear gain, in %',
               site_min_c:'the assessment temperature, in C' };
  var CHOICE = { module_class:Object.keys(BINS),
                 routing:['leapfrog', 'one-after-another'] };
  function shown(v) { return typeof v === 'string' ? '"' + v + '"' : String(v); }
  function guard(inp) {
    var bad = [], k, v, x;
    for (k in inp) {
      if (!Object.prototype.hasOwnProperty.call(inp, k)) continue;
      v = inp[k];
      if (v === undefined || v === null) continue;   /* absent = take the default */
      if (!NUMS[k] && !CHOICE[k]) {
        bad.push('"' + k + '" is not an input this command has, so it was about '
          + 'to be ignored in silence while its default answered in its place; '
          + 'the inputs are '
          + Object.keys(CHOICE).concat(Object.keys(NUMS)).join(', ') + '.');
        continue;
      }
      if (CHOICE[k]) {
        if (CHOICE[k].indexOf(v) < 0)
          bad.push(k + ' must be one of ' + CHOICE[k].join(', ')
                   + '; you typed ' + shown(v) + '.');
        continue;
      }
      x = typeof v === 'number' ? v
        : (typeof v === 'string' && v.trim() !== '' ? Number(v) : NaN);
      if (!isFinite(x))
        bad.push(NUMS[k] + ' must be a number; you typed ' + shown(v) + '.');
    }
    return bad.slice(0, 6);
  }

  F.register('site', 'SITE', function (inputs) {
    var stopped = guard(inputs || {});
    if (stopped.length) {
      return {
        numbers: { drawn:'nothing', inputs_refused:stopped.length },
        refused: true,
        said: 'NOTHING IS DRAWN. ' + stopped.join(' ')
            + ' Refusing beats defaulting because a default still produces a '
            + 'confident number nobody asked for, and a value that is not a '
            + 'number produces NaN, which loses every comparison silently and '
            + 'reads as if the design were inside its rating. Change the input '
            + 'named above and fire again.',
        how: 'Every value is read and checked before a coordinate is worked '
           + 'out. A refusal is not a failure: it is the engine declining to '
           + 'draw a plant whose arithmetic it cannot stand behind.',
        sld: null
      };
    }
    var id = inputs.module_class && BINS[inputs.module_class] ? inputs.module_class : 'T660';
    var b = BINS[id];
    var se = inputs.modules_in_series === undefined ? 30 : +inputs.modules_in_series;
    var rear = (inputs.rear_gain_pct === undefined ? BNPI_REAR * 100 : +inputs.rear_gain_pct) / 100;
    var tmin = inputs.site_min_c === undefined ? -10 : +inputs.site_min_c;
    var routing = inputs.routing || 'leapfrog';

    var phi = (b.kcorr - 1) / BNPI_REAR;
    var kb = 1 + phi * rear;                        /* rear side adds current */
    var kt = 1 + b.alpha / 100 * (tmin - 25);       /* cold takes a little back */
    var isc_e = b.isc * kb * kt, imp_e = b.imp * kb * kt;
    var v = se * b.voc * (1 + b.beta / 100 * (tmin - 25));

    /* THREE DIFFERENT TESTS, AND THE SIZING FACTOR BELONGS TO ONLY ONE OF THEM.
       An earlier draft multiplied the machine's own input limit by 1.25 and so
       failed designs that are inside it. 1.25 is a continuous-current factor
       for array cable and overcurrent protection; a manufacturer's input limit
       is a limit on the current itself. They are reported separately. */
    /* `!(x <= limit)` NOT `x > limit`. On every finite number the two agree -
       8,000,132 checks on the card, 0 disagreements - so nothing a real design
       does changes. They part on NaN: `>` says false and passes it, `!(<=)`
       says true and names it. The guard above should make that unreachable;
       this is the second lock on the same door, for the day someone edits
       the guard. */
    var over_volts  = !(v <= V_CEIL);                               /* equipment rating */
    var over_string = !(imp_e <= STRING_INPUT_A);                   /* string input, working current */
    var over_mppt   = !(isc_e * STRINGS_PER_MPPT <= MPPT_INPUT_A);  /* the machine's input */
    var design_a    = SIZING * isc_e;                               /* what cable and OCPD are sized to */
    var over_fuse   = !(design_a <= b.fuse);                        /* the sheet's max series fuse */

    /* over_fuse WAS COMPUTED, PRINTED IN THE SENTENCE, AND NEVER DRAWN.
       It was absent from this object, so finalFor() could not see it and a
       design over its maximum series fuse was coloured exactly like one that
       passed: the words said OVER, the picture said fine. It could not fire
       today only by arithmetic coincidence - the worst reachable design
       current is about 28.8 A against 35 A - and it would have gone live in
       silence on any bin with a 30 A fuse. */
    var s = { over_volts:over_volts, over_string:over_string,
              over_mppt:over_mppt, over_fuse:over_fuse };
    var head = V_CEIL - v;
    var said =
      'The whole plant in one drawing: grid, interface, one transformer to the '
      + 'collection busbar, and ' + BLOCKS_DRAWN + ' blocks hanging off it. '
      + se + ' of the ' + b.label + ' in series reaches ' + v.toFixed(1)
      + ' V at ' + tmin + ' C, '
      + (over_volts ? 'OVER the ' + V_CEIL + ' V equipment rating by '
                      + (-head).toFixed(1) + ' V'
                    : 'inside the ' + V_CEIL + ' V rating by ' + head.toFixed(1) + ' V')
      + (!over_volts && head < 25 ? ' - which at a 0 to +5 W tolerance is not a margin, '
         + 'because the module that arrives can be the top bin' : '')
      + '. At ' + (rear * 100).toFixed(1) + '% rear gain, with a bifaciality of '
      + phi.toFixed(3) + (b.bnpi_stated
          ? ' derived from this sheet\'s own printed rear-irradiance condition, '
          : ' derived from this sheet\'s printed current ratio but divided by a rear '
            + 'irradiance THIS SHEET DOES NOT STATE - it heads a column BNPI and '
            + 'defines only STC and NOCT, so that divisor is borrowed from another '
            + 'sheet and this number is an assumption, ')
      + 'the string '
      + 'works at ' + imp_e.toFixed(2) + ' A and shorts at ' + isc_e.toFixed(2) + ' A: '
      + (over_string ? 'OVER the ' + STRING_INPUT_A + ' A string input'
                     : 'inside the ' + STRING_INPUT_A + ' A string input') + ', '
      + (over_mppt ? 'OVER the ' + MPPT_INPUT_A + ' A machine input on ' + STRINGS_PER_MPPT
                     + ' strings' : 'inside the ' + MPPT_INPUT_A + ' A machine input') + ', '
      + 'and cable and protection size to ' + design_a.toFixed(2) + ' A against a '
      + b.fuse + ' A maximum series fuse'
      + (over_fuse ? ' - OVER it' : '')
      + '. Routing is ' + routing + ', which sets the loop and therefore the '
      + 'transient, and reaches neither the voltage nor the current above.';

    return {
      numbers: {
        module_class: id,
        bifaciality: +phi.toFixed(3),
        bifaciality_is_derived: !!b.bnpi_stated,
        modules_in_series: se,
        string_voltage_v: +v.toFixed(1),
        headroom_to_rating_v: +head.toFixed(1),
        working_current_a: +imp_e.toFixed(2),
        short_circuit_current_a: +isc_e.toFixed(2),
        design_current_a: +design_a.toFixed(2),
        rear_gain_pct: +(rear * 100).toFixed(1),
        blocks_drawn: BLOCKS_DRAWN
      },
      said: said,
      how: 'The teeth of each comb are GROUPS of strings, not strings: a tube map '
         + 'does not draw every train, and a dot closer than three radii to its '
         + 'neighbour is the one thing this renderer will not draw. Bifaciality is '
         + 'derived from the sheet\'s own K_Corr at its printed rear-irradiance '
         + 'condition, never assumed, and the sheet publishes rear gain to '
         + TABLE_TOP + '%. The 1.25 factor is applied to cable and protection '
         + 'sizing only, never to a manufacturer\'s input limit. NOT MODELLED, '
         + 'and each one makes the real answer worse: the rise in open-circuit '
         + 'voltage with irradiance, uneven rear light along a string, and every '
         + 'transient effect beyond a first-order V = L I / t. Nothing here '
         + 'carries a coordinate, a length, a bearing or a name.',
      sld: { kind:'site', pieces:pieces(), state:s, finalFor:final }
    };
  }, BOXES);
};

// Family #31935 · element #31935 · 146 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_renewables_pipeline/202609051156/tests/browser_smoke_v9_7.mjs#L105-L110
export const f31935__anonymous_ = (wrap) => {
        wrap.scrollLeft = wrap.scrollWidth;
        const reached = wrap.scrollLeft;
        wrap.scrollLeft = 0;
        return reached;
      };

// Family #172453 · element #172453 · 57 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/v923-recovery/templates/machine-notes.js#L12-L15
export const f172453_originalLink = function originalLink(raw) {
    try { var u = new URL(String(raw)); return u.protocol === 'https:' ? u.href : null; }
    catch (_) { return null; }
  };

// Family #172454 · element #172454 · 57 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/v923-recovery/templates/machine-notes.js#L16-L32
export const f172454_headlineSummaryV923 = function headlineSummaryV923(item) {
    var kind = {
      refusal: 'REFUSAL REPORTED',
      consent: 'CONSENT REPORTED',
      planning_decision: 'PLANNING DECISION REPORTED',
      construction: 'CONSTRUCTION REPORTED',
      finance: 'FINANCING REPORTED',
      grid: 'GRID UPDATE REPORTED',
      energisation: 'ENERGISATION REPORTED',
      dco: 'DCO UPDATE REPORTED',
      datacentre: 'DATA CENTRE UPDATE REPORTED'
    }[item.category] || 'PROJECT HEADLINE';
    var d = new Date(item.published);
    var date = Number.isNaN(d.getTime()) ? 'DATE UNKNOWN' :
      d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' }).toUpperCase();
    return kind + ' · ' + date;
  };

// Family #172455 · element #172455 · 57 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/v923-recovery/templates/machine-notes.js#L33-L39
export const f172455_shortHeadlineV923 = function shortHeadlineV923(item) {
    // First ten source-title words only, never publisher article text.
    var raw = String(item.title || '').replace(/\s+/g, ' ').trim();
    if (!raw) return 'Headline details available at original source';
    var words = raw.split(' ');
    return words.slice(0, 10).join(' ') + (words.length > 10 ? '…' : '');
  };

// Family #172456 · element #172456 · 57 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/v923-recovery/templates/machine-notes.js#L40-L43
export const f172456_latestTime = function latestTime(item) {
    var t = Date.parse(item.published || item.observed || '');
    return Number.isFinite(t) ? t : 0;
  };

// Family #172645 · element #172645 · 53 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/news/prospecting-ui/adapter.mjs#L87-L90
export const f172645_selectRecords = function selectRecords(model,{recordType='renewable_project',query='',sort='priority'}={}){
  const needle=query.trim().toLocaleLowerCase('en-GB');const rows=model.records.filter(row=>row.record_type===recordType&&[row.id,row.name||'',row.country||'',row.technology].join(' ').toLocaleLowerCase('en-GB').includes(needle));
  return sort==='name'?rows.sort((a,b)=>(a.name||a.id).localeCompare(b.name||b.id,'en-GB')||a.id.localeCompare(b.id)):rows.sort((a,b)=>a.rank-b.rank);
};

// Family #144681 · element #144681 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/boq-assumptions.mjs#L39-L42
export const f144681__anonymous_ = (l, i) => ({
  key: /sub-base/.test(l.name) ? 'SUBBASE' : `L${i + 1}`,
  material: `${l.name}, ${l.material}`, thicknessMm: Math.round(l.thickness * 1000), assumed: true,
});

// Family #144683 · element #144683 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/boq.mjs#L35-L39
export const f144683_planLength = function planLength(path) {
  let s = 0;
  for (let k = 1; k < (path || []).length; k++) s += Math.hypot(path[k][0] - path[k - 1][0], path[k][1] - path[k - 1][1]);
  return s;
};

// Family #144684 · element #144684 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/boq.mjs#L41-L50
export const f144684_bendCount = function bendCount(path) {
  let n = 0;
  for (let i = 1; i < (path || []).length - 1; i++) {
    const [a, b, c] = [path[i - 1], path[i], path[i + 1]];
    const cr = (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0]);
    const dot = (b[0] - a[0]) * (c[0] - b[0]) + (b[1] - a[1]) * (c[1] - b[1]);
    if (Math.abs(Math.atan2(cr, dot)) > 1e-6) n++;
  }
  return n;
};

// Family #144698 · element #144698 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/boq.mjs#L332-L335
export const f144698_cell = (v) => {
  const s = v == null ? '' : String(v);
  return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
};

// Family #144700 · element #144700 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/buffers-ui.mjs#L9-L16
export const f144700_worldFrom = function worldFrom({ grid, rivers, roads, hedges } = {}) {
  return {
    overhead: (grid?.lines || []).filter(l => Array.isArray(l.points)),
    water: (rivers?.lines || []).filter(l => Array.isArray(l.points)),
    roads: (roads?.lines || []).filter(l => Array.isArray(l.pts)),
    hedges: (hedges?.lines || []).filter(l => Array.isArray(l.pts)),
  };
};

// Family #144701 · element #144701 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/buffers-ui.mjs#L19-L25
export const f144701_drawnItems = function drawnItems(design, origin) {
  const local = path => (path || []).map(p => [p.e - origin.e, p.n - origin.n]);
  return [
    ...(design?.trenches || []).map((t, i) => ({ id: `trench-${i + 1}`, kind: 'trench', points: local(t.path) })),
    ...(design?.cables || []).map((c, i) => ({ id: `cable-${i + 1}`, kind: 'trench', points: local(c.path) })),
  ].filter(it => it.points.length >= 2);
};

// Family #144705 · element #144705 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/buffers.mjs#L48-L52
export const f144705_voltageClass = function voltageClass(kv) {
  const v = Number(kv);
  if (!(v > 0)) return '33kV';
  return v >= 345 ? '400kV' : v >= 220 ? '275kV' : v >= 100 ? '132kV' : v >= 50 ? '66kV' : '33kV';
};

// Family #144709 · element #144709 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/buffers.mjs#L95-L99
export const f144709_stemDiameterMm = function stemDiameterMm(t, fallback) {
  const s = Array.isArray(t.stems_mm) ? t.stems_mm.filter(v => v > 0) : t.stem_mm > 0 ? [t.stem_mm] : [];
  if (!s.length) return { mm: fallback, assumed: true };
  return { mm: s.length === 1 ? s[0] : Math.sqrt(s.reduce((a, v) => a + v * v, 0)), assumed: false, stems: s.length };
};

// Family #144726 · element #144726 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L17-L21
export const f144726_closestOnSeg = function closestOnSeg(px, py, a, b) {
  const dx = b[0] - a[0], dy = b[1] - a[1], L2 = dx * dx + dy * dy;
  const t = L2 ? Math.max(0, Math.min(1, ((px - a[0]) * dx + (py - a[1]) * dy) / L2)) : 0;
  return [a[0] + dx * t, a[1] + dy * t];
};

// Family #144727 · element #144727 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L23-L26
export const f144727_segsCross = function segsCross(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 #144728 · element #144728 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L28-L33
export const f144728_segsOf = function segsOf(g) {
  const p = g.pts, closed = g.closed || g.area, out = [];
  if (p.length === 1) return [[p[0], p[0]]];
  for (let i = 0; i < (closed ? p.length : p.length - 1); i++) out.push([p[i], p[(i + 1) % p.length]]);
  return out;
};

// Family #144731 · element #144731 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L58-L62
export const f144731_crossing = function crossing(a, b, c, d) {
  const rx = b[0] - a[0], ry = b[1] - a[1], sx = d[0] - c[0], sy = d[1] - c[1];
  const t = ((c[0] - a[0]) * sy - (c[1] - a[1]) * sx) / (rx * sy - ry * sx);
  return [a[0] + rx * t, a[1] + ry * t];
};

// Family #144733 · element #144733 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L74-L78
export const f144733_chainage = function chainage(pts) {
  const c = [0];
  for (let i = 1; i < pts.length; i++) c.push(c[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
  return c;
};

// Family #144734 · element #144734 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/clash.mjs#L79-L84
export const f144734_pointAt = function pointAt(pts, cum, s) {
  let i = 1;
  while (i < pts.length - 1 && cum[i] < s) i++;
  const f = cum[i] > cum[i - 1] ? Math.max(0, Math.min(1, (s - cum[i - 1]) / (cum[i] - cum[i - 1]))) : 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];
};

// Family #144743 · element #144743 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-earthworks.mjs#L171-L176
export const f144743_batch = function batch(key, v, pos, color) {
    if (!pos || pos.length < 6) return null;
    const o = [pos[0], pos[1], pos[2]], out = new Float32Array(pos.length);
    for (let i = 0; i < pos.length; i++) out[i] = pos[i] - o[i % 3];
    return { key, version: v, positions: out, color, origin: o };
  };

// Family #144754 · element #144754 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-store.mjs#L53-L58
export const f144754_sha256Hex = async function sha256Hex(text) {
  const subtle = globalThis.crypto?.subtle;
  if (!subtle) throw new Error('SHA-256 is not available here (no crypto.subtle)');
  const digest = await subtle.digest('SHA-256', new TextEncoder().encode(text));
  return [...new Uint8Array(digest)].map(b => b.toString(16).padStart(2, '0')).join('');
};

// Family #144769 · element #144769 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-store.mjs#L277-L280
export const f144769_b64url = bytes => {
  let s = ''; for (let i = 0; i < bytes.length; i += 0x8000) s += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
  return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
};

// Family #144770 · element #144770 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-store.mjs#L281-L284
export const f144770_unb64url = s => {
  const bin = atob(s.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - s.length % 4) % 4));
  return Uint8Array.from(bin, c => c.charCodeAt(0));
};

// Family #144771 · element #144771 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-store.mjs#L286-L299
export const f144771_pump = async function pump(bytes, stream, cap) {
  const out = new Blob([bytes]).stream().pipeThrough(stream).getReader();
  const parts = []; let n = 0;
  for (;;) {
    const { done, value } = await out.read();
    if (done) break;
    n += value.length;
    if (n > cap) { await out.cancel(); throw new Error(`the link expands past ${cap} bytes; refused`); }
    parts.push(value);
  }
  const all = new Uint8Array(n); let o = 0;
  for (const p of parts) { all.set(p, o); o += p.length; }
  return all;
};

// Family #144774 · element #144774 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/design-store.mjs#L347-L350
export const f144774_pickStorage = s => {
  if (s) return { st: s };
  try { return { st: globalThis.localStorage ?? null }; } catch { return { st: null, blocked: true }; }
};

// Family #144810 · element #144810 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/drums.mjs#L70-L78
export const f144810_barrelRule = function barrelRule(cable, rules = []) {
  const armoured = /armoured/.test(cable.id);
  const want = cable.voltage_kv > 66 ? 'single_core_metallic_sheath' : armoured ? 'single_core_armoured' : 'single_core_unarmoured';
  const fits = rules.filter((r) => r.voltage_kv === cable.voltage_kv && r.when === 'final' && r.status === 'verified' && r.multiple_of_od > 0);
  const pool = fits.filter((r) => r.construction === want).length ? fits.filter((r) => r.construction === want) : fits;
  if (!pool.length) return { multiple: 15, source: 'No verified static rule in cables.json for this cable; 15 x OD assumed.' };
  const r = pool.reduce((a, b) => (b.multiple_of_od < a.multiple_of_od ? b : a));
  return { multiple: r.multiple_of_od, source: r.source };
};

// Family #144811 · element #144811 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/drums.mjs#L81-L87
export const f144811_drumCapacity = function drumCapacity(drum, odM, freeboard) {
  const layers = Math.floor((drum.flange - drum.barrel - 2 * Math.max(freeboard, odM)) / (2 * odM));
  const turns = Math.floor(drum.width / odM);
  let len = 0;
  for (let i = 1; i <= layers; i++) len += Math.PI * (drum.barrel + (2 * i - 1) * odM) * turns;
  return Math.max(0, len);
};

// Family #144814 · element #144814 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/drums.mjs#L115-L136
export const f144814_profile = function profile(route) {
  const cl = route.centreline;
  const n = cl.length;
  const plan = [0], d3 = [0];
  for (let k = 1; k < n; k++) {
    const dx = cl[k][0] - cl[k - 1][0], dy = cl[k][1] - cl[k - 1][1], dz = cl[k][2] - cl[k - 1][2];
    plan.push(plan[k - 1] + Math.hypot(dx, dy));
    d3.push(d3[k - 1] + Math.hypot(dx, dy, dz));
  }
  // Chords are a hair shorter than arcs; scale so the plan chainage matches the route's exact length2d.
  const f = plan[n - 1] > 0 ? route.length2d / plan[n - 1] : 1;
  for (let k = 0; k < n; k++) plan[k] *= f;
  const cores = (route.cores && route.cores.length ? route.cores : [{ polyline: cl }]).map((c) => {
    const acc = [0];
    for (let k = 1; k < n; k++) {
      const p = c.polyline[k], q = c.polyline[k - 1];
      acc.push(acc[k - 1] + Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]));
    }
    return acc;
  });
  return { cl, plan, d3, cores, n, xs: cl.map((p) => p[0]), ys: cl.map((p) => p[1]), zs: cl.map((p) => p[2]) };
};

// Family #144815 · element #144815 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/drums.mjs#L139-L147
export const f144815_interp = function interp(pr, arr, t) {
  const { d3, n } = pr;
  if (t <= 0) return arr[0];
  if (t >= d3[n - 1]) return arr[n - 1];
  let lo = 0, hi = n - 1;
  while (hi - lo > 1) { const m = (lo + hi) >> 1; if (d3[m] <= t) lo = m; else hi = m; }
  const u = (t - d3[lo]) / (d3[hi] - d3[lo] || 1);
  return arr[lo] + (arr[hi] - arr[lo]) * u;
};

// Family #144833 · element #144833 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/ground-readout.mjs#L13-L16
export const f144833_srcName = (sources, key) => {
  const s = sources?.[key];
  return (s && (s.title || s.name || s.id)) || '';
};

// Family #144835 · element #144835 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/ground-readout.mjs#L31-L37
export const f144835_mayLink = function mayLink(source, url) {
  if (typeof url !== 'string') return false;
  let u;
  try { u = new URL(url); } catch { return false; }
  if (u.protocol !== 'https:' || source?.allow_links === false) return false;
  return source?.allow_links === true || source?.scans?.link_only === true || /(^|\.)bgs\.ac\.uk$/i.test(u.hostname);
};

// Family #144841 · element #144841 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/hdd.mjs#L59-L64
export const f144841_lineOf = function lineOf(from, to) {
  const L = Math.hypot(to[0] - from[0], to[1] - from[1]);
  if (!(L > 0)) throw Error('hdd: the plan line needs two distinct points');
  const d = [(to[0] - from[0]) / L, (to[1] - from[1]) / L];
  return { L, d, xy: (s) => [from[0] + d[0] * s, from[1] + d[1] * s] };
};

// Family #144842 · element #144842 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/hdd.mjs#L67-L71
export const f144842_side = function side(zg, zb, a, R) {
  const drop = zg - zb, arcDrop = R * (1 - Math.cos(a));
  const tangent = (drop - arcDrop) / Math.sin(a);
  return { tangent, run: tangent * Math.cos(a) + R * Math.sin(a), arcRun: R * Math.sin(a) };
};

// Family #144846 · element #144846 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/hdd.mjs#L237-L241
export const f144846_noLayout = function noLayout(base, note) {
  return { ...base, layout: false, fit: { converged: false, residual: null }, entry: null, exit: null, segments: [],
    boreLength: null, planLength: null, samples: [], checks: [{ id: 'layout', ok: false, note }], ok: false, pits: [],
    lines: new Float32Array(0) };
};

// Family #144847 · element #144847 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/hdd.mjs#L246-L263
export const f144847_rootOut = function rootOut(f, start, end, valid = () => true) {
  const dir = end < start ? -1 : 1, n = Math.max(1, Math.ceil(Math.abs(end - start) / 0.1));
  const h = (s) => dir * -f(s);   // entry side: f > 0 at the obstacle; exit side: f < 0 at the obstacle
  let a = start, ha = h(a);
  if (!Number.isFinite(ha)) return { s: null, nan: true };
  if (ha <= 0 && valid(a)) return { s: a, residual: f(a) };
  for (let i = 1; i <= n; i++) {
    const b = i === n ? end : start + dir * 0.1 * i, hb = h(b);
    if (!Number.isFinite(hb)) return { s: null, nan: true };
    if (hb <= 0 && ha > 0) {
      let lo = a, hi = b;
      for (let k = 0; k < 80 && Math.abs(hi - lo) > 1e-9; k++) { const m = (lo + hi) / 2; if (h(m) > 0) lo = m; else hi = m; }
      if (valid(hi)) return { s: hi, residual: f(hi) };
    }
    a = b; ha = hb;
  }
  return { s: null, nan: false };
};

// Family #144862 · element #144862 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers-panel.mjs#L59-L64
export const f144862_statusLine = function statusLine(entry) {
  if (!entry) return 'Not in this site\'s data yet.';
  const s = String(entry.status || '').trim();
  if (!s) return 'No status given.';
  return s.charAt(0).toUpperCase() + s.slice(1) + (/[.!?]$/.test(s) ? '' : '.');
};

// Family #144896 · element #144896 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/canopy.mjs#L53-L57
export const f144896_blockOffset = function blockOffset(bi, bj, stride) {
  let x = (Math.imul(bi, 73856093) ^ Math.imul(bj, 19349663)) >>> 0;
  x = Math.imul(x ^ (x >>> 15), 2246822519) >>> 0; x = (x ^ (x >>> 13)) >>> 0;
  return [x % stride, (x >>> 8) % stride];
};

// Family #144898 · element #144898 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/canopy.mjs#L78-L86
export const f144898_along = function along(pts, step) {
  const out = [];
  for (let k = 0; k + 1 < pts.length; k++) {
    const [ax, ay, ah] = pts[k], [bx, by, bh] = pts[k + 1], L = Math.hypot(bx - ax, by - ay);
    const n = Math.max(1, Math.ceil(L / step));
    for (let m = k === 0 ? 0 : 1; m <= n; m++) { const f = m / n; out.push([ax + (bx - ax) * f, ay + (by - ay) * f, ah + (bh - ah) * f]); }
  }
  return out;
};

// Family #144917 · element #144917 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/contours.mjs#L35-L46
export const f144917_decodeContourTile = function decodeContourTile(doc) {
  if (!doc || doc.format !== 'ggc1') throw Error(`contour tile format "${doc && doc.format}" is not ggc1`);
  if (!Number.isFinite(doc.e0) || !Number.isFinite(doc.n0)) throw Error('contour tile has no south-west corner');
  const unit = doc.unit_m ?? 0.01;
  if (!(unit > 0)) throw Error('contour tile has no unit');
  if (!Array.isArray(doc.levels)) throw Error('contour tile has no levels list');
  for (const lv of doc.levels) {
    if (!Number.isFinite(lv.z) || !Array.isArray(lv.lines)) throw Error('contour level without z or lines');
    for (const l of lv.lines) if (!Array.isArray(l) || l.length % 2 || l.length < 4) throw Error(`contour line at ${lv.z} m is not a list of x, y pairs`);
  }
  return { e0: doc.e0, n0: doc.n0, unit, size: doc.tile_m || 256, tol: doc.dp_tol_m, levels: doc.levels };
};

// Family #144937 · element #144937 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/flow.mjs#L87-L90
export const f144937_colorFor = function colorFor(c, minClass, maxClass) {
  const f = maxClass > minClass ? Math.min(1, Math.max(0, (c - minClass) / (maxClass - minClass))) : 1;
  return [0.30 + 0.30 * f, 0.50 + 0.30 * f, 0.72 + 0.20 * f, 0.30 + 0.55 * f];
};

// Family #144983 · element #144983 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs#L38-L47
export const f144983_inside = 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;
};

// Family #144984 · element #144984 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs#L49-L53
export const f144984_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];
};

// Family #144988 · element #144988 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs#L103-L112
export const f144988_distToLine = 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;
};

// Family #144989 · element #144989 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs#L115-L124
export const f144989_cuts = 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;
};

// Family #144994 · element #144994 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/ground.mjs#L213-L217
export const f144994_groundStatus = 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`;
};

// Family #145016 · element #145016 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/shade.mjs#L96-L99
export const f145016_readSun = function readSun(s) {
  if (!s || !Number.isFinite(s.azimuth) || !Number.isFinite(s.elevation)) return null;
  return { azimuth: ((s.azimuth % 360) + 360) % 360, elevation: s.elevation };
};

// Family #145033 · element #145033 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/slope.mjs#L58-L61
export const f145033_downslope = function downslope(o) {
  const a = o * Math.PI / 4;
  return [Math.round(Math.sin(a) * 1e12) / 1e12, Math.round(Math.cos(a) * 1e12) / 1e12];
};

// Family #145136 · element #145136 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/offset.mjs#L23-L27
export const f145136_ringArea = function ringArea(ring) {
  let s = 0;
  for (let i = 0, n = ring.length; i < n; i++) { const a = ring[i], b = ring[(i + 1) % n]; s += a[0] * b[1] - b[0] * a[1]; }
  return s / 2;
};

// Family #145137 · element #145137 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/offset.mjs#L30-L37
export const f145137_pointInRing = function pointInRing(ring, x, y) {
  let inside = false;
  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 < (xj - xi) * (y - yi) / (yj - yi) + xi) inside = !inside;
  }
  return inside;
};

// Family #145139 · element #145139 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/offset.mjs#L60-L63
export const f145139_piece = function piece(pts, id) {
  const xs = pts.map(p => p[0]), ys = pts.map(p => p[1]);
  return { pts, id, box: [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)] };
};

// Family #145141 · element #145141 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/offset.mjs#L71-L74
export const f145141_rect = function rect(a, b, d) {
  const L = Math.hypot(b[0] - a[0], b[1] - a[1]), nx = -(b[1] - a[1]) / L * d, ny = (b[0] - a[0]) / L * d;
  return [[a[0] - nx, a[1] - ny], [b[0] - nx, b[1] - ny], [b[0] + nx, b[1] + ny], [a[0] + nx, a[1] + ny]];
};

// Family #145145 · element #145145 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/offset.mjs#L108-L122
export const f145145_makeGrid = function makeGrid(h) {
  const cells = new Map(), key = (i, j) => i * 1e6 + j;
  const range = (lo, hi) => [Math.floor(lo / h), Math.floor(hi / h)];
  return {
    h, cells,
    add(box, v) {
      const [i0, i1] = range(box[0], box[2]), [j0, j1] = range(box[1], box[3]);
      for (let i = i0; i <= i1; i++) for (let j = j0; j <= j1; j++) {
        const k = key(i, j); let c = cells.get(k); if (!c) cells.set(k, c = []); c.push(v);
      }
    },
    at(x, y) { return cells.get(key(Math.floor(x / h), Math.floor(y / h))) || []; },
    cellOf(x, y) { return key(Math.floor(x / h), Math.floor(y / h)); }
  };
};

// Family #145166 · element #145166 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L55-L58
export const f145166_frame = function frame(centre, heading = 0) {
  const s = Math.sin(heading), c = Math.cos(heading), [cx, cy] = centre;
  return (u, v) => [cx + u * c + v * s, cy - u * s + v * c];
};

// Family #145182 · element #145182 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L291-L298
export const f145182_boxEdges = function boxEdges(c, z0, z1) {
  const out = [];
  for (let i = 0; i < 4; i++) {
    const p = c[i], q = c[(i + 1) % 4];
    out.push([p[0], p[1], z0], [q[0], q[1], z0], [p[0], p[1], z1], [q[0], q[1], z1], [p[0], p[1], z0], [p[0], p[1], z1]);
  }
  return out;
};

// Family #145183 · element #145183 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L302-L305
export const f145183__anonymous_ = b => {
    const xs = b.corners.map(p => p[0]), ys = b.corners.map(p => p[1]);
    return { min: [Math.min(...xs), Math.min(...ys), b.z0], max: [Math.max(...xs), Math.max(...ys), b.z1] };
  };

// Family #145195 · element #145195 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/phases-slider.mjs#L6-L16
export const f145195_sliderModel = function sliderModel(timeline, step) {
  const s = timeline.clamp(Math.round(Number(step) || 0));
  const snap = timeline.stateAt(s);
  const ticks = [];
  let acc = 0;
  for (const p of timeline.plan.phases) { ticks.push({ step: acc, name: p.name }); acc += p.steps; }
  return {
    min: 0, max: timeline.totalSteps, value: s, label: timeline.label(s), ticks, counts: snap.counts,
    summary: `${snap.counts.complete} complete, ${snap.items.length - snap.counts.planned - snap.counts.complete} in progress, ${snap.counts.planned} planned`
  };
};

// Family #145198 · element #145198 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/phases.mjs#L47-L49
export const f145198_issue = function issue(severity, code, message, extra = {}) {