From b96d5681e2309d85d768af5f83c87508d181c168 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sun, 25 Oct 2026 16:00:14 +0100 Subject: [PATCH] Draw your own subsea cable beside its route (#64) It was drawn as a curve offset by how many links shared the city pair, so with eight waves on Dublin-London it swung far out to sea. It now follows the commercial cable on the route, eased sideways, or a gentle curve when there is none. --- CHANGELOG.md | 1 + site/index.html | 10 +++++++++- tests/issues.test.js | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d2867..1b57351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Your own subsea cable now runs beside the existing cable on its route instead of looping far out to sea (#64). Its shape no longer depends on how many waves already share the route. - Loans got stranger, and good ones got harder to get. Your credit rating now adds a risk premium to the interest rate, the big banks only lend to strong ratings, and a loan worth more than five months of revenue also takes 2–8% of your revenue until diff --git a/site/index.html b/site/index.html index a12e707..c93ed8b 100644 --- a/site/index.html +++ b/site/index.html @@ -3588,9 +3588,17 @@ function linkGroups(){const m=new Map();for(const l of S.links){const pr=l.ax.tier===t),tot=grp.reduce((a,x)=>a+LT[x.tier].g,0);return (same?`${grp.length}×${LT[t].n}`:`${grp.length} × ${fmtCap(tot)}`)+(up.lengthp.slice());const same=pairLinks(l.a,l.b).filter(x=>x.cable===l.cable).indexOf(l);if(same>0)for(let j=1;jx.kind==='df'&&x.own&&x.sub).indexOf(l),c0=cablesFor(l.a,l.b).slice().sort((x,y)=>x.km-y.km)[0],cp=c0&&cablePair(c0.cid,l.a,l.b); + if(cp)pts=besideLine(cp.pts,2+k*1.5); + else{const g=bezGeom(l,k);pts=[];for(let j=0;j<=20;j++)pts.push(qpt(g,j/20));}} if(!pts){const g=bezGeom(l);pts=[];for(let j=0;j<=20;j++)pts.push(qpt(g,j/20));} const cum=[0];let L=0;for(let j=1;jv/L),t),a=polyAt(sp,c.map(v=>v/L),Math.max(0,t-.02)),b=polyAt(sp,c.map(v=>v/L),Math.min(1,t+.02)),dx=b[0]-a[0],dy=b[1]-a[1],n=Math.hypot(dx,dy)||1,f=d*Math.sin(Math.PI*t);out.push([q[0]+dy/n*f,q[1]-dx/n*f]);}return out;} function polyAt(sp,cum,t){let i=1;while(it0?(t-t0)/(t1-t0):0;return [sp[i-1][0]+(sp[i][0]-sp[i-1][0])*f,sp[i-1][1]+(sp[i][1]-sp[i-1][1])*f];} function segDist(x,y,a,b){const dx=b[0]-a[0],dy=b[1]-a[1],L=dx*dx+dy*dy||1;const t=clamp(((x-a[0])*dx+(y-a[1])*dy)/L,0,1);return Math.hypot(x-a[0]-t*dx,y-a[1]-t*dy);} function drawCables(ks){const z=cam.z,selC=UI.drag&&UI.drag.mode==='link'?UI.drag.from:(UI.sel&&UI.sel.type==='city'?UI.sel.id:null),cached=!!(WL.cv&&WL.key); @@ -3601,7 +3609,7 @@ function drawCables(ks){const z=cam.z,selC=UI.drag&&UI.drag.mode==='link'?UI.dra if(hot||!cached){ctx.globalAlpha=hot?0.95:0.4;ctx.strokeStyle=col;ctx.lineWidth=hot?3:1.6;ctx.lineJoin='round';ctx.setLineDash(C.age==='old'?[6,5]:[]);ctx.beginPath();ctx.moveTo(sp[0][0],sp[0][1]);for(let i=1;i=1.7){const m=sp[Math.floor(sp.length/2)];ctx.globalAlpha=hot?1:0.75;ctx.lineWidth=3;ctx.strokeStyle='rgba(255,255,255,.85)';ctx.strokeText(C.name,m[0],m[1]-8);ctx.fillStyle=col;ctx.fillText(C.name,m[0],m[1]-8);} ctx.globalAlpha=1;}}} -function bezGeom(l){const A=CITY[l.a],B=CITY[l.b];const i=pairLinks(l.a,l.b).indexOf(l);const key=l.id+'|'+i;const hit=GEO.get(key);if(hit)return hit; +function bezGeom(l,at){const A=CITY[l.a],B=CITY[l.b];const i=at!==undefined?at:pairLinks(l.a,l.b).indexOf(l);const key=l.id+'|'+i;const hit=GEO.get(key);if(hit)return hit; const bx=A.x+wrapDx(A.x,B.x),by=B.y;const dx=bx-A.x,dy=by-A.y,len=Math.hypot(dx,dy)||1;let nx=-dy/len,ny=dx/len;if(ny>0){nx=-nx;ny=-ny;} const base=Math.max(10,Math.min(len*0.13,110)),off0=i<=0?base:(i%2?-1:1)*(base*(i%2?0.2:1)+Math.ceil(i/2)*16); const mx=(A.x+bx)/2,my=(A.y+by)/2; diff --git a/tests/issues.test.js b/tests/issues.test.js index 13b30b8..181bf45 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -539,3 +539,18 @@ test('#35 your own trench can light another fiber pair once a ROADMaster is full assert.equal(ev('S.links[0].pairs'), 4, 'saves are clamped to four pairs'); assert.deepEqual(errors, []); }); + +test('#64 your own subsea cable runs beside the route, however many waves share it', () => { + const { ev, errors } = load(); + base(ev); + ev("ACT.buildPop({city:'lon'});ACT.buildPop({city:'dub'});S.links.push({id:'own',a:'lon',b:'dub',kind:'df',own:true,sub:true,km:475,sys:'roadm',ch:[],ready:0,mo:1,day:0,cut:0});GEO.clear()"); + const span = "(()=>{const g=linkGeom(S.links.find(l=>l.id==='own')),A=CITY.lon,B=CITY.dub;return Math.max(...g.pts.map(p=>segDist(p[0],p[1],[A.x,A.y],[B.x,B.y])));})()"; + const alone = ev(span); + ev("for(let i=0;i<8;i++)S.links.unshift({id:'w'+i,a:'lon',b:'dub',kind:'wave',tier:2,km:475,sub:true,cable:'celtix',mo:1,mult:1,trench:'cab:celtix',cut:0,day:0});GEO.clear()"); + const crowded = ev(span); + assert.ok(Math.abs(crowded - alone) < 0.01, 'the shape does not grow with the waves'); + assert.ok(crowded < 8, `stays close to the route (${crowded.toFixed(1)})`); + const g = ev("linkGeom(S.links.find(l=>l.id==='own')).pts"); + assert.ok(Math.hypot(g[0][0] - ev('CITY.lon.x'), g[0][1] - ev('CITY.lon.y')) < 1, 'still starts in London'); + assert.deepEqual(errors, []); +});