GLOBALGRID2050 / EXPLORE CODE

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

Standalone (part 14)

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 1576 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 9640–10339

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 9640–10339 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
sameLocation, sameEntity, createComputeObserver, publish, get, describeComputeReceipt, f142073__anonymous_, pieces, line, ring, final, shown, guard, f131973_segDist2, f179800__anonymous_, f179801_normalize, scalar, f179813__anonymous_, f65297_esc, f65299_endLine, f66668_siteKey, f151664_toScreen, f151665_excel, f145079_cumulative, f145080_pointAt, f145081_distToLine, f145168_insidePoly, f145169_edgeDistance, f145177_nearPad, f74936_invariant
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:9640-10339 · 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
  && Math.abs(point.lon) <= 180 && Math.abs(point.lat) <= 90;
const sameLocation = (a, b) => located(a) && located(b) && a.lon === b.lon && a.lat === b.lat;
const sameEntity = (a, b) => a && b && a.kind === b.kind && String(a.id) === String(b.id);

/**
 * Create one observer per selection surface, not one per project. Every request
 * invalidates the previous selection for assessment, including repeated IDs.
 * Receipts are evidence about the supplied callback, not proof that a renderer
 * used this module. Attach run() at the real calculation call site.
 */
function createComputeObserver({ onEvent = () => {}, now = () => Date.now() } = {}) {
  const attempts = new Map();
  let sequence = 0;
  let latest = null;
  const publish = (attempt, status, extra = {}) => {
    Object.assign(attempt, extra, { status, sequence: ++sequence, updated_at_ms: now() });
    attempt.events.push({ status, sequence: attempt.sequence, at_ms: attempt.updated_at_ms });
    // A broken logging consumer must never break the grid calculation itself.
    try { onEvent(copy(attempt)); } catch { /* receipt remains queryable */ }
    return copy(attempt);
  };
  const get = id => {
    const attempt = attempts.get(id);
    if (!attempt) throw new Error('Unknown computation attempt: ' + id);
    return attempt;
  };
  return {
    request({ entity, location = null, operation = 'nearest-grid', dataset = null }) {
      if (!entity || typeof entity.kind !== 'string' || !entity.kind.trim()
          || entity.id == null || !String(entity.id).trim()) {
        throw new TypeError('A computation request requires an entity kind and ID');
      }
      const id = 'compute-' + (sequence + 1);
      const attempt = {
        schema, id, entity: { kind: entity.kind, id: String(entity.id) },
        location: located(location) ? { lon: location.lon, lat: location.lat } : null,
        operation, dataset, requested_at_ms: now(), events: []
      };
      attempts.set(id, attempt);
      latest = id;
      publish(attempt, 'requested');
      return id;
    },
    unsupported(id, reason) {
      const attempt = get(id);
      if (attempt.status !== 'requested') throw new Error('Attempt already invoked or terminal');
      return publish(attempt, 'unsupported', { reason: String(reason || 'Unsupported input') });
    },
    async run(id, compute) {
      const attempt = get(id);
      if (attempt.status !== 'requested') throw new Error('Attempt already invoked or terminal');
      if (!attempt.location) return publish(attempt, 'unsupported', { reason: 'No valid project location' });
      if (typeof compute !== 'function') return publish(attempt, 'failed', { reason: 'No computation callback' });
      publish(attempt, 'started');
      try {
        const result = await compute(copy(attempt));
        if (!sameLocation(result?.origin, attempt.location)) throw new Error('Result origin does not match this request');
        if (!sameEntity(result?.entity, attempt.entity)) throw new Error('Result entity does not match this request');
        if (!Array.isArray(result.measurements)) throw new Error('Computation returned no measurements array');
        if (result.measurements.length === 0) {
          if (result.search_completed !== true || !Number.isInteger(result.scanned_count) || result.scanned_count < 0) {
            throw new Error('Empty result lacks completed-search and scanned-count evidence');
          }
          return publish(attempt, 'completed_empty', { measurements: [],
            summary: { measured_count: 0, scanned_count: result.scanned_count, nearest_km: null } });
        }
        const measurements = result.measurements.map(row => {
          if (!row || row.node_id == null || !String(row.node_id).trim()
              || !located(row) || !finite(row.km) || row.km < 0) {
            throw new Error('Computation returned an invalid grid measurement');
          }
          const expected = distanceKm(attempt.location.lon, attempt.location.lat, row.lon, row.lat);
          // Receipts carry unrounded values from the shared geodesy, not UI text.
          if (Math.abs(expected - row.km) > Math.max(1e-6, expected * 1e-9)) {
            throw new Error('Grid distance does not match the request and measured node');
          }
          return { node_id: String(row.node_id), lon: row.lon, lat: row.lat, km: row.km };
        });
        return publish(attempt, 'completed', { measurements,
          summary: { measured_count: measurements.length, nearest_km: Math.min(...measurements.map(row => row.km)) } });
      } catch (error) {
        return publish(attempt, 'failed', { reason: String(error?.message || error) });
      }
    },
    snapshot(id = latest) { return id == null ? null : copy(get(id)); },
    assess(id, expected) {
      if (!attempts.has(id)) return { passed: false, reason: 'never-requested' };
      const attempt = get(id);
      if (id !== latest) return { passed: false, reason: 'stale-attempt' };
      if (!sameEntity(attempt.entity, expected?.entity) || !sameLocation(attempt.location, expected?.location)) {
        return { passed: false, reason: 'selection-mismatch' };
      }
      return { passed: attempt.status === 'completed', reason: attempt.status };
    }
  };
}

/** Honest UI projection of computation receipts. No inference from a URL. */
function describeComputeReceipt(receipt) {
  const status = receipt?.status || 'not_requested';
  const summary = receipt?.summary;
  const nearest = summary?.nearest_km;
  const labels = {
    not_requested: 'Grid calculation not requested', requested: 'Grid calculation queued',
    started: 'Calculating nearest mapped substations', completed_empty: 'Search completed: no mapped substations returned',
    unsupported: 'Grid calculation unavailable', failed: 'Grid calculation failed',
  };
  if (status === 'completed' && Number.isFinite(nearest) && nearest >= 0) {
    return { status, text: `Nearest mapped substation: ${nearest.toFixed(2)} km`,
      distance_km: nearest, unit: 'km', scope: 'Geometric screening only; not an electrical connection, capacity or offer.' };
  }
  return { status, text: labels[status] || 'Grid calculation result unavailable',
    reason: receipt?.reason || null, distance_km: null, unit: null,
    scope: 'Geometric screening only; not an electrical connection, capacity or offer.' };
}

globalThis.VentusGridCompute = Object.freeze({ schema, distanceKm, createComputeObserver, describeComputeReceipt });
};

// Family #142073 · element #142073 · 6 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/kuiper-grid/i0094/cartridges/009400000000-kuiper-programs.js#L3763-L4032
export const f142073__anonymous_ = function (root) {
  var F = root.FIRE; if (!F || !F.register) return;

  /* the kind registers itself, the way the file asks a program to */
  var K = root.FIRE_SLD_KIND || (root.FIRE_SLD_KIND = {});
  K['site'] = 'site';

  var BLOCKS_DRAWN = 8;          /* columns across the busbar */
  var TEETH = 4;                 /* string GROUPS drawn per block, not strings */

  /* THE BINS, read off published datasheets and carried here as numbers.
     phi COMES FROM A RATIO OF TWO PRINTED NUMBERS, K_Corr = Isc(BNPI)/Isc(STC),
     divided by the rear irradiance of the BNPI condition:
         phi = (K_Corr - 1) / 0.135

     AND THE TWO FAMILIES ARE NOT ON THE SAME FOOTING. One sheet PRINTS its
     BNPI condition - front 1000 W/m2, rear 135 W/m2, 25 C, AM 1.5 - so for
     those bins phi is derived and the 0.135 is theirs. The other sheet HEADS
     a column BNPI and never defines the irradiance condition anywhere; only
     STC and NOCT are in its footnote. For those bins, dividing by 0.135
     imports the first sheet's condition into the second, and phi is an
     ASSUMPTION wearing a derivation's clothes.

     This file said 'derived, not assumed' about both. That was true of one
     family and false of the other, and the family it was false about is the
     DEFAULT. bnpi_stated carries which is which and the card now says so.
     The class ids are power-bin labels; no maker or product is named. */
  var BINS = {
    'T645': { bnpi_stated:false, voc:45.30, isc:18.31, imp:17.23, beta:-0.25, alpha:0.04, kcorr:1.0945, fuse:35, label:'645 W class' },
    'T650': { bnpi_stated:false, voc:45.50, isc:18.35, imp:17.27, beta:-0.25, alpha:0.04, kcorr:1.0943, fuse:35, label:'650 W class' },
    'T655': { bnpi_stated:false, voc:45.70, isc:18.40, imp:17.31, beta:-0.25, alpha:0.04, kcorr:1.0946, fuse:35, label:'655 W class' },
    'T660': { bnpi_stated:false, voc:45.90, isc:18.45, imp:17.35, beta:-0.25, alpha:0.04, kcorr:1.0943, fuse:35, label:'660 W class' },
    'T665': { bnpi_stated:false, voc:46.10, isc:18.50, imp:17.39, beta:-0.25, alpha:0.04, kcorr:1.0946, fuse:35, label:'665 W class, the top bin a 0 to +5 W tolerance can deliver' },
    'W750': { bnpi_stated:true, voc:50.53, isc:18.56, imp:17.70, beta:-0.22, alpha:0.04, kcorr:1.1148, fuse:35, label:'750 W class' },
    'W755': { bnpi_stated:true, voc:50.56, isc:18.59, imp:17.78, beta:-0.22, alpha:0.04, kcorr:1.1151, fuse:35, label:'755 W class' },
    'W760': { bnpi_stated:true, voc:50.59, isc:18.62, imp:17.85, beta:-0.22, alpha:0.04, kcorr:1.1149, fuse:35, label:'760 W class' },
    'W765': { bnpi_stated:true, voc:50.62, isc:18.65, imp:17.93, beta:-0.22, alpha:0.04, kcorr:1.1153, fuse:35, label:'765 W class' },
    'W770': { bnpi_stated:true, voc:50.65, isc:18.68, imp:18.00, beta:-0.22, alpha:0.04, kcorr:1.1151, fuse:35, label:'770 W class' }
  };
  var BNPI_REAR = 0.135, TABLE_TOP = 25;     /* the sheet's own top rear-gain row */
  var V_CEIL = 1500;                         /* equipment rating, not a standards limit */
  var STRING_INPUT_A = 20, MPPT_INPUT_A = 40, STRINGS_PER_MPPT = 2, SIZING = 1.25;

  function pieces() {
    var P = [];
    function line(tag, d, x0, y0, x1, y1) {
      P.push({ tag:tag, d:d, kind:'line', x0:x0, y0:y0, x1:x1, y1:y1,
               len:Math.hypot(x1 - x0, y1 - y0) });
    }
    function ring(tag, d, cx, cy, r) {
      P.push({ tag:tag, d:d, kind:'ring', cx:cx, cy:cy, r:r, len:2 * Math.PI * r });
    }

    ring('grid', 0, 0, 0.90, 0.07);                    /* the grid */
    line('interface', 0.07, 0, 0.83, 0, 0.70);
    ring('tx', 0.14, 0, 0.655, 0.05);                  /* down to the collection voltage */
    ring('tx', 0.24, 0, 0.575, 0.05);
    line('board', 0.34, 0, 0.525, 0, 0.455);
    line('bus', 0.42, -0.92, 0.425, 0.92, 0.425);      /* the collection busbar */
    line('bus', 0.42, -0.92, 0.405, 0.92, 0.405);

    var n = BLOCKS_DRAWN;
    for (var i = 0; i < n; i++) {
      var x = n === 1 ? 0 : -0.82 + 1.64 * i / (n - 1);
      var d0 = 0.45 + Math.abs(x);                     /* further out is further along */
      var t = 'b' + i;
      line(t, d0, x, 0.395, x, 0.315);                 /* feeder off the busbar */
      ring(t, d0 + 0.09, x, 0.275, 0.035);             /* the switch */
      ring('sk' + i, d0 + 0.16, x, 0.195, 0.042);      /* skid transformer, two rings */
      ring('sk' + i, d0 + 0.24, x, 0.118, 0.042);
      line(t, d0 + 0.31, x, 0.070, x, 0.030);
      ring('inv', d0 + 0.36, x, -0.015, 0.045);        /* the inverter, a symbol */
      line('dc' + i, d0 + 0.44, x, -0.062, x, -0.150); /* the DC it eats */
      var w = 0.072;
      line('dc' + i, d0 + 0.50, x - w, -0.150, x + w, -0.150);
      /* THE TEETH ARE NOT TAGGED 'pv', AND THAT IS NOT A NAMING WHIM.
         sldLayout decides which pieces are SYMBOLS - pieces given a floor of
         dots so they read as the thing they are - with a PREFIX match:
         t.startsWith('pv'). That was written when a network drawing had one
         solar symbol on it. Tagging 32 comb pieces 'pv' claimed 32 symbol
         floors, which is 704 of the 896 dots the whole drawing gets, and the
         rounding loop cannot take a symbol below its floor. The collection
         busbar - the spine of the picture - was left with scraps and did not
         appear at all. The blocks hung off nothing. */
      for (var j = 0; j < TEETH; j++) {                /* teeth are GROUPS of strings */
        var tx = x - w + 2 * w * j / (TEETH - 1);
        line('sr' + i, d0 + 0.54, tx, -0.150, tx, -0.300);
        ring('sr' + i, d0 + 0.62, tx, -0.340, 0.020);
      }
    }
    return P;
  }

  /* brightness per tag: 0..1 lit, 2 = outside a rating (amber), -1 = dark */
  function final(s, tag) {
    return tag.map(function (t) {
      if (t === 'grid' || t === 'interface' || t === 'bus') return 0.95;
      if (t === 'tx' || t === 'board') return 0.90;
      if (t.indexOf('sk') === 0) return 0.85;
      if (t === 'inv') return s.over_mppt ? 2 : 1;          /* the machine's own input */
      if (t.indexOf('sr') === 0) return s.over_volts ? 2 : 1;  /* the array's voltage */
      if (t.indexOf('dc') === 0) return s.over_string ? 2 : 0.9;  /* the string's current */
      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 */

    var s = { over_volts:over_volts, over_string:over_string, over_mppt:over_mppt };
    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 #131973 · element #131973 · 4 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/iterations/04-400kv-engine/layers-panel.mjs#L970-L975
export const f131973_segDist2 = function segDist2(px, py, ax, ay, bx, by) {
  const dx = bx - ax, dy = by - ay, L = dx * dx + dy * dy;
  const t = L ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / L)) : 0;
  const qx = ax + t * dx - px, qy = ay + t * dy - py;
  return qx * qx + qy * qy;
};

// Family #179800 · element #179800 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/modules/202612010912-ukpn-secondary-substations.js#L91-L96
export const f179800__anonymous_ = s=>({
      type:'Feature', id:s.site, geometry:{type:'Point',coordinates:s.coords},
      properties:{name:s.site, type:'Secondary substation (transformer register)', operator:'UK Power Networks ('+s.dno+')',
        voltage:[...s.voltages].sort((a,b)=>a-b).map(v=>v+' kV primary').join(', '),
        transformer_count:s.ids.size, ukpn_transformers:JSON.stringify([...s.details.values()]), source:'UK Power Networks secondary site transformers', asset_class:'secondary_substation'}
    });

// Family #179801 · element #179801 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/modules/202612010912-ukpn-secondary-substations.js#L63-L100
export const f179801_normalize = function normalize(raw) {
    if (raw?.type !== 'FeatureCollection' || raw.features?.length !== 74719)
      throw Error('UKPN source row count mismatch');
    const sites = new Map(), transformers = new Set();
    let points = 0;
    for (const f of raw.features) {
      const p = f.properties || {}, site = p.secondarysitefunctionallocation;
      if (typeof site !== 'string' || !site || typeof p.transformerfunctionallocation !== 'string' ||
          !['EPN','SPN','LPN'].includes(p.dno)) throw Error('UKPN identity invalid');
      transformers.add(p.transformerfunctionallocation);
      let s = sites.get(site);
      if (!s) {s = {site, dno:p.dno, coords:null, ids:new Set(), voltages:new Set(), details:new Map()}; sites.set(site,s);}
      if (s.dno !== p.dno) throw Error('UKPN conflicting network');
      s.ids.add(p.transformerfunctionallocation);
      // Retain distinct published values, not an arbitrary winner for duplicate FLOCs.
      const scalar=v=>typeof v==='number'&&Number.isFinite(v)||typeof v==='string'&&v.trim()?v:null;
      const detail=[p.transformerfunctionallocation,scalar(p.primarywinding),scalar(p.secondarywinding),scalar(p.onanrating),scalar(p.opvolts)];
      s.details.set(JSON.stringify(detail),detail);
      if (typeof p.primarywinding === 'number' && p.primarywinding > 0) s.voltages.add(p.primarywinding);
      if (f.geometry === null) continue;
      const c = f.geometry?.coordinates;
      if (f.geometry?.type !== 'Point' || !Array.isArray(c) || c.length !== 2 ||
          !c.every(Number.isFinite) || c[0] < -11 || c[0] > 3 || c[1] < 49.5 || c[1] > 61.5)
        throw Error('UKPN invalid point');
      points++;
      if (s.coords && (s.coords[0] !== c[0] || s.coords[1] !== c[1])) throw Error('UKPN conflicting site points');
      s.coords = c;
    }
    const features = [...sites.values()].filter(s=>s.coords).sort((a,b)=>a.site < b.site ? -1 : a.site > b.site ? 1 : 0).map(s=>({
      type:'Feature', id:s.site, geometry:{type:'Point',coordinates:s.coords},
      properties:{name:s.site, type:'Secondary substation (transformer register)', operator:'UK Power Networks ('+s.dno+')',
        voltage:[...s.voltages].sort((a,b)=>a-b).map(v=>v+' kV primary').join(', '),
        transformer_count:s.ids.size, ukpn_transformers:JSON.stringify([...s.details.values()]), source:'UK Power Networks secondary site transformers', asset_class:'secondary_substation'}
    }));
    if (sites.size !== 56309 || features.length !== 54558 || points !== 56685 || transformers.size !== 74712)
      throw Error('UKPN source closure mismatch');
    return {type:'FeatureCollection',features};
  };

// Family #179813 · element #179813 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/modules/202612010912-ukpn-secondary-substations.js#L254-L259
export const f179813__anonymous_ = raw=>{
        const row=typeof raw.toJSON==='function'?raw.toJSON():raw;
        const id=String(row.feature_id), geometry=JSON.parse(String(row.geometry_json)), properties=JSON.parse(String(row.properties_json));
        if(!id||properties.name!==id||geometry.type!=='Point'||!geometry.coordinates?.every(Number.isFinite))throw Error('UKPN map row invalid');
        return {type:'Feature',id,geometry,properties};
      };

// Family #65297 · element #65297 · 40 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/cartridges/202609071232-sld-sandbox-v9-8.js#L7501-L7503
export const f65297_esc = function esc(value) {
    return String(value == null ? '' : value).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
  };

// Family #65299 · element #65299 · 40 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/cartridges/202609071232-sld-sandbox-v9-8.js#L7511-L7518
export const f65299_endLine = function endLine(end, km) {
    if (!end) return 'not held';
    if (end.coverage === 'NONE') return end.statement;
    if (end.nearest_km === null) return 'no substation within the payload';
    return (end.nearest_name || 'nearest substation') + ' at ' + end.nearest_km + ' km'
      + (end.nearest_beyond_search ? ' (beyond the ' + km + ' km search)' : '')
      + ' · ' + end.within + ' within ' + km + ' km';
  };

// Family #66668 · element #66668 · 35 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/cartridges/202609080430-sld-sandbox-v9-8.js#L1926-L1934
export const f66668_siteKey = function siteKey(value) {
    return String(value || '')
      .toLowerCase()
      .replace(/\d+\s*\/?\s*\d*\s*kv/g, ' ')
      .replace(/[^a-z0-9 ]/g, ' ')
      .replace(/\b(substation|substations|gsp|grid supply point|node|platform|offshores?|the)\b/g, ' ')
      .replace(/\s+/g, ' ')
      .trim();
  };

// Family #151664 · element #151664 · 14 places in 1 repositories · https://github.com/Ventusltd/kuiper-belt/blob/5f49da3d53de024852bbe60993add7a0c4cd5812/learn-the-kuiper/202610042225/kuiper-law.js#L83-L85
export const f151664_toScreen = function toScreen(x, y, cam, W, H){
    return [ W/2 + (x - cam.cx) * cam.zoom, H/2 - (y - cam.cy) * cam.zoom ];
  };

// Family #151665 · element #151665 · 14 places in 1 repositories · https://github.com/Ventusltd/kuiper-belt/blob/5f49da3d53de024852bbe60993add7a0c4cd5812/learn-the-kuiper/202610042225/kuiper-law.js#L102-L106
export const f151665_excel = function (key) {
      const k = +key, deg = (k * 137.507764) % 360, th = deg * Math.PI / 180, r = Math.sqrt(k);
      return { key: k, deg: deg, turns: deg / 360, theta: th, r: r, x: r*Math.cos(th), y: r*Math.sin(th),
               label: 'NOT THE REAL KUIPER: Excel spiral, 137.507764 deg per key anticlockwise, r = sqrt(key)' };
    };

// Family #145079 · element #145079 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/water.mjs#L43-L47
export const f145079_cumulative = function cumulative(pts) {
  const cum = [0];
  for (let i = 1; i < pts.length; i++) cum.push(cum[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
  return cum;
};

// Family #145080 · element #145080 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/water.mjs#L50-L58
export const f145080_pointAt = function pointAt(pts, cum, s) {
  const L = cum[cum.length - 1];
  if (s <= 0) return [pts[0][0], pts[0][1]];
  if (s >= L) return [pts[pts.length - 1][0], pts[pts.length - 1][1]];
  let lo = 0, hi = cum.length - 1;
  while (hi - lo > 1) { const m = (lo + hi) >> 1; if (cum[m] <= s) lo = m; else hi = m; }
  const f = (s - cum[lo]) / (cum[hi] - cum[lo] || 1);
  return [pts[lo][0] + (pts[hi][0] - pts[lo][0]) * f, pts[lo][1] + (pts[hi][1] - pts[lo][1]) * f];
};

// Family #145081 · element #145081 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/layers/water.mjs#L61-L69
export const f145081_distToLine = function distToLine(pts, x, y) {
  let best = Infinity;
  for (let i = 1; i < pts.length; i++) {
    const [ax, ay] = pts[i - 1], [bx, by] = pts[i], dx = bx - ax, dy = by - ay, d2 = dx * dx + dy * dy;
    const t = d2 ? Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / d2)) : 0;
    best = Math.min(best, Math.hypot(x - ax - t * dx, y - ay - t * dy));
  }
  return pts.length === 1 ? Math.hypot(x - pts[0][0], y - pts[0][1]) : best;
};

// Family #145168 · element #145168 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L80-L88
export const f145168_insidePoly = function insidePoly(x, y, vx, vy) {
  let ins = false;
  for (let i = 0, n = vx.length; i < n; i++) {
    const j = (i - 1 + n) % n, x1 = vx[i], y1 = vy[i], x2 = vx[j], y2 = vy[j];
    if (y1 === y2) continue;
    if ((y1 > y) !== (y2 > y) && x < x1 + (y - y1) * (x2 - x1) / (y2 - y1)) ins = !ins;
  }
  return ins;
};

// Family #145169 · element #145169 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L91-L99
export const f145169_edgeDistance = function edgeDistance(x, y, pts) {
  let best = Infinity;
  for (let i = 0, n = pts.length; i < n; i++) {
    const [ax, ay] = pts[i], [bx, by] = pts[(i + 1) % n], dx = bx - ax, dy = by - ay;
    const t = Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / (dx * dx + dy * dy)));
    best = Math.min(best, Math.hypot(x - ax - t * dx, y - ay - t * dy));
  }
  return best;
};

// Family #145177 · element #145177 · 12 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270005-site-world-v3/world/pad.mjs#L220-L226
export const f145177_nearPad = function nearPad(p, x, y) {
  if (!p.box) {
    const xs = p.polygon.map(q => q[0]), ys = p.polygon.map(q => q[1]), r = p.reach + p.cell;
    p.box = [Math.min(...xs) - r, Math.min(...ys) - r, Math.max(...xs) + r, Math.max(...ys) + r];
  }
  return x >= p.box[0] && y >= p.box[1] && x <= p.box[2] && y <= p.box[3];
};

// Family #74936 · element #74936 · 10 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/releases/javascript/202608270055-v8-fast-runtime.js#L199-L201
export const f74936_invariant = function invariant(condition, message) {
  if (!condition) throw new Error(`PipelineNews V8 fast runtime: ${message}`);
};

// Family #181009 · element #181009 · 5 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/modules/202612032137-orient17a-camera.js#L113-L121
export const f181009_cameraTarget = function cameraTarget(map,fix,streetZoom){
    if (!map || !fix) return null;
    const target={center:[fix.longitude,fix.latitude]};
    if(streetZoom){
      const current=map.getZoom(), maximum=map.getMaxZoom();
      if(Number.isFinite(current)&&Number.isFinite(maximum))target.zoom=Math.min(maximum,Math.max(17,current));
    }
    return target;
  };

// Family #181010 · element #181010 · 5 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/modules/202612032137-orient17a-camera.js#L122-L124
export const f181010_shouldAcceptCameraFix = function shouldAcceptCameraFix(fix,quality,requestedAt,hidden){
    return !hidden && quality==="usable" && fix!==null && Number.isFinite(fix.timestampMs) && (requestedAt===null||fix.timestampMs>=requestedAt);
  };

// Family #71451 · element #71451 · 3 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/tools/proofs/202609041250-menu-bar-instrument-panel.browser.mjs#L79-L81
export const f71451__anonymous_ = (id) => `
  <label class="key-item"><input type="checkbox" data-pn-layer="${id}">
    <span data-pn-label="${id}">${id}</span></label>`;

// Family #142498 · element #142498 · 3 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/kuiper-grid/drawing/kuiper-programs.js#L3881-L3898
export const f142498_final = function final(s, tag) {
    return tag.map(function (t) {
      if (t === 'grid' || t === 'interface' || t === 'bus') return 0.95;
      if (t === 'tx' || t === 'board') return 0.90;
      if (t.indexOf('sk') === 0) return 0.85;
      if (t === 'inv') return s.over_mppt ? 2 : 1;          /* the machine's own input */
      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;
    });
  };

// Family #142501 · element #142501 · 3 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/kuiper-grid/drawing/kuiper-programs.js#L3787-L4071
export const f142501__anonymous_ = function (root) {
  var F = root.FIRE; if (!F || !F.register) return;

  /* the kind registers itself, the way the file asks a program to */
  var K = root.FIRE_SLD_KIND || (root.FIRE_SLD_KIND = {});
  K['site'] = 'site';

  var BLOCKS_DRAWN = 8;          /* columns across the busbar */
  var TEETH = 4;                 /* string GROUPS drawn per block, not strings */

  /* THE BINS, read off published datasheets and carried here as numbers.
     phi COMES FROM A RATIO OF TWO PRINTED NUMBERS, K_Corr = Isc(BNPI)/Isc(STC),
     divided by the rear irradiance of the BNPI condition:
         phi = (K_Corr - 1) / 0.135

     AND THE TWO FAMILIES ARE NOT ON THE SAME FOOTING. One sheet PRINTS its
     BNPI condition - front 1000 W/m2, rear 135 W/m2, 25 C, AM 1.5 - so for
     those bins phi is derived and the 0.135 is theirs. The other sheet HEADS
     a column BNPI and never defines the irradiance condition anywhere; only
     STC and NOCT are in its footnote. For those bins, dividing by 0.135
     imports the first sheet's condition into the second, and phi is an
     ASSUMPTION wearing a derivation's clothes.

     This file said 'derived, not assumed' about both. That was true of one
     family and false of the other, and the family it was false about is the
     DEFAULT. bnpi_stated carries which is which and the card now says so.
     The class ids are power-bin labels; no maker or product is named. */
  var BINS = {
    'T645': { bnpi_stated:false, voc:45.30, isc:18.31, imp:17.23, beta:-0.25, alpha:0.04, kcorr:1.0945, fuse:35, label:'645 W class' },
    'T650': { bnpi_stated:false, voc:45.50, isc:18.35, imp:17.27, beta:-0.25, alpha:0.04, kcorr:1.0943, fuse:35, label:'650 W class' },
    'T655': { bnpi_stated:false, voc:45.70, isc:18.40, imp:17.31, beta:-0.25, alpha:0.04, kcorr:1.0946, fuse:35, label:'655 W class' },
    'T660': { bnpi_stated:false, voc:45.90, isc:18.45, imp:17.35, beta:-0.25, alpha:0.04, kcorr:1.0943, fuse:35, label:'660 W class' },
    'T665': { bnpi_stated:false, voc:46.10, isc:18.50, imp:17.39, beta:-0.25, alpha:0.04, kcorr:1.0946, fuse:35, label:'665 W class, the top bin a 0 to +5 W tolerance can deliver' },
    'W750': { bnpi_stated:true, voc:50.53, isc:18.56, imp:17.70, beta:-0.22, alpha:0.04, kcorr:1.1148, fuse:35, label:'750 W class' },
    'W755': { bnpi_stated:true, voc:50.56, isc:18.59, imp:17.78, beta:-0.22, alpha:0.04, kcorr:1.1151, fuse:35, label:'755 W class' },
    'W760': { bnpi_stated:true, voc:50.59, isc:18.62, imp:17.85, beta:-0.22, alpha:0.04, kcorr:1.1149, fuse:35, label:'760 W class' },
    'W765': { bnpi_stated:true, voc:50.62, isc:18.65, imp:17.93, beta:-0.22, alpha:0.04, kcorr:1.1153, fuse:35, label:'765 W class' },
    'W770': { bnpi_stated:true, voc:50.65, isc:18.68, imp:18.00, beta:-0.22, alpha:0.04, kcorr:1.1151, fuse:35, label:'770 W class' }
  };
  var BNPI_REAR = 0.135, TABLE_TOP = 25;     /* the sheet's own top rear-gain row */
  var V_CEIL = 1500;                         /* equipment rating, not a standards limit */
  var STRING_INPUT_A = 20, MPPT_INPUT_A = 40, STRINGS_PER_MPPT = 2, SIZING = 1.25;

  function pieces() {
    var P = [];
    function line(tag, d, x0, y0, x1, y1) {
      P.push({ tag:tag, d:d, kind:'line', x0:x0, y0:y0, x1:x1, y1:y1,
               len:Math.hypot(x1 - x0, y1 - y0) });
    }
    function ring(tag, d, cx, cy, r) {
      P.push({ tag:tag, d:d, kind:'ring', cx:cx, cy:cy, r:r, len:2 * Math.PI * r });
    }

    ring('grid', 0, 0, 0.90, 0.07);                    /* the grid */
    line('interface', 0.07, 0, 0.83, 0, 0.70);
    ring('tx', 0.14, 0, 0.655, 0.05);                  /* down to the collection voltage */
    ring('tx', 0.24, 0, 0.575, 0.05);
    line('board', 0.34, 0, 0.525, 0, 0.455);
    line('bus', 0.42, -0.92, 0.425, 0.92, 0.425);      /* the collection busbar */
    line('bus', 0.42, -0.92, 0.405, 0.92, 0.405);

    var n = BLOCKS_DRAWN;
    for (var i = 0; i < n; i++) {
      var x = n === 1 ? 0 : -0.82 + 1.64 * i / (n - 1);
      var d0 = 0.45 + Math.abs(x);                     /* further out is further along */
      var t = 'b' + i;
      line(t, d0, x, 0.395, x, 0.315);                 /* feeder off the busbar */
      ring(t, d0 + 0.09, x, 0.275, 0.035);             /* the switch */
      ring('sk' + i, d0 + 0.16, x, 0.195, 0.042);      /* skid transformer, two rings */
      ring('sk' + i, d0 + 0.24, x, 0.118, 0.042);
      line(t, d0 + 0.31, x, 0.070, x, 0.030);
      ring('inv', d0 + 0.36, x, -0.015, 0.045);        /* the inverter, a symbol */
      line('dc' + i, d0 + 0.44, x, -0.062, x, -0.150); /* the DC it eats */
      var w = 0.072;
      line('dc' + i, d0 + 0.50, x - w, -0.150, x + w, -0.150);
      /* THE TEETH ARE NOT TAGGED 'pv', AND THAT IS NOT A NAMING WHIM.
         sldLayout decides which pieces are SYMBOLS - pieces given a floor of
         dots so they read as the thing they are - with a PREFIX match:
         t.startsWith('pv'). That was written when a network drawing had one
         solar symbol on it. Tagging 32 comb pieces 'pv' claimed 32 symbol
         floors, which is 704 of the 896 dots the whole drawing gets, and the
         rounding loop cannot take a symbol below its floor. The collection
         busbar - the spine of the picture - was left with scraps and did not
         appear at all. The blocks hung off nothing. */
      for (var j = 0; j < TEETH; j++) {                /* teeth are GROUPS of strings */
        var tx = x - w + 2 * w * j / (TEETH - 1);
        line('sr' + i, d0 + 0.54, tx, -0.150, tx, -0.300);
        ring('sr' + i, d0 + 0.62, tx, -0.340, 0.020);
      }
    }
    return P;
  }

  /* brightness per tag: 0..1 lit, 2 = outside a rating (amber), -1 = dark */
  function final(s, tag) {
    return tag.map(function (t) {
      if (t === 'grid' || t === 'interface' || t === 'bus') return 0.95;
      if (t === 'tx' || t === 'board') return 0.90;
      if (t.indexOf('sk') === 0) return 0.85;
      if (t === 'inv') return s.over_mppt ? 2 : 1;          /* the machine's own input */