In this section
- Kuiper Programs render · globalgrid2050 / kuiper-grid/i0083/cartridges/008300000000-kuiper-programs.js lines 2530–3229
Kuiper Programs
A JavaScript module in the cartridges folder of GlobalGrid2050 covering cables, solar, substations and transformers, using IEC 62446-1 and SHA-256, and uses data from the faraday repository.
Set aside from the main view: 91% of its lines are the same as kuiper-grid/i0090/cartridges/009000000000-kuiper-programs.js (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 91% of lines shared with Kuiper Programs; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9107 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0090/cartridges/009000000000-kuiper-programs.js:1-4074 900ccf797d8055b28d45153c3fa3dbb44ccb03a5
- sha256 ae019b9cb0babff1ee7df643eee33d4cfb3ff5151ff598ee0db9d2925ef5271c
- target sha256 3b3ff8b2b317c0c59e1431b1d9e003c246ec9bb5227219e64e47d313656e2062
- group of 6 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
- re-pointed by apply.py version rule from file 3680 to file 3682; similarity was measured to file 3680
renderglobalgrid2050 / kuiper-grid/i0083/cartridges/008300000000-kuiper-programs.js · lines 2530–3229 of 3710 (continued from section 1368) · Not reached from any entry point (candidate for review) · pattern stringClampMicro (shared by 18 files)
- What it does
- It draws cables, solar, substations and transformers. Defines 200 functions or classes, including reFire, closestPair, blackSky, nameInLines, makeBody. Side effects: changes the web page (DOM); reads or writes files; makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: cables, solar, substations, transformers, 400kV, 1500V.
- Inputs & outputs
- In: data source: faraday data; JSON file current.json. Out: canvas drawing. Voltage levels named: 400kV, 1500V.
- What it achieves
- It makes body (`makeBody`), sets tag (`setTag`) and merges menu (`mergeMenu`). A cartridge of the Kuiper shell. Its code works with 352 kVA, 295 kVA and 320 kVA. It responds to click, keydown and pointerdown events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · kuiper-grid/i0083/cartridges · JavaScript module
- Uses
- Faraday — Index Page (estate URL), Wafer Development Environment — Proof S0004 Page (estate URL), ./fire.js
- Used by
- none found
- Produces
- reFire, closestPair, blackSky, nameInLines, makeBody, bodyTo, labels, bodyJump, bodyMove, bodyDrawnDiameter, bodyDotPx, sheet
- Defines here
- nameLayer, amberName, pocWords, makeSldNames, at, addAmberName, placeSldNames, sldUniforms, sldTick, stringViewSpanM, sayRect, shapeBand, stringPlaceView, stringViewWord, stringOpenView, stringWholeView, stringNearView, stringClampMicro, sldStart, buildStringWalk, shapeLayer, shapeScale, shapePoint, shapesGone, polyLen, polyAt, polySlice, polyThin, bez, potColour
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0083/cartridges/008300000000-kuiper-programs.js:2530-3229 · blob f4e0f2b8e9134662b28d36964b137dbe8f8ed229 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
const k = far > 1e-9 ? 0.97 / far : 1;
for (let j = 0; j < m; j++) { lay.unit[2*j] = (lay.unit[2*j] - mx) * k; lay.unit[2*j+1] = (lay.unit[2*j+1] - my) * k; }
lay.spacing *= k; }
for (let q = 0; q < 2 * m; q++) to[q] = lay.unit[q] * R * frac;
const gap = closestPair(lay.unit) * R * frac;
sldNow = { net, lay, final:net.kind === 'string' ? stringFinal(net, lay.tag) : net.kind === 'network' ? netFinal(net, lay.tag) : sldFinal(net, lay.tag), t0:0, vals:new Float32Array(SLD_MAX) };
// THE SOLID DRAWING COMES FROM THE SAME DESCRIPTION THE DOTS CAME FROM, so the two can never disagree.
shapeLayer(); sldShapes = net.kind === 'string' ? (net.g.__draw || stringDrawing(net.g)) : null;
if (sldShapes) { sldShapes.front = -1; sldShapes.head = -1; sldShapes.walk = null; sldShapes.t0 = 0; shapeHover = null; }
nameLayer();
sldNames = makeSldNames(lay, net);
if (net.kind !== 'string') { const amber = addAmberName(lay, sldNow.final); if (amber) sldNames.push(amber); }
return { n:m, from, pos:new Float32Array(from), states:[{ shape:'sld', to, gap, frac, hold:0, unresolved:false }], k:-1, gap:0, shown:false, sld:true, fineDots:net.kind === 'string', sldGap:lay.spacing * R * frac };
}
// ===== THE FEWEST WORDS A DIAGRAM NEEDS ==========================================================
// A picture of nine substations with no word on it anywhere is a pattern, not a single line diagram, to
// anybody who is not an engineer. Three words are added, and no more: GRID where the grid is, what the
// connection point is doing (exports 50 kW, or imports 1,649 kW) where the connection point is, and the
// name of whatever ended AMBER, because amber is the only thing on the picture that is a warning and a
// colour nobody can look up. They are drawn as plain text over the canvas, no boxes and no lines, at the
// place the drawing itself puts them, and they appear only once the dots have landed.
let sldNames = null;
function nameLayer(){
let el = document.getElementById('sldnames');
if (!el) { el = document.createElement('div'); el.id = 'sldnames';
const st = document.createElement('style');
st.textContent = '#sldnames{position:fixed;inset:0;z-index:4;pointer-events:none}'
+ '#sldnames span{position:absolute;transform:translate(-50%,-50%);color:#cfeaf2;font-size:10.5px;letter-spacing:.06em;'
+ 'white-space:nowrap;text-shadow:0 0 6px #000,0 0 3px #000}'
+ '#sldnames span.warn{color:#ffb454}'
+ '#sldnames span.note{color:#7f8899;font-size:10px;letter-spacing:.04em}'
+ '#sldnames span.danger{color:#ff5a4f;font-size:10.5px;font-weight:600;letter-spacing:.05em}'
// A PINNED LINE MAY WRAP. It is a sentence, not a name, and on a telephone it is longer than the
// screen; a key that runs off the edge is a key nobody reads.
+ '#sldnames span.pinned{white-space:normal;text-align:center;transform:translate(-50%,-100%);line-height:1.35}'
+ '#sldnames span.said{color:#eaf6ff;font-size:11.5px;background:#0b0f16e8;border:1px solid #2a3444;'
+ 'border-radius:4px;padding:3px 8px;letter-spacing:.03em}'
+ '@media (max-width:700px){#sldnames span{font-size:9.5px}#sldnames span.note{font-size:9px}}';
document.head.append(st); document.body.append(el); }
return el;
}
const AMBER_WORDS = { bus:'volts outside the band', poc:'over the export limit', grid:'', board:'' };
function amberName(tag){
if (!tag) return '';
if (AMBER_WORDS[tag] !== undefined) return AMBER_WORDS[tag];
// A SERIES STRING WITH ONE LINK THAT DOES NOT MEET IS NOT "AMBER THERE". It carries no current at all.
if (tag.startsWith('short')) return 'open here, and live: no current, full open circuit voltage across the break';
if (tag.startsWith('tx')) return 'transformer over its rating';
if (tag.startsWith('load')) return 'volts outside the band at the load';
if (tag.startsWith('hv')) return 'volts outside the band on this cable';
if (tag.startsWith('f')) return 'transformer over its rating';
return '';
}
// WHAT THE CONNECTION POINT IS DOING, in the words the bench itself uses: minus is out to the grid.
function pocWords(net){
let kw = null;
if (net.kind === 'network' && net.solved) kw = net.solved.p;
else if (net.r && net.r.p_poc_kw !== undefined) kw = net.r.p_poc_kw;
if (kw === null || kw === undefined || !isFinite(kw)) return '';
const n = Math.abs(Math.round(kw));
return (kw < 0 ? 'exports ' : 'imports ') + (typeof fmt === 'function' ? fmt(n) : String(n)) + ' kW';
}
// the places, in the drawing's own units AFTER it has been fitted to the disc, so they follow the dots
function makeSldNames(lay, net){
const want = [], first = tag => { for (let j = 0; j < lay.tag.length; j++) if (lay.tag[j] === tag) return j; return -1; };
const at = j => ({ x:lay.unit[2*j], y:lay.unit[2*j+1] });
// A WIRING DRAWING CARRIES ITS OWN WORDS, and they were written when it was described: the inverter,
// the two free ends, what a sequential string lays extra, and the one note about red and black. Red
// and black here are how the drawing is READ; in the field both conductors are black cable and only
// the polarity marking tells them apart.
if (net.kind === 'string') { const d = net.g.__draw || stringDrawing(net.g);
const out = d.words.map(w => ({ x:w.x, y:w.y, dy:0, dx:0, text:w.text, small:w.small, warn:!!w.warnLine, note:!!w.note, danger:!!w.danger,
wide:!!w.wide, narrow:!!w.narrow, off:!!w.off, pinned:w.pinned }));
// A SERIES STRING WITH ONE LINK THAT DOES NOT MEET IS DEAD ALL THE WAY ROUND, and that is said once,
// under the drawing, not thirty times along it.
return out; }
const g = first('grid'); if (g >= 0) want.push(Object.assign(at(g), { text:'GRID', dy:-0.10, warn:false }));
const pc = first('poc'), words = pocWords(net);
if (pc >= 0 && words) want.push(Object.assign(at(pc), { text:words, dy:0, dx:0.22, warn:false }));
return want;
}
function addAmberName(lay, final){
const seen = new Set();
for (let j = 0; j < final.length; j++) {
if (final[j] !== 2) continue;
const words = amberName(lay.tag[j]);
if (!words || seen.has(words)) continue;
seen.add(words);
return { x:lay.unit[2*j], y:lay.unit[2*j+1], text:words, dy:-0.06, warn:true };
}
return null;
}
// THE WORDS FOLLOW THE PICTURE. They are put where they belong every time the camera moves, and nowhere
// else: no animation loop of their own is started, because a loop that runs for ever to move three words
// is a loop that runs for ever.
function placeSldNames(){
const el = document.getElementById('sldnames');
if (!el) return;
if (!sldNames || !body || !body.sld || !body.shown || bodyAnim || !sldNow) { el.replaceChildren(); return; }
const R = Math.sqrt(SPACE), frac = BODY_RADIUS_MAX;
// WHAT A TAP OR A HOVER HAS FOUND is one more word, and it comes and goes, so the list is rebuilt
// whenever its length changes and no sooner.
const said = sldShapes && shapeHover ? sldShapes.saying : null;
const list = said ? sldNames.concat([{ x:0, y:0, text:said, hover:true }]) : sldNames;
const small = innerWidth < 760;
// A LINE THAT BELONGS TO ONE SIZE OF SCREEN IS NOT BUILT FOR THE OTHER.
if (sldNames.some(n => n.wide || n.narrow || n.off)) sldNames = sldNames.filter(n => !n.off && (small ? !n.wide : !n.narrow));
if (el.childElementCount !== list.length || el.dataset.said !== String(said) || el.dataset.small !== String(small)) {
el.dataset.said = String(said); el.dataset.small = String(small);
el.replaceChildren(...list.map(n => { const sp = document.createElement('span');
sp.textContent = (small && n.small) ? n.small : n.text;
if (n.danger) sp.className = 'danger'; else if (n.warn) sp.className = 'warn'; else if (n.note) sp.className = 'note';
else if (n.hover) sp.className = 'said';
if (n.pinned !== undefined) sp.className += ' pinned'; return sp; }));
}
const pinBand = (sldShapes && sldShapes.kind === 'string') ? shapeBand() : null;
list.forEach((n, i) => { const sp = el.children[i]; if (!sp) return;
if (n.hover) { sp.style.left = Math.round(innerWidth / 2) + 'px';
sp.style.top = Math.round(Math.min(innerHeight - 120, innerHeight * 0.80)) + 'px'; return; }
// A PINNED LINE SITS AT THE FOOT OF THE BAND. Where exactly is settled in one pass afterwards,
// because these lines WRAP and a stack of guessed heights is a stack of sentences on top of
// each other, which is what a first attempt at this looked like.
if (n.pinned !== undefined && pinBand) { sp.style.visibility = '';
sp.style.left = Math.round((pinBand.left + pinBand.right) / 2) + 'px';
sp.style.maxWidth = Math.round(Math.min(900, pinBand.right - pinBand.left - 8)) + 'px';
return; }
const wx = (n.x + (n.dx || 0)) * R * frac, wy = (n.y + (n.dy || 0)) * R * frac;
const px0 = Math.round((wx - cx) * zoom + innerWidth / 2), py0 = Math.round(innerHeight / 2 - (wy - cy) * zoom);
// A WORD OFF THE SCREEN IS NOT LAID OUT. Thirty modules is several screens wide and the browser
// should not be asked to place what nobody can see; and text is put on whole pixels so it is crisp.
const bd = (sldShapes && sldShapes.kind === 'string') ? shapeBand(true) : { left:-260, right:innerWidth + 260, top:-60, bottom:innerHeight + 60 };
if (px0 < bd.left - 6 || px0 > bd.right + 6 || py0 < bd.top - 4 || py0 > bd.bottom + 4) { sp.style.visibility = 'hidden'; return; }
sp.style.visibility = ''; sp.style.left = px0 + 'px'; sp.style.top = py0 + 'px';
// A WORD IS NOT ALLOWED UNDER THE WINDOW EITHER, wherever the reader has put it.
const w2 = sayRect();
if (w2) { const b2 = sp.getBoundingClientRect();
if (b2.width > 0 && b2.right > w2.left && b2.left < w2.right && b2.bottom > w2.top && b2.top < w2.bottom) sp.style.visibility = 'hidden'; } });
// THE PINNED LINES ARE STACKED FROM THE BOTTOM UP, each one measured after it has wrapped.
if (pinBand) { const pins = [];
list.forEach((n, i) => { if (n.pinned !== undefined && el.children[i]) pins.push([n.pinned, el.children[i]]); });
pins.sort((a, b) => a[0] - b[0]);
let y = pinBand.bottom - 4;
for (const [, sp] of pins) { sp.style.top = Math.round(y) + 'px'; y -= (sp.offsetHeight || 14) + 2; }
pinHeight = Math.max(0, pinBand.bottom - 4 - y); }
}
addEventListener('wheel', placeSldNames, { passive:true });
addEventListener('pointermove', placeSldNames);
addEventListener('pointerup', placeSldNames);
addEventListener('resize', placeSldNames);
addEventListener('orientationchange', placeSldNames);
function sldUniforms(){
if (!BP) return; gl.useProgram(BP);
const on = !!(body && body.sld && sldNow);
gl.uniform1f(gl.getUniformLocation(BP, 'u_sld'), on ? 1 : 0);
if (on) gl.uniform4fv(gl.getUniformLocation(BP, 'u_val[0]'), sldNow.vals);
}
function sldTick(now){
sldLoop = 0; if (!(body && body.sld && sldNow)) return;
const S = sldNow, m = body.n, arrived = !bodyAnim && body.shown;
if (arrived && !S.t0) S.t0 = now;
const t = S.t0 ? (now - S.t0) / 1000 : -1;
// A WIRING DRAWING HAS ITS OWN TIMING: the dots settle, and then, ONLY IF THE LOOP IS CLOSED, one
// wavefront leaves the modules and runs out along both conductors to the inverter. Behind it the
// pencil line fuses solid and the dots under it MELT AWAY, because the line is the drawing now.
// An open string never starts: no current anywhere, so nothing to run.
if (S.net.kind === 'string' && sldShapes) {
const T2 = 1.3, live = !sldShapes.open;
// each dot goes out at its own moment, so the drawing is uncovered rather than switched off
if (!S.melt) { S.melt = new Float32Array(m); for (let j = 0; j < m; j++) S.melt[j] = 0.15 + 0.8 * ((j * 2654435761) % 1000) / 1000; }
const f = (t < 0 || !live) ? -1 : Math.min(1, t / T2);
sldShapes.front = f;
// THE NEON FRONT RUNS ON THIS SAME CLOCK. Not a second animation: the head is set here, beside the
// fuse front, and the shape pass draws it. One head, steady speed, running the ELECTRICAL WALK the
// model already names - inverter - round through every module to inverter +. An open string is
// given no head at all, because it carries nothing.
sldShapes.head = (live && t >= 0) ? ((t / 3.6) % 1) : -1;
for (let j = 0; j < m; j++) { const o = S.lay.dist[j], base = S.final[j];
if (t < 0) { S.vals[j] = 0.55; continue; }
if (f < 0) { S.vals[j] = base; continue; }
// AND THEN THEY ARE GONE. The dots are the way in - the work flies from the record and settles
// along the drawing - and once the line is there they melt away completely, because a drawing
// made of fine lines with dots scattered over it is two drawings. A value under -1.5 is thrown
// away by the shader, so nothing at all is left behind.
const gone = Math.min(1, Math.max(0, (t - 0.25) / 0.9));
const reach = Math.abs(o - 0.5) <= f * 0.5 + 1e-6;
const atFront = Math.abs(Math.abs(o - 0.5) - f * 0.5) < 0.035;
const still = atFront ? 1.25 : (reach ? 0.10 : base);
S.vals[j] = (gone >= 1 || (S.melt && S.melt[j] <= gone)) ? -2 : still; }
sldUniforms(); placeSldNames();
if (arrived && !S.placed) { S.placed = true; try { if (window.__placeSay) window.__placeSay(); } catch (_) {}
try { stringOpenView(); } catch (_) {} }
dirty = true;
if (live || t < Math.max(T2, 1.2) + 0.5) sldLoop = requestAnimationFrame(sldTick);
return;
}
const T = 1.5, D = S.lay.dMax, w = D * 0.06;
for (let j = 0; j < m; j++) { const d = S.lay.dist[j], f = S.final[j]; let v;
if (t < 0) v = 0.55; // in flight: every dot alike
else if (t < T) { const front = D * (1 - t / T); v = Math.abs(d - front) < w ? 1.25 : (d > front ? 0.5 : 0.22); } // PULSE ONE: back toward the grid
else if (t < 2 * T) { const front = D * (t / T - 1); v = Math.abs(d - front) < w ? 1.25 : (d < front ? f : 0.22); } // PULSE TWO: out from the grid, leaving the answer
else v = f;
S.vals[j] = v; }
sldUniforms(); placeSldNames();
if (arrived && !S.placed) { S.placed = true; try { if (window.__placeSay) window.__placeSay(); } catch (_) {} }
dirty = true;
if (t < 2 * T + 0.2) sldLoop = requestAnimationFrame(sldTick);
}
// WHERE THE VIEW OPENS. A thirty module row is several screens wide, so the reader is put at the NEAR
// END, with the inverter and the first few modules big enough to read on a phone, and drags along the
// row for the rest. The whole row is one press away.
function stringViewSpanM(){ return Math.max(9.5, Math.min(17, innerWidth / 40)); }
// THE BAND THE DRAWING LIVES IN. The answer window must never cover a shape or a word, so the free part
// of the screen is measured - what the foot takes, what the chips take, and where the window is docked -
// the row is laid out INTO that band, and the drawing layer is CLIPPED to it. A row several screens long
// would otherwise run on under the window, and a drawing nobody can read is not a drawing.
function sayRect(){ const el = document.getElementById('say');
if (!el || !el.classList.contains('open')) return null;
const r = el.getBoundingClientRect();
return (r.width > 8 && r.height > 8) ? r : null; }
let pinHeight = 0; // what the pinned key took last time it was laid out
function shapeBand(reserve){
let left = 14, right = innerWidth - 14, top = 14, bottom = innerHeight - 14;
const foot = document.getElementById('foot');
if (foot) { const r = foot.getBoundingClientRect(); if (r.height > 2) bottom = Math.min(bottom, r.top - 10); }
{ const r = sayRect();
if (r) { if (r.width > innerWidth * 0.7) top = Math.max(top, r.bottom + 10); // across the top: go under it
else if (r.left > innerWidth * 0.5) right = Math.min(right, r.left - 12); // docked to the right
else left = Math.max(left, r.right + 12); } }
const chips = document.getElementById('presets');
if (chips) { const c = chips.getBoundingClientRect(); if (c.height > 2 && c.left < right) top = Math.max(top, c.bottom + 10); }
if (right - left < 220) { left = 14; right = innerWidth - 14; }
if (bottom - top < 150) { top = 14; bottom = innerHeight - 14; }
// THE KEY IS NOT PART OF THE PICTURE AND THE PICTURE DOES NOT RUN UNDER IT. What the key took last
// time is kept out of the band the drawing is laid into and clipped to; the key itself is placed
// against the band that has NOT been shortened, or it would walk up the screen a line a frame.
if (reserve && pinHeight > 0) bottom = Math.max(top + 120, bottom - pinHeight - 6);
return { left, right, top, bottom };
}
function stringPlaceView(spanM, whole){
const D = sldShapes; if (!D || typeof flyTo !== 'function') return;
const R = Math.sqrt(SPACE), f = BODY_RADIUS_MAX, b = shapeBand(true);
if (whole) { const bb = D.bounds, w = Math.max(1e-6, bb.x1 - bb.x0), h = Math.max(1e-6, bb.y1 - bb.y0);
const z = Math.max(1e-9, Math.min((b.right - b.left) * 0.98 / (w * R * f), (b.bottom - b.top) * 0.92 / (h * R * f)));
flyTo((bb.x0 + bb.x1) / 2 * R * f - ((b.left + b.right) / 2 - innerWidth / 2) / z,
(bb.y0 + bb.y1) / 2 * R * f + ((b.top + b.bottom) / 2 - innerHeight / 2) / z, z); return; }
// THE NEAR VIEW FILLS THE BAND, in both directions. It used to be set by width alone, so on a
// telephone a two tier table sat in a third of the screen with empty dark above and below it. The
// zoom is now whichever of the two fits - the whole drawing's height into the band's height, or
// three modules across its width - so the picture is as large as it can be and still legible, and it
// starts at M1 rather than at the inverter, because the modules are what is being read.
const hUnits = Math.max(1e-6, D.bounds.y1 - D.bounds.y0);
const zH = (b.bottom - b.top) * 0.97 / (hUnits * R * f);
// MICRO IS FOUR MODULES, and it is four on a telephone and four on a desk: the view is named by what
// it shows, not by how much of the screen happens to be free. M1 to M4 across the band, with a hair
// of margin so the fourth module is not cut by the edge.
const wantM = 4.06 * D.g.pitch;
const zW = (b.right - b.left) * 0.97 / (wantM * D.perM * R * f);
const z = Math.max(1e-9, Math.min(zH, zW));
const firstX = D.firstModuleX !== undefined ? D.firstModuleX : D.near.x;
flyTo(firstX * R * f - (b.left + 6 - innerWidth / 2) / z,
(D.bounds.y0 + D.bounds.y1) / 2 * R * f + ((b.top + b.bottom) / 2 - innerHeight / 2) / z, z);
}
// WHICH VIEW THE DRAWING OPENS IN IS THE DECLARED INPUT, and nothing else decides it: `view` says macro
// or micro, its default is micro on a telephone and macro on a desk, and the two typed words set it.
function stringViewWord(D){ const c = D && D.g && D.g.c; const v = String((c && c.view) || '').toLowerCase();
if (v === 'macro' || v === 'micro') return v;
return (innerWidth < 700) ? 'micro' : 'macro'; }
function stringOpenView(){ const D = sldShapes; if (!D || D.opened) return; D.opened = true;
stringPlaceView(stringViewSpanM(), stringViewWord(D) === 'macro'); }
function stringWholeView(){ stringPlaceView(0, true); } // MACRO: the whole string, fitted to the width
function stringNearView(){ const D = sldShapes; if (!D) return; stringPlaceView(stringViewSpanM(), false); }
// THE MICRO END HAS A FLOOR UNDER IT. Going in is going in until the module you are reading fills the
// band - and then it stops. Past that point the wheel only cuts the thing you came to look at: the top
// of the module goes off the top of the band, the bottom off the bottom, and the reader is left with a
// slab of glass and no edges to hold on to. So the camera is CLAMPED. One module, whole, inside the
// band, is the closest the drawing will go; and when the clamp bites the module under the middle of
// the screen is also brought to the middle of the band, so what stops is centred and not half gone.
function stringClampMicro(){
const D = sldShapes; if (!D || !D.shapes || typeof flyTo !== 'function' || typeof zoom !== 'number') return;
const R = Math.sqrt(SPACE), f = BODY_RADIUS_MAX, b = shapeBand(true);
let hU = 0, wU = 0;
for (const s of D.shapes) { if (s.role !== 'module' || !s.pts || s.pts.length < 2) continue;
let y0 = 1e9, y1 = -1e9, x0 = 1e9, x1 = -1e9;
for (const p of s.pts) { if (p[1] < y0) y0 = p[1]; if (p[1] > y1) y1 = p[1];
if (p[0] < x0) x0 = p[0]; if (p[0] > x1) x1 = p[0]; }
hU = Math.max(hU, y1 - y0); wU = Math.max(wU, x1 - x0); break; }
if (!(hU > 0) || !(wU > 0)) return;
const zMax = Math.min((b.bottom - b.top) * 0.90 / (hU * R * f), (b.right - b.left) * 0.90 / (wU * R * f));
if (!(zMax > 0)) return;
const zUse = Math.min(zoom, zMax);
// the module nearest the middle of the screen is the one the reader is on; centre it in the band
const midX = innerWidth / 2, midY = (b.top + b.bottom) / 2;
let best = null, bd = 1e18;
for (const s of D.shapes) { if (s.role !== 'module' || !s.pts || s.pts.length < 2) continue;
let y0 = 1e9, y1 = -1e9, x0 = 1e9, x1 = -1e9;
for (const p of s.pts) { const q = shapePoint(p);
if (q[1] < y0) y0 = q[1]; if (q[1] > y1) y1 = q[1]; if (q[0] < x0) x0 = q[0]; if (q[0] > x1) x1 = q[0]; }
const dx = (x0 + x1) / 2 - midX, dy = (y0 + y1) / 2 - midY, d2 = dx * dx + dy * dy;
if (d2 < bd) { bd = d2; best = s; } }
if (!best) return;
// ONLY WHEN IT IS ACTUALLY CUT. The clamp is not a rule about zoom, it is a rule about the module
// the reader is on: if that module already sits whole inside the band at the zoom in hand, nothing
// moves. It moves when the module is too big for the band, or when it fits and is simply hanging
// over an edge - and then the same move fixes both, because the module is put in the middle.
let sx0 = 1e9, sx1 = -1e9, sy0 = 1e9, sy1 = -1e9;
for (const p of best.pts) { const q = shapePoint(p);
if (q[0] < sx0) sx0 = q[0]; if (q[0] > sx1) sx1 = q[0]; if (q[1] < sy0) sy0 = q[1]; if (q[1] > sy1) sy1 = q[1]; }
const inside = sx0 >= b.left && sx1 <= b.right && sy0 >= b.top && sy1 <= b.bottom;
if (inside && zoom <= zMax * 1.02) return;
let ux0 = 1e9, ux1 = -1e9, uy0 = 1e9, uy1 = -1e9;
for (const p of best.pts) { if (p[0] < ux0) ux0 = p[0]; if (p[0] > ux1) ux1 = p[0];
if (p[1] < uy0) uy0 = p[1]; if (p[1] > uy1) uy1 = p[1]; }
const xc = (ux0 + ux1) / 2 * R * f, yc = (uy0 + uy1) / 2 * R * f;
flyTo(xc - (midX - innerWidth / 2) / zUse, yc + (midY - innerHeight / 2) / zUse, zUse);
}
function sldStart(){ if (!sldLoop) sldLoop = requestAnimationFrame(sldTick); }
// THE ELECTRICAL WALK, READ OFF THE DRAWING ITSELF. Nothing is measured or placed here: every
// conductor shape already says which terminal it leaves and which it joins, so the order is found by
// following those names from INV- to INV+, and each leg's share of the walk is the TRUE LENGTH of the
// polyline that was drawn for it. A module is a leg too - the walk goes in at its - box and out at its
// + box. Returns false, and no neon runs, if any link is open or the chain does not close.
function buildStringWalk(D){
const byFrom = new Map(), mods = new Map();
for (const s of D.shapes) {
if ((s.role === 'lead' || s.role === 'cable') && s.from && s.to && s.pts && s.pts.length > 1) {
if (s.open) return false; // a break: the string carries nothing
if (!byFrom.has(s.from)) byFrom.set(s.from, s); }
else if (s.role === 'module' && s.module !== undefined && s.pts && s.pts.length > 1) mods.set(+s.module, s); }
const legs = []; let at = 'INV-', guard = 0;
while (guard++ < 500 && at !== 'INV+') {
const s = byFrom.get(at);
if (s) { legs.push({ s, len:Math.max(1e-6, polyLen(s.pts).total) }); at = s.to; continue; }
const m = /^M(\d+)-$/.exec(at); if (!m) return false;
const box = mods.get(+m[1]);
const bb = box ? box.pts : null;
let len = 0.6;
if (bb) { let x0 = 1e9, x1 = -1e9, y0 = 1e9, y1 = -1e9;
for (const p of bb) { x0 = Math.min(x0, p[0]); x1 = Math.max(x1, p[0]); y0 = Math.min(y0, p[1]); y1 = Math.max(y1, p[1]); }
len = Math.max(1e-6, (x1 - x0) + (y1 - y0)) * 0.5; }
legs.push({ mod:box, len }); at = 'M' + m[1] + '+'; }
if (at !== 'INV+' || !legs.length) return false;
let total = 0; for (const L of legs) total += L.len;
let c = 0; for (const L of legs) { L.u0 = c / total; c += L.len; L.u1 = c / total; }
return { legs, total };
}
// ===== SOLID SHAPES: THE WAY THIS PAGE DRAWS A WIRING DIAGRAM ===================================
// WHY THERE ARE TWO WAYS OF DRAWING AND NOT ONE. Dots are right for the MACRO view: a population of
// work, a whole estate, a field of addresses. They are wrong for a drawing somebody has to READ. At
// module level a cable made of dots is a smear, and no reader can tell which box joins which. So a
// diagram is described ONCE, as SHAPES, and the shapes are drawn as fine vector lines on one layer
// that follows the camera exactly. Vectors stay sharp at any zoom and on any screen.
//
// A SHAPE IS DATA, NOT A DRAWING INSTRUCTION:
// { role, node, order, pot, volts, earth_v, pts, closed, fill, weight, dash, gap, says }
// role what it is: inverter, terminal, module, cells, box, lead, cable, loop, mark
// node the conductor or electrical node it belongs to, so a tap can light one whole link
// order its place along the electrical path, 0 at the - end of the string, 1 at the + end
// pot the potential at that point, 0 at the - end and 1 at the + end, one module's volts a module
// volts that potential in volts above the - end
// earth_v the same point's volts TO EARTH. A floating array on a transformerless inverter sits
// roughly symmetric about earth, so this is about minus half to plus half of the string
// voltage end to end. It is carried now, unused, because an earth fault study needs it: the
// FIRST fault pins one point to earth and re-references every other potential (the far end
// rises toward the whole string voltage: insulation stress, little current), and a SECOND
// fault closes a loop through earth that bypasses the modules between and drives their short
// circuit current round it. Nothing of that is computed here; the model is ready for it.
// The dot pieces are produced from the SAME list, so the dots and the drawing can never disagree.
//
// THREE STATES, AND THE PHYSICS DECIDES WHICH ONE IS SHOWN:
// DRAWN the pencil drawing, grey. What was designed, before any question of current.
// OPEN a series string with ONE link whose leads do not meet carries NO current ANYWHERE. Not
// "that link is amber": the whole string is dead. Every gap is drawn as the gap it is,
// with its shortfall in metres beside it, and nothing fuses.
// ENERGISED the loop is closed. A WAVEFRONT starts AT THE MODULES and runs out along both
// conductors TO THE INVERTER, which is the way the power goes, and behind the front the
// pencil line FUSES into a solid one. The front is fast because energy arrives as a field,
// at a large fraction of the speed of light; the electrons themselves drift about a fifth
// of a millimetre a second at 17 A in 6 mm2, which is why nothing crawls along a wire in
// this drawing. The fused line's WEIGHT is the current, the same all round a series string
// because charge is conserved at every node, and it would ADD where two strings meet. Its
// COLOUR is the POTENTIAL at that point: black at the - end, red at the + end, one
// module's voltage higher at each module, so only the two home runs are fully - and + .
// CLARITY OVER FANCY. The pencil drawing, the marked boxes, the module names and the followable cables
// are what the picture is for. The fusing, the potential colour and the loop shading are drawn UNDER
// them and never over a label or a box.
const SHAPE_PENCIL = '#94a2b5', SHAPE_FAINT = '#333c49', SHAPE_FILL = '#111823', SHAPE_INK = '#d5e4f0',
SHAPE_RED = '#ff4b3a', SHAPE_BLACK = '#080b11', SHAPE_EDGE = '#6d7d92', SHAPE_WARN = '#ffb454';
const CABLE_NOTE = 'black cables only with polarity marking in the field';
// THE LINE THAT HAS TO BE THERE EVERY TIME, in red, wherever an answer of this family is shown. It is
// not closable and it does not scroll away: this page is a place to think in, not a design.
const DEV_WARNING = 'Not real cable or array sizing - consult a design engineer. DEVELOPMENT ENVIRONMENT: estimates from a model, nothing measured.';
const DEV_WARNING_SHORT = 'Not real cable or array sizing - consult a design engineer.';
let sldShapes = null; // the prepared drawing now on the screen
let shapeHover = null; // the link the pointer is over, if any
// ---- the layer -------------------------------------------------------------------------------
function shapeLayer(){
let el = document.getElementById('sldshapes');
if (!el) { el = document.createElement('canvas'); el.id = 'sldshapes'; el.setAttribute('aria-hidden', 'true');
const st = document.createElement('style');
st.textContent = '#sldshapes{position:fixed;inset:0;z-index:2;pointer-events:none}';
document.head.append(st);
const c = document.getElementById('c');
if (c && c.parentNode) c.parentNode.insertBefore(el, c.nextSibling); else document.body.append(el); }
return el;
}
// the drawing's own units to the screen, by the same arithmetic the words overlay uses
function shapeScale(){ return Math.sqrt(SPACE) * BODY_RADIUS_MAX * zoom; }
function shapePoint(p){ const R = Math.sqrt(SPACE), f = BODY_RADIUS_MAX;
return [(p[0] * R * f - cx) * zoom + innerWidth / 2, innerHeight / 2 - (p[1] * R * f - cy) * zoom]; }
function shapesGone(){ sldShapes = null; shapeHover = null;
const el = document.getElementById('sldshapes'); if (!el) return;
const ctx = el.getContext && el.getContext('2d');
if (ctx) { ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.clearRect(0, 0, el.width, el.height); } }
// ---- polyline arithmetic ---------------------------------------------------------------------
function polyLen(pts){ let t = 0; const cum = [0];
for (let i = 1; i < pts.length; i++) { t += Math.hypot(pts[i][0] - pts[i-1][0], pts[i][1] - pts[i-1][1]); cum.push(t); }
return { total:t, cum }; }
function polyAt(pts, cum, total, u){ const want = Math.max(0, Math.min(1, u)) * total;
for (let i = 1; i < pts.length; i++) if (cum[i] >= want || i === pts.length - 1) {
const seg = (cum[i] - cum[i-1]) || 1, t = Math.min(1, Math.max(0, (want - cum[i-1]) / seg));
return [pts[i-1][0] + (pts[i][0] - pts[i-1][0]) * t, pts[i-1][1] + (pts[i][1] - pts[i-1][1]) * t, i]; }
return [pts[0][0], pts[0][1], 1]; }
function polySlice(pts, u0, u1){ const m = polyLen(pts); if (m.total < 1e-12 || u1 <= u0 + 1e-9) return [];
const a = polyAt(pts, m.cum, m.total, u0), b = polyAt(pts, m.cum, m.total, u1), out = [[a[0], a[1]]];
for (let i = a[2]; i < b[2]; i++) out.push(pts[i]);
out.push([b[0], b[1]]); return out; }
function polyThin(pts, n){ const m = polyLen(pts), out = []; // the same curve, fewer points
for (let i = 0; i <= n; i++) { const p = polyAt(pts, m.cum, m.total, i / n); out.push([p[0], p[1]]); }
return out; }
function bez(p0, c0, c1, p1, n){ const out = [];
for (let i = 0; i <= n; i++) { const t = i / n, u = 1 - t, a = u*u*u, b = 3*u*u*t, c = 3*u*t*t, d = t*t*t;
out.push([a*p0[0] + b*c0[0] + c*c1[0] + d*p1[0], a*p0[1] + b*c0[1] + c*c1[1] + d*p1[1]]); }
return out; }
// THE POTENTIAL AS A COLOUR: black at the - end of the string, red at the +. Nothing in between is
// either, which is the point: only the two home runs are at a whole polarity.
function potColour(t){ const u = Math.max(0, Math.min(1, t));
const r = Math.round(10 + 245 * Math.pow(u, 0.75)), g = Math.round(12 + 63 * u * u), b = Math.round(18 + 40 * u * u);
return 'rgb(' + r + ',' + g + ',' + b + ')'; }
function dimColour(css, k){ const m = /rgb\((\d+),(\d+),(\d+)\)/.exec(css);
return m ? 'rgb(' + Math.round(m[1] * k) + ',' + Math.round(m[2] * k) + ',' + Math.round(m[3] * k) + ')' : css; }
// ===== ONE STRING, DRAWN AS A WIRING DRAWING ===================================================
// The row as it really stands: every module a rectangle of its true proportions with its cells in
// hairlines, its two junction boxes where they truly are (a split box at mid height on the back,
// box_spacing_m apart, centred on the width), each box MARKED - or + in text and not by colour alone,
// its lead leaving it at the lead's own length and ending in a connector. Where two connectors do not
// meet, the gap between them is the shortfall, drawn as a gap and given in metres.
function stringDrawing(g){
const c = g.c, N = g.N, pitch = g.pitch;
const wX = g.wX, wY = g.wY, port = g.port, rows = g.rows, cols = g.cols, tableTop = g.rowY[rows - 1] + wY;
const cellCols = Math.max(1, Math.round(c.cell_cols === undefined ? 6 : c.cell_cols));
const cellRows = Math.max(2, Math.round(c.cell_rows === undefined ? 22 : c.cell_rows));
// TWO VIEWS OF THE SAME STRING, and the WIRING one is what anybody actually asks a drawing for.
// Looking at the BACK of the modules: plain backs, no cell grid, the junction boxes drawn several
// times their real size because what is being read is WHICH BOX JOINS WHICH, and a true-to-scale box
// at row zoom is three pixels of nothing. Every cable is a line you can follow with a finger from one
// box terminal to the next. The other view keeps the module to scale with its cells, for when the
// question is how big the thing is rather than how it is wired.
const viewWord = String(c.view === undefined || c.view === null || c.view === '' ? 'macro' : c.view).toLowerCase();
const wiring = viewWord !== 'scale';
// PLAIN SMALL BOXES, the same in both views. Drawn several times life size the boxes became a strip
// of black rectangles across the module and the drawing stopped looking like a drawing.
const boxW = port ? 0.24 : 0.16, boxH = port ? 0.16 : 0.24;
const boxY = g.rowY[0] + wY / 2;
// EVERY TERMINAL IS DECLARED, by name, once. A cable may begin and end nowhere else, and that is
// checked rather than trusted: this list is what the checks walk.
const terminals = [];
const term = (id, x, y, kind, module) => { terminals.push({ id, x, y, kind, module }); return [x, y]; };
const vmp = c.module_vmp === undefined ? 38.1 : +c.module_vmp, vString = N * vmp;
const vOpen = N * (c.module_voc === undefined ? 45.9 : +c.module_voc);
const shapes = [], marks = [], words = [], conns = [];
const chain = 2 * N; // home-, module, link, module ... home+
let put = o => { shapes.push(o); return o; };
const put0 = put;
put = o => { if (o.pot === undefined) o.pot = 0; o.volts = o.pot * vString; o.earth_v = (o.pot - 0.5) * vString;
if (o.node === undefined) o.node = null; return put0(o); };
const poly = (role, o, pts, extra) => put(Object.assign({ role, order:o, pot:0, pts, weight:1 }, extra || {}));
const box = (role, o, x0, y0, x1, y1, extra) => poly(role, o, [[x0,y0],[x1,y0],[x1,y1],[x0,y1],[x0,y0]], extra);
// ---- the inverter: a filled block with a - terminal and a + terminal, both marked
const invW = 3.0, standOff = 2.2;
const invX1 = -standOff, invX0 = invX1 - invW, invY0 = boxY - 1.14, invY1 = boxY + 1.14;
const negY = invY1 - (invY1 - invY0) * 0.26, posY = invY0 + (invY1 - invY0) * 0.26;
box('inverter', 0, invX0, invY0, invX1, invY1, { fill:SHAPE_FILL, node:'inv' });
for (const [y, sign] of [[negY, '−'], [posY, '+']]) {
poly('terminal', 0, [[invX1, y], [invX1 + 0.16, y]], { node:'inv' });
term(sign === '+' ? 'INV+' : 'INV-', invX1 + 0.16, y, sign === '+' ? 'inv+' : 'inv-', 0);
put({ role:'terminal', order:0, pot:sign === '+' ? 1 : 0, node:'inv', pts:[[invX1 + 0.16, y]], dot:0.10 });
marks.push({ x:invX1 - 0.30, y, text:sign, size:12, colour:sign === '+' ? SHAPE_RED : SHAPE_EDGE, minPx:14 }); }
// ---- the modules, to true proportion, with their cells and their two boxes
const turned = k => g.turned(k);
for (let k = 1; k <= N; k++) {
const x0 = g.x0(k), x1 = x0 + wX, yb = g.y0(k), yt = yb + wY;
const o = (2 * g.order.indexOf(k) + 1) / chain, pot = (g.order.indexOf(k) + 1) / N;
box('module', o, x0, yb, x1, yt, { fill:'#0c1119', node:'M' + k, weight:1 });
// THE CELLS. This module class is cols x rows half cells with the break across the middle where the
// two halves meet. They are hairlines and they are dropped entirely when they would turn to mush.
// THE CELLS FOLLOW THE MODULE ROUND. A module laid on its side has its columns of cells across the
// table and its rows up it: the count belongs to the module, not to the table.
// EVERY CELL IS A THING, not a stripe of a pattern. The grid is carried as DATA - how many across
// and up, the gap between cells, the wider gap where the two halves of the module meet, and for
// every cell which cell string it is in and which bypass diode guards it - because what comes next
// is lighting, shading and faulting cells one at a time. The lines drawn from it are quiet: they sit
// UNDER the cables, and they are only drawn when a cell is wide enough on the screen to be a cell.
const cA = port ? cellCols : cellRows, cB = port ? cellRows : cellCols;
const gapC = 0.002, midG = 0.012; // between cells, and across the middle of the module
const cw = (wX - gapC * (cA - 1)) / cA, ch = (wY - gapC * (cB - 1) - midG) / cB;
const cellX = i2 => x0 + i2 * (cw + gapC);
const cellY = j2 => yb + j2 * (ch + gapC) + (j2 >= cB / 2 ? midG : 0);
put({ role:'cells', order:o, pot, node:'M' + k, module:k, pts:[[x0, yb], [x1, yt]],
grid:{ across:cA, up:cB, cell_w:cw, cell_h:ch, gap:gapC, mid_gap:midG, x0, y0:yb,
cell_strings:3, diodes:3, per_string:Math.round(cA * cB / 3) } });
// THREE SPLIT BOXES ON THE MID LINE, which is what a modern module really has: the two outer ones
// carry the leads, one - and one +, and the middle one carries a bypass diode and nothing else.
// Each lead leaves its box SIDEWAYS along that line and ends in a connector you can see.
// ONE BOX OR THREE, as the module class declares. With one box the minus and plus points are the
// same point (rule 2 holds |fP0 - fM0| <= 1e-6), so drawing three would stack them: draw the one
// box, and put the two signs inside it, one either side of its centre, since both leads leave it.
const oneBox = Math.round(+c.n_boxes) === 1;
const midPt = [(g.minusPt(k)[0] + g.plusPt(k)[0]) / 2, (g.minusPt(k)[1] + g.plusPt(k)[1]) / 2];
box('box', o, midPt[0] - boxW / 2, midPt[1] - boxH / 2, midPt[0] + boxW / 2, midPt[1] + boxH / 2,
{ fill:'#060a10', node:'M' + k, weight:1, big:wiring, diodeOnly:!oneBox, diode:oneBox });
for (const [pt, sign] of [[g.minusPt(k), '−'], [g.plusPt(k), '+']]) {
if (!oneBox) box('box', o, pt[0] - boxW / 2, pt[1] - boxH / 2, pt[0] + boxW / 2, pt[1] + boxH / 2,
{ fill:'#060a10', node:'M' + k, weight:1, big:wiring, diode:true });
term('M' + k + (sign === '+' ? '+' : '-'), pt[0], pt[1], sign === '+' ? 'module+' : 'module-', k);
const away = sign === '+' ? 1 : -1;
marks.push(oneBox
? { x:pt[0] + (port ? away * boxW * 0.26 : 0), y:pt[1] + (port ? 0 : away * boxH * 0.26),
text:sign, size:11, colour:sign === '+' ? SHAPE_RED : SHAPE_INK, minPx:22, mid:true, rank:0 }
: { x:pt[0] + (port ? 0 : boxW * 0.5 + 0.17), y:pt[1] - (port ? boxH / 2 + 0.17 : 0),
text:sign, size:11, colour:sign === '+' ? SHAPE_RED : SHAPE_INK, minPx:22, mid:port, rank:0 }); }
marks.push({ x:(x0 + x1) / 2, y:yb - 0.34, text:'M' + k, size:11, colour:SHAPE_INK, minPx:18, mid:true, rank:0, dodge:true });
if (turned(k)) marks.push({ x:(x0 + x1) / 2, y:yb - 0.62, text:'rear', size:9, colour:SHAPE_EDGE, minPx:60, mid:true, dodge:true, rank:3 });
// THE MACRO WORDS. Zoomed out to the whole string every name is a grey tick and thirty of them are a
// smear, so at that distance FIVE words are written and no others: M1, M10, M20, M30 and the
// inverter. They are the same names, written larger and never shrunk - a word too small to read is
// dropped, not drawn faint - and they are a separate mark so that the near names can carry on being
// dropped by their own rule. 9 px is the floor for any word on this drawing.
if (k === 1 || k % 10 === 0)
marks.push({ x:(x0 + x1) / 2, y:yb - 0.34, text:'M' + k, size:11, colour:SHAPE_INK, minPx:0, mid:true, macro:true, rank:0 });
}
marks.push({ x:(invX0 + invX1) / 2, y:invY0 - 0.60, text:'inverter', size:11, colour:SHAPE_EDGE, minPx:0, mid:true, macro:true, rank:0 });
// WHAT HOLDS THE TABLE UP, where it changes the geometry: the ridge of an east west table and the
// torque tube of a tracker are each drawn as the one fine line they are.
for (let r = 0; r + 1 < rows; r++) { const gapTop = g.rowY[r + 1], gapBot = g.rowY[r] + wY;
if (gapTop - gapBot > c.gap_up_m + 1e-6) poly('tube', 0, [[-0.4, (gapTop + gapBot) / 2], [g.row + 0.2, (gapTop + gapBot) / 2]], { node:'tube' }); }
// ---- the links: a curve from the + box of one module to the - box of the next, made of two leads
let laneHi = tableTop, laneLo = g.rowY[0];
// A LEAD IS NOT AN ARCH. It leaves its own box, runs behind the modules and plugs into the box it
// mates with, and the line drawn here is THAT ROUTE, AT ITS TRUE LENGTH: 0.84 m of lead is 0.84 m of
// line at this drawing's scale. The tall arches this picture used to have were readable, and they
// were three times as long as the cable they stood for, which is not a drawing of anything. What
// tells two links apart now is a small lane offset - out of the row one way and back the other - the
// tick where the two leads mate, and the numbers written on the link itself.
// A LINK IS FOUR THINGS YOU CAN SEE: a lead out of one box, a PLUG, a SOCKET it clicks into, and a
// lead into the next box. The two leads leave their boxes sideways along the mid line of the module,
// the way they really do, and the cable between them is a smooth curve with sag - arching ABOVE the
// mid line on the way out and sweeping BELOW it on the way back - so that two cables crossing can
// still be told apart. Colour stays with POLARITY, not with direction: red is the + lead and black
// the -, whichever way round the curve goes.
// A STRAIGHT RUN OUT OF THE BOX FIRST. Curving away the instant it leaves made the whole row read as
// one wave passing through the modules; a short straight stub, clear of the box outline and along the
// mid line, is what makes the eye see a cable LEAVING THAT BOX. Where two boxes sit side by side at a
// module boundary, the stubs are what say which tube belongs to which.
// THE ONE THING THAT WAS WRONG: a cable that begins in the air. Each one now starts on the EDGE of
// its own box, on the side facing where it is going, with a small dot to mark the landing, runs a
// short straight way clear of the box, and then curves to the edge of the box it joins.
const stub = Math.max(0.13, wX * 0.22), lip = boxW * 0.60;
const faceX = (bx, towards) => bx + (towards >= bx ? 1 : -1) * boxW / 2;
const faceY = (by, towards) => by + (towards >= by ? 1 : -1) * boxH / 2;
// EVERY CONDUCTOR RUNS BETWEEN THE TWO TERMINALS THE MODEL SAYS IT JOINS, and nowhere else. The link
// list is the netlist: out along the odd modules, M1+ to M3-, M3+ to M5-, and back through the even
// ones. Nothing is drawn from a module to itself, nothing leaves the middle box - the middle box has
// no lead, it holds a diode - and nothing is invented to make the picture tidy.
//
// AND EVERY LEAD IS ITS TRUE LENGTH. The drawing is to scale, so a lead of 0.30 m is 0.30 m of line.
// Two leads that reach are drawn as one curve whose ARC LENGTH is the two lead lengths added: the
// spare cable shows as the gentle bow it really makes, not as a decorative arch. Two leads that do
// NOT reach are drawn straight out from their own boxes, each to its own length, each ending in its
// connector, with nothing at all between them. The gap IS the message: no dashes, no dots, no amber
// line pretending a cable is there.
g.links.forEach((l, i) => {
const Ac = g.plusPt(l.from), Bc = g.minusPt(l.to);
const A = port ? [faceX(Ac[0], Bc[0]), Ac[1]] : [Ac[0], faceY(Ac[1], Bc[1])];
const B = port ? [faceX(Bc[0], Ac[0]), Bc[1]] : [Bc[0], faceY(Bc[1], Ac[1])];
const dx = B[0] - A[0], dy = B[1] - A[1], L = Math.max(1e-6, Math.hypot(dx, dy));
// OUT ABOVE, RETURN BELOW. A link on the way out bows ABOVE the box line and a link on the way
// back bows BELOW it, so two cables sharing a module are told apart by which side they sit on and
// not by a guess. The perpendicular is taken to the run and then its sign is settled by direction.
const ux = dx / L, uy = dy / L;
let nx = -uy, ny = ux;
const want = l.back ? -1 : 1;
if (Math.abs(ny) < 1e-6) { if (nx * want < 0) { nx = -nx; ny = -ny; } }
else if (ny * want < 0) { nx = -nx; ny = -ny; }
const o = (2 * i + 2) / chain, pot = (i + 1) / N;
const lp = c.lead_plus_m, lm = c.lead_minus_m, pair = lp + lm;
const fromId = 'M' + l.from + '+', toId = 'M' + l.to + '-';
const node = 'L' + i;
const says = fromId + ' to ' + toId + ', needs ' + l.need.toFixed(2) + ' m, leads ' + pair.toFixed(2) + ' m'
+ (l.reaches ? '' : ', short by ' + (l.need - pair).toFixed(2) + ' m');
conns.push({ node, from:fromId, to:toId, needed:l.need, pair, reaches:l.reaches, jumper:l.jumper || 0 });
if (pair >= L) {
// A CURVE WHOSE ARC LENGTH IS THE CABLE THERE REALLY IS. For a shallow parabola of sag h over a
// span L the arc is about L(1 + 8h^2/3L^2), so the sag that spends exactly the spare cable is
// h = L * sqrt(3(pair/L - 1) / 8). With no spare it is a straight line, which is the truth.
const h = L * Math.sqrt(Math.max(0, 3 * (pair / L - 1) / 8));
// NO ARC LEAVES ITS OWN MODULE. A bow that climbs off the module back is a drawing of a cable
// hanging in the sky. The boxes sit on the mid line, so the room there is half a module either
// way, less a margin for the edge; a cubic with both handles at 2h peaks at 1.5h, so the bow is
// clamped to that room. The cable that the clamp does not spend is not lost: it shows as the
// SMALL LOOP a jointer leaves at the connector, which is where the spare really sits.
const roomY = Math.max(0.02, wY / 2 - 0.06);
const hMax = (Math.abs(ny) < 1e-6) ? h : roomY / 1.5 / Math.max(1e-6, Math.abs(ny));
const hUse = Math.min(h, hMax), spare = Math.max(0, h - hUse);
const cp = [(A[0] + B[0]) / 2 + nx * hUse * 2, (A[1] + B[1]) / 2 + ny * hUse * 2];
const pts = bez(A, cp, cp, B, 24);
for (const q of pts) { laneHi = Math.max(laneHi, q[1]); laneLo = Math.min(laneLo, q[1]); }
const t = Math.min(0.92, Math.max(0.08, lp / pair)), m2 = polyLen(pts);
poly('lead', o, polySlice(pts, 0, t), { node, pot, plus:true, link:l, says, hit:true, from:fromId, to:'mate' + i, metres:lp });
poly('lead', o, polySlice(pts, t, 1), { node, pot, plus:false, link:l, says, hit:true, from:'mate' + i, to:toId, metres:lm });
const j = polyAt(pts, m2.cum, m2.total, t), tan = polyAt(pts, m2.cum, m2.total, Math.min(1, t + 0.02));
put({ role:'mate', order:o, pot, node, pts:[[j[0], j[1]]], link:l, says, mated:true,
along:[tan[0] - j[0], tan[1] - j[1]] });
} else {
// NEITHER LEAD REACHES. Each is drawn straight out from its own box, at its own length, and stops.
const Pa = [A[0] + ux * lp, A[1] + uy * lp], Pb = [B[0] - ux * lm, B[1] - uy * lm];
poly('lead', o, [A, Pa], { node, pot, plus:true, link:l, says, hit:true, open:true, from:fromId, to:'open' + i, metres:lp });
poly('lead', o, [Pb, B], { node, pot, plus:false, link:l, says, hit:true, open:true, from:'open' + i, to:toId, metres:lm });
put({ role:'plug', order:o, pot, node, pts:[[Pa[0], Pa[1]]], male:true, along:[ux, uy] });
put({ role:'plug', order:o, pot, node, pts:[[Pb[0], Pb[1]]], male:false, along:[ux, uy] });
laneHi = Math.max(laneHi, A[1], B[1]); laneLo = Math.min(laneLo, A[1], B[1]);
}
});
// ---- the two home runs, above everything and below everything, so they never cross a module
const first = g.order[0], last = g.order[g.order.length - 1];
laneHi = Math.max(laneHi, tableTop); laneLo = Math.min(laneLo, g.rowY[0]);
const topLane = laneHi + 0.70, botLane = laneLo - 0.70;
const nP = g.minusPt(first), pP = g.plusPt(last), xn = nP[0], xp = pP[0];
// ROUNDED, like every other cable here: a square corner is a busbar, not a cable.
const round4 = (pp, r2) => { const out = [pp[0]];
for (let i2 = 1; i2 + 1 < pp.length; i2++) { const a2 = pp[i2 - 1], b2 = pp[i2], c2 = pp[i2 + 1];
const u1 = [a2[0] - b2[0], a2[1] - b2[1]], u2 = [c2[0] - b2[0], c2[1] - b2[1]];
const L1 = Math.max(1e-6, Math.hypot(u1[0], u1[1])), L2 = Math.max(1e-6, Math.hypot(u2[0], u2[1]));
const k1 = Math.min(r2, L1 * 0.45), k2 = Math.min(r2, L2 * 0.45);
const s1 = [b2[0] + u1[0] / L1 * k1, b2[1] + u1[1] / L1 * k1], s2 = [b2[0] + u2[0] / L2 * k2, b2[1] + u2[1] / L2 * k2];
out.push(s1); for (let q = 1; q < 6; q++) { const t2 = q / 6, w2 = (1 - t2) * (1 - t2), m2 = 2 * (1 - t2) * t2, e2 = t2 * t2;
out.push([w2 * s1[0] + m2 * b2[0] + e2 * s2[0], w2 * s1[1] + m2 * b2[1] + e2 * s2[1]]); }
out.push(s2); }
out.push(pp[pp.length - 1]); return out; };
const nEdge = port ? [xn, nP[1] + boxH / 2] : [xn - boxW / 2, nP[1]];
const pEdge = port ? [xp, pP[1] - boxH / 2] : [xp - boxW / 2, pP[1]];
const homeNeg = round4([[invX1 + 0.16, negY], [invX1 + 0.70, negY], [invX1 + 0.70, topLane], [xn, topLane], nEdge], 0.45);
conns.unshift({ node:'home-', from:'INV-', to:'M' + first + '-', needed:c.near_end_m, pair:null, reaches:true, home:true });
conns.push({ node:'home+', from:'M' + last + '+', to:'INV+', needed:c.near_end_m, pair:null, reaches:true, home:true });
poly('cable', 0, homeNeg, { node:'home-', pot:0, plus:false, weight:1.2, from:'INV-', to:'M' + first + '-', says:'the home run to the string’s − end' });
// DRAWN THE WAY THE CURRENT GOES, from the string's + terminal back to the inverter's, so that the
// line's first point IS the terminal it says it starts at. It ran the other way, and the check that
// asks "does every cable begin on the terminal it names" found it at once.
const homePos = round4([pEdge, [xp, botLane], [invX1 + 0.55, botLane], [invX1 + 0.55, posY], [invX1 + 0.16, posY]], 0.45);
poly('cable', 1, homePos, { node:'home+', pot:1, plus:true, weight:1.2, from:'M' + last + '+', to:'INV+',
says:g.bothNear ? 'the home run from the string’s + end' : 'the far end return: one more cable, ' + g.ret.toFixed(1) + ' m of it' });
// ---- the loop the string encloses: what a nearby stroke couples into
const loopPts = [[xn, nP[1]], [xp, pP[1]], [xp, botLane], [invX1 + 0.55, botLane], [invX1 + 0.70, topLane], [xn, topLane], [xn, nP[1]]];
put({ role:'loop', order:0, pot:0, pts:loopPts, closed:true });
// ---- the words the drawing needs, in the page's own overlay
words.push({ x:(invX0 + invX1) / 2, y:invY1 + 0.55, text:'INVERTER' });
words.push({ x:xn, y:topLane + 0.40, text:'inverter − to M' + first + '−' });
words.push({ x:xp, y:botLane - 0.30, text:'M' + last + '+ to inverter +' });
if (!g.bothNear) words.push({ x:g.row / 2, y:botLane - 0.62, text:'additional far end return, about ' + g.ret.toFixed(1) + ' m' });
// THE KEY IS PINNED TO THE SCREEN, NOT LAID OUT IN THE DRAWING. It was written into the picture under
// the row, which meant that the moment a reader zoomed in to read a module - the whole point of the
// near view - the key was a hundred metres below the bottom of the screen and nobody ever saw it. A
// key is not part of the thing it explains: it stays at the foot of the band, at every zoom, at every
// size, without scrolling and without opening anything. The warning sits above it, in the same place.
// EVERY LINE HAS A SHORT FORM. On a telephone the long forms wrapped into four paragraphs that took
// half the screen and sat on the drawing, which is worse than not showing them at all. Each line is
// written twice, and the narrow screen gets the short one, on one line.
if (g.short.length) words.push({ pinned:2, warnLine:true,
text:'the circuit is open and BOTH ENDS ARE LIVE: ' + g.short.length + ' links do not reach, so no current flows, but up to '
+ Math.round(vOpen) + ' V stands across a break and that is where an arc starts',
small:'OPEN and LIVE: ' + g.short.length + ' links short, up to ' + Math.round(vOpen) + ' V across a break' });
// THE NOTE ITSELF IS NEVER SHORTENED. Those are the owner's words and they are short enough already.
// ONE LINE OF ARITHMETIC UNDER THE PICTURE, so the whole answer is on the page without opening a thing.
words.push({ pinned:3, note:true, off:true,
text:(g.links.length - g.short.length) + ' of ' + g.links.length + ' links reach \u00b7 ' + g.lead_m.toFixed(1)
+ ' m of module lead \u00b7 ' + g.field_m.toFixed(1) + ' m of site cable \u00b7 ' + g.ohm.toFixed(3)
+ ' ohm with the leads at ' + c.t_lead_c + ' C and the cable at ' + c.t_site_c + ' C',
small:(g.links.length - g.short.length) + '/' + g.links.length + ' reach \u00b7 ' + g.lead_m.toFixed(0)
+ ' m lead \u00b7 ' + g.field_m.toFixed(0) + ' m cable \u00b7 ' + g.ohm.toFixed(3) + ' ohm' });
words.push({ pinned:4, danger:true, text:DEV_WARNING, small:DEV_WARNING_SHORT });