Sea routing: Suez and Panama crossings, great circles, fastest design back on par
After #133 the coastline router treated Egypt and Panama as solid land, so Marseille–Singapore sailed round Africa (21,440 km instead of 12,175) and Miami–Lima round Cape Horn (17,700 km for a 4,220 km hop). Real systems cross both by land: Port Said to Suez beside the canal, and Panama (PAN AM). These are now overland edges in the sea graph, priced as the distance they cover. The Red Sea Crisis shuts Suez, and routes are cached per set of open passages, also in the survey worker. Long open-water legs follow the great circle where it stays at sea, instead of a straight line on the map. The low-latency design may land further off and backhaul overland, and may follow the corridor of the fastest in-service cable on the pair when that is shorter, so it matches Hibernia again (London–New York 25.3 ms, Halifax–London 20.9 ms) and beats cables that take detours (Lagos–Bude 32.2 against 37.6 ms). Tests: main's expectations restored where #133 had loosened them (Marseille–Singapore needs no upgrades, New York–Sydney needs terminals, express equals the fastest cable); the marine check knows the passages; new checks for Suez, Panama, the crisis and the corridor rule.
This commit is contained in:
parent
656e904e05
commit
56f2d446ea
5 changed files with 105 additions and 39 deletions
|
|
@ -9,7 +9,7 @@ All notable changes to this project are documented here. The project follows
|
|||
- RouteScript has a new “Slop it with AI” button: an AI reads your live traffic, writes you a script and tells you how great it is. A new help page explains what every rule does and how real routers do the same, with seven ready-made scripts (Penny Pincher, Peering First, Shields Up and more) filled in from your own network and loaded with one tap.
|
||||
- Six Atlantic stops join the map: Halifax, Bermuda, the Azores, Tenerife, Cape Verde and St Helena (#120). The cables across the Atlantic now stop where they really land, and a POP on an island splits a crossing that is just too long for 1.6T into hops that each carry 1.6T or more: Miami to Madrid via Bermuda and the Azores, Atlanta to Lisbon via Bermuda, Lisbon and London to Lagos via Tenerife, and Fortaleza to Europe via Cape Verde. Halifax sits at the start of the shortest line to England. Three new cables, Sol Survivor, Atlantis-2: The Sequel and Canary in the Cable Mine, link the islands, and older ones gain island stops. Exchanges only where one runs today, in Praia and Halifax. New island networks from One Commotion to Pretty Sure South Atlantic, cables that go quiet in the Bermuda Triangle, and a new scenario, Mid-Atlantic Accent, asks you to cross at 1.6T hop by hop. Broadband in a very small town no longer starts above what the town can use.
|
||||
- You can zoom in much further on the map, and a short link between two close cities can now be picked (#126). Dense regions like southern Brazil spread out properly when you zoom in, and tapping right on a link next to a city opens the link instead of the city.
|
||||
- New player-built subsea cables follow surveyed sea routes around land. Their map paths, prices, optical reach and latency use the same distance, and premium designs are consistently faster. Existing cables keep their saved characteristics.
|
||||
- New player-built subsea cables follow surveyed sea routes around land (#133). Their map paths, prices, optical reach and latency use the same distance, and premium designs are consistently faster. Like real cables, routes between Europe and Asia cross Egypt beside the Suez Canal and routes between the Caribbean and the Pacific cross Panama, except during the Red Sea Crisis, which shuts the canal. The low-latency design is still as fast as the fastest cable on the map: it can follow that cable’s corridor, or land a little further off and run to an inland city over land. Quotes change with the real sea distance, cheaper on some routes and dearer on others. Existing cables keep their saved characteristics.
|
||||
|
||||
## [1.31.0] — 2026-10-26
|
||||
|
||||
|
|
|
|||
|
|
@ -4138,7 +4138,18 @@ const ownCabDays=km=>Math.round(300+km*0.05);
|
|||
// A quarter-degree grid keeps narrow passages open; edges are checked against
|
||||
// coastline segments as well as water cells, so diagonal steps cannot cut land.
|
||||
// Nothing is built until an order is quoted; topology and finished routes are reused.
|
||||
const SEA_NAV={step:0.25,nx:1440,ny:641,rows:new Map(),edges:null,tiles:new Map(),fine:new Set(),routes:new Map(),ports:new Map()};
|
||||
const SEA_NAV={step:0.25,nx:1440,ny:641,rows:new Map(),edges:null,tiles:new Map(),fine:new Set(),routes:new Map(),ports:new Map(),pass:null,closed:new Set()};
|
||||
// Real Europe–Asia cables land at Port Said and cross Egypt beside the canal to Suez; PAN AM crosses Panama by land.
|
||||
// Each is an overland edge between two sea cells, priced as the distance it covers.
|
||||
const SEA_PASS=[{id:'suez',a:[32.30,31.30],b:[32.58,29.85]},{id:'panama',a:[-79.90,9.40],b:[-79.50,8.85]}];
|
||||
function seaSnap(p){const cx=Math.round((seaLon(p[0])+180)/SEA_NAV.step)%SEA_NAV.nx,cy=Math.round((p[1]+80)/SEA_NAV.step);let best=null;
|
||||
for(let r=0;r<=16&&!best;r++)for(let dy=-r;dy<=r;dy++)for(let dx=-r;dx<=r;dx++){if(Math.max(Math.abs(dx),Math.abs(dy))!==r)continue;const x=(cx+dx+SEA_NAV.nx)%SEA_NAV.nx,y=cy+dy;if(!seaWater(x,y)||!seaNode(x,y))continue;const id=y*SEA_NAV.nx+x;if(!seaOpen(id))continue;const d=hav(...p,...seaPoint(id));if(!best||d<best.d)best={id,d};}
|
||||
return best&&best.id;}
|
||||
function seaPasses(){if(!SEA_NAV.pass){SEA_NAV.pass=new Map();for(const P of SEA_PASS){const a=seaSnap(P.a),b=seaSnap(P.b);if(a==null||b==null||a===b)continue;const km=hav(...seaPoint(a),...seaPoint(b));
|
||||
for(const [u,v] of [[a,b],[b,a]]){let L=SEA_NAV.pass.get(u);if(!L)SEA_NAV.pass.set(u,L=[]);L.push({to:v,km,id:P.id});}}}return SEA_NAV.pass;}
|
||||
// Which passages are shut: the Red Sea Crisis closes Suez. The main page sets this; the survey worker is told.
|
||||
function seaSync(){if(typeof S==='undefined')return;SEA_NAV.closed=new Set(S&&S.scn&&S.scn.id==='redsea'?['suez']:[]);}
|
||||
const seaKey=(a,b)=>(a<b?a+'|'+b:b+'|'+a)+(SEA_NAV.closed.size?'|x'+[...SEA_NAV.closed].sort().join(','):'');
|
||||
const seaLon=x=>((x+180)%360+360)%360-180;
|
||||
function seaInit(){if(SEA_NAV.edges)return;
|
||||
SEA_NAV.edges=Array.from({length:181},()=>[]);
|
||||
|
|
@ -4192,15 +4203,17 @@ function seaPorts(city){if(SEA_NAV.ports.has(city))return SEA_NAV.ports.get(city
|
|||
// Keep shore approaches in different directions; routing chooses the right sea.
|
||||
for(let r=0;r<=16;r++)for(let dy=-r;dy<=r;dy++)for(let dx=-r;dx<=r;dx++){
|
||||
if(Math.max(Math.abs(dx),Math.abs(dy))!==r)continue;const x=(cx+dx+SEA_NAV.nx)%SEA_NAV.nx,y=cy+dy;if(!seaWater(x,y)||!seaNode(x,y))continue;
|
||||
const id=y*SEA_NAV.nx+x,q=seaPoint(id),d=hav(...p,...q),angle=Math.atan2(q[1]-p[1],seaLon(q[0]-p[0])*Math.cos(c.lat*Math.PI/180)),bin=Math.floor((angle+Math.PI)*4/Math.PI)%8;
|
||||
const id=y*SEA_NAV.nx+x,q=seaPoint(id),d=hav(...p,...q),angle=Math.atan2(q[1]-p[1],seaLon(q[0]-p[0])*Math.cos(c.lat*Math.PI/180)),bin=Math.floor((angle+Math.PI)*8/Math.PI)%16+'|'+Math.floor(d/100);
|
||||
if(d>350||bins.has(bin)&&d>=bins.get(bin).d)continue;
|
||||
if(wet&&!seaClear(p,q))continue;
|
||||
if(!wet){const n=Math.max(2,Math.ceil(d/2));let water=false,ok=true;for(let i=0;i<=n;i++){const t=i/n,pt=[p[0]+seaLon(q[0]-p[0])*t,p[1]+(q[1]-p[1])*t];if(!seaLand(...pt)){water=true;if(!seaClear(pt,q)){ok=false;break;}}else if(water){ok=false;break;}}if(!ok)continue;}
|
||||
if(seaOpen(id))bins.set(bin,{id,d});
|
||||
if(seaOpen(id))bins.set(bin,{id,d,bin});
|
||||
}
|
||||
const sorted=[...bins.values()].sort((a,b)=>a.d-b.d),limit=sorted.length?(sorted[0].d<30?sorted[0].d+15:sorted[0].d*1.75):0,ports=sorted.filter(p=>p.d<=limit);SEA_NAV.ports.set(city,ports);return ports;
|
||||
// Nearby approaches are the default. A low-latency survey may also land further off and backhaul overland, like real
|
||||
// transatlantic systems that land in the west of England and run to London on land.
|
||||
const sorted=[...bins.values()].sort((a,b)=>a.d-b.d),limit=sorted.length?(sorted[0].d<30?sorted[0].d+15:sorted[0].d*1.75):0,dir=new Set(),ports=sorted.map(p=>{const k=p.bin.split('|')[0]>>1;const first=!dir.has(k);dir.add(k);return {id:p.id,d:p.d,near:first&&p.d<=limit};});SEA_NAV.ports.set(city,ports);return ports;
|
||||
}
|
||||
const seaPort=city=>seaPorts(city)[0]?.id??null;
|
||||
const seaPort=city=>seaPorts(city)[0]?.id??null,seaNear=ps=>ps.filter(p=>p.near);
|
||||
// The grid topology is shared by all designs. Test each edge only once.
|
||||
function seaStep(id,dx,dy){if(!SEA_NAV.known){const n=SEA_NAV.nx*SEA_NAV.ny;SEA_NAV.known=new Uint8Array(n);SEA_NAV.open=new Uint8Array(n);SEA_NAV.knownWide=new Uint8Array(n);SEA_NAV.openWide=new Uint8Array(n);}
|
||||
const wide=Math.abs(dx)>1||Math.abs(dy)>1,sx=Math.sign(dx),sy=Math.sign(dy),bit=1<<((sy+1)*3+sx+1-(sy>0||sy===0&&sx>0?1:0)),known=wide?SEA_NAV.knownWide:SEA_NAV.known,open=wide?SEA_NAV.openWide:SEA_NAV.open;
|
||||
|
|
@ -4210,13 +4223,14 @@ function seaStep(id,dx,dy){if(!SEA_NAV.known){const n=SEA_NAV.nx*SEA_NAV.ny;SEA_
|
|||
for(const e of SEA_NAV.tiles.get((((x+90)%180+180)%180)+','+y)||[])if(seaCross(a,b,e))return false;
|
||||
open[id]|=bit;return true;
|
||||
}
|
||||
function seaSearch(starts,ends,target,clearance){
|
||||
function seaSearch(starts,ends,target,clearance){const PASS=seaPasses();
|
||||
const dist=new Map(),prev=new Map(),done=new Set(),heap=[],goals=new Map(ends.map(p=>[p.id,p.d]));let goal=Infinity,goalEnd=null;
|
||||
const put=(id,g)=>{const v={id,g,f:g+(id===-1?0:hav(...seaPoint(id),...target))};let i=heap.length;heap.push(v);while(i){const p=(i-1)>>1;if(heap[p].f<=v.f)break;heap[i]=heap[p];i=p;}heap[i]=v;};
|
||||
const take=()=>{const out=heap[0],v=heap.pop();if(heap.length){let i=0;while(i*2+1<heap.length){let j=i*2+1;if(j+1<heap.length&&heap[j+1].f<heap[j].f)j++;if(heap[j].f>=v.f)break;heap[i]=heap[j];i=j;}heap[i]=v;}return out;};
|
||||
for(const p of starts){dist.set(p.id,p.d);put(p.id,p.d);}
|
||||
while(heap.length){const {id,g}=take();if(id===-1){const path=[];for(let v=goalEnd;v!==undefined;v=prev.get(v))path.push(seaPoint(v));return path.reverse();}if(done.has(id))continue;done.add(id);if(goals.has(id)&&g+goals.get(id)<goal){goal=g+goals.get(id);goalEnd=id;put(-1,goal);}
|
||||
const x=id%SEA_NAV.nx,y=Math.floor(id/SEA_NAV.nx),a=seaPoint(id);
|
||||
for(const P of PASS.get(id)||[]){if(SEA_NAV.closed.has(P.id)||done.has(P.to))continue;const ng=g+P.km;if(ng<(dist.get(P.to)??Infinity)){dist.set(P.to,ng);prev.set(P.to,id);put(P.to,ng);}}
|
||||
for(const stride of (x%4===0&&y%4===0?[4,1]:[1]))for(let sy=-1;sy<=1;sy++)for(let sx=-1;sx<=1;sx++){if(!sx&&!sy)continue;const dx=sx*stride,dy=sy*stride,xx=(x+dx+SEA_NAV.nx)%SEA_NAV.nx,yy=y+dy,v=yy*SEA_NAV.nx+xx;if(done.has(v)||!seaNode(xx,yy)||!seaWater(xx,yy))continue;
|
||||
const b=seaPoint(v);if(!seaStep(id,dx,dy))continue;
|
||||
const near=clearance&&(!seaWater(xx-2,yy)||!seaWater(xx+2,yy)||!seaWater(xx,yy-2)||!seaWater(xx,yy+2)),ng=g+hav(...a,...b)*(near?1+clearance:1);
|
||||
|
|
@ -4226,12 +4240,18 @@ function seaSearch(starts,ends,target,clearance){
|
|||
}
|
||||
function seaSimplify(path,margin){const out=[path[0]];for(let i=0;i<path.length-1;){let j=Math.min(path.length-1,i+64);while(j>i+1&&!seaClear(path[i],path[j],margin))j--;out.push(path[j]);i=j;}return out;}
|
||||
function seaDensify(path){const out=[path[0].slice()];for(let i=1;i<path.length;i++){const a=path[i-1],b=path[i],dx=seaLon(b[0]-a[0]),n=Math.max(1,Math.ceil(Math.max(Math.abs(dx),Math.abs(b[1]-a[1]))));for(let j=1;j<=n;j++)out.push([seaLon(a[0]+dx*j/n),a[1]+(b[1]-a[1])*j/n]);}return out;}
|
||||
// Points along the great circle from a to b, about every half degree.
|
||||
function seaGC(a,b){const r=Math.PI/180,v=([lo,la])=>[Math.cos(la*r)*Math.cos(lo*r),Math.cos(la*r)*Math.sin(lo*r),Math.sin(la*r)],A=v(a),B=v(b),w=Math.acos(Math.min(1,A[0]*B[0]+A[1]*B[1]+A[2]*B[2]));
|
||||
const n=Math.max(1,Math.ceil(w/r/0.5)),out=[];if(w<1e-9)return [b.slice()];for(let i=1;i<=n;i++){const t=i/n,f=Math.sin((1-t)*w)/Math.sin(w),g=Math.sin(t*w)/Math.sin(w),x=f*A[0]+g*B[0],y=f*A[1]+g*B[1],z=f*A[2]+g*B[2];out.push([seaLon(Math.atan2(y,x)/r),Math.atan2(z,Math.hypot(x,y))/r]);}return out;}
|
||||
// A straight line on the map is not the shortest way across an ocean. Long legs follow the great circle where it stays at sea.
|
||||
function seaGreat(path,margin){const out=[path[0]];for(let i=1;i<path.length;i++){const a=path[i-1],b=path[i];
|
||||
if(hav(...a,...b)>300){const gc=seaGC(a,b);let ok=true,q=a;for(const p of gc){if(!seaClear(q,p,margin)){ok=false;break;}q=p;}if(ok){out.push(...gc);continue;}}out.push(b);}return out;}
|
||||
const seaLength=pts=>Math.round(pts.slice(1).reduce((s,p,i)=>s+hav(...pts[i],...p),0));
|
||||
function seaRoutes(a,b){const reverse=a>b,key=reverse?b+'|'+a:a+'|'+b;let routes=SEA_NAV.routes.get(key);
|
||||
if(!routes){const A=reverse?b:a,B=reverse?a:b,starts=seaPorts(A),ends=seaPorts(B);routes=[];
|
||||
if(starts.length&&ends.length)for(const [penalty,margin] of [[1,0.5],[0.3,0.25],[0,0]]){
|
||||
const raw=seaSearch(starts,ends,[CITY[B].lon,CITY[B].lat],penalty);if(!raw)break;
|
||||
const pts=seaDensify([[CITY[A].lon,CITY[A].lat],...seaSimplify(raw,margin),[CITY[B].lon,CITY[B].lat]]),r={pts,km:seaLength(pts),shore:[raw[0],raw[raw.length-1]]};
|
||||
function seaRoutes(a,b){seaSync();const reverse=a>b,key=seaKey(a,b);let routes=SEA_NAV.routes.get(key);
|
||||
if(!routes){const A=reverse?b:a,B=reverse?a:b,PA=seaPorts(A),PB=seaPorts(B);routes=[];
|
||||
if(seaNear(PA).length&&seaNear(PB).length)for(const [penalty,margin,all] of [[1,0.5,false],[0.3,0.25,false],[0,0,true]]){
|
||||
const raw=seaSearch(all?PA:seaNear(PA),all?PB:seaNear(PB),[CITY[B].lon,CITY[B].lat],penalty);if(!raw)break;
|
||||
const pts=seaDensify(seaGreat([[CITY[A].lon,CITY[A].lat],...seaSimplify(raw,margin),[CITY[B].lon,CITY[B].lat]],margin)),r={pts,km:seaLength(pts),shore:[raw[0],raw[raw.length-1]]};
|
||||
// A survey can reuse the previous feasible route if its new candidate is longer.
|
||||
routes.push(routes.length&&r.km>routes[routes.length-1].km?routes[routes.length-1]:r);
|
||||
}SEA_NAV.routes.set(key,routes);
|
||||
|
|
@ -4241,24 +4261,24 @@ function seaRoutes(a,b){const reverse=a>b,key=reverse?b+'|'+a:a+'|'+b;let routes
|
|||
// Surveys run off the UI thread in browsers. Tests and browsers without workers
|
||||
// use the same deterministic router synchronously. Switching designs uses the cache.
|
||||
const SEA_SURVEY={worker:null,pending:new Set(),failed:false};
|
||||
function seaReady(a,b){const key=a<b?a+'|'+b:b+'|'+a;
|
||||
function seaReady(a,b){seaSync();const key=seaKey(a,b);
|
||||
if(SEA_NAV.routes.has(key)||typeof Worker==='undefined'||SEA_SURVEY.failed)return true;
|
||||
if(SEA_SURVEY.pending.has(key))return false;
|
||||
try{
|
||||
if(!SEA_SURVEY.worker){
|
||||
const helpers=[seaLon,seaInit,seaLand,seaWater,seaCross,seaClear,seaPoint,seaNode,seaOpen,seaPorts,seaPort,seaStep,seaSearch,seaSimplify,seaDensify,seaLength,seaRoutes,hav,clamp];
|
||||
const code='const COAST_LL='+JSON.stringify(COAST_LL)+';const CITY='+JSON.stringify(Object.fromEntries(CITIES.map(c=>[c.id,{lon:c.lon,lat:c.lat}])))+';const SEA_NAV={step:0.25,nx:1440,ny:641,rows:new Map(),edges:null,tiles:new Map(),fine:new Set(),routes:new Map(),ports:new Map()};'+
|
||||
helpers.map(f=>'const '+f.name+'='+f.toString()+';').join('')+'onmessage=({data:{a,b,key}})=>{try{postMessage({key,routes:seaRoutes(a,b)});}catch(e){postMessage({key,error:String(e)});}};';
|
||||
const helpers=[seaSnap,seaPasses,seaGC,seaGreat,seaNear,seaKey,seaSync,seaLon,seaInit,seaLand,seaWater,seaCross,seaClear,seaPoint,seaNode,seaOpen,seaPorts,seaPort,seaStep,seaSearch,seaSimplify,seaDensify,seaLength,seaRoutes,hav,clamp];
|
||||
const code='const SEA_PASS='+JSON.stringify(SEA_PASS)+';const COAST_LL='+JSON.stringify(COAST_LL)+';const CITY='+JSON.stringify(Object.fromEntries(CITIES.map(c=>[c.id,{lon:c.lon,lat:c.lat}])))+';const SEA_NAV={step:0.25,nx:1440,ny:641,rows:new Map(),edges:null,tiles:new Map(),fine:new Set(),routes:new Map(),ports:new Map(),pass:null,closed:new Set()};'+
|
||||
helpers.map(f=>'const '+f.name+'='+f.toString()+';').join('')+'onmessage=({data:{a,b,key,closed}})=>{try{SEA_NAV.closed=new Set(closed||[]);postMessage({key,routes:seaRoutes(a,b)});}catch(e){postMessage({key,error:String(e)});}};';
|
||||
const url=URL.createObjectURL(new Blob([code],{type:'text/javascript'}));
|
||||
try{SEA_SURVEY.worker=new Worker(url);}finally{URL.revokeObjectURL(url);}
|
||||
const refresh=key=>{if(!S)return;const survey=$('modalCard').querySelector('[data-sea-survey]');if(UI.pending&&!$('modal').hidden&&survey&&(!key||survey.dataset.seaSurvey===key))openLinkModal(UI.pending.a,UI.pending.b);renderPanel();renderLeft();if(!$('dash').hidden)renderDash();};
|
||||
SEA_SURVEY.worker.onmessage=({data})=>{SEA_SURVEY.pending.delete(data.key);if(data.error){SEA_SURVEY.failed=true;SEA_SURVEY.worker.terminate();SEA_SURVEY.worker=null;SEA_SURVEY.pending.clear();}else SEA_NAV.routes.set(data.key,data.routes);refresh(data.error?undefined:data.key);};
|
||||
SEA_SURVEY.worker.onerror=()=>{SEA_SURVEY.failed=true;SEA_SURVEY.worker.terminate();SEA_SURVEY.worker=null;SEA_SURVEY.pending.clear();refresh();};
|
||||
}
|
||||
SEA_SURVEY.pending.add(key);const [from,to]=key.split('|');SEA_SURVEY.worker.postMessage({a:from,b:to,key});return false;
|
||||
SEA_SURVEY.pending.add(key);const [from,to]=key.split('|');SEA_SURVEY.worker.postMessage({a:from,b:to,key,closed:[...SEA_NAV.closed]});return false;
|
||||
}catch(e){SEA_SURVEY.failed=true;if(SEA_SURVEY.worker)SEA_SURVEY.worker.terminate();SEA_SURVEY.worker=null;SEA_SURVEY.pending.clear();return true;}
|
||||
}
|
||||
const seaSurveyAttr=(a,b)=>{const k=a<b?a+'|'+b:b+'|'+a;return SEA_SURVEY.pending.has(k)?`data-sea-survey="${k}"`:'';};
|
||||
const seaSurveyAttr=(a,b)=>{seaSync();const k=seaKey(a,b);return SEA_SURVEY.pending.has(k)?`data-sea-survey="${k}"`:'';};
|
||||
function seaMapPoints(pts){const out=[];for(const p of pts){const q=proj(...p);if(out.length)q[0]+=W*Math.round((out[out.length-1][0]-q[0])/W);out.push(q);}return out;}
|
||||
|
||||
// Designs pay for progressively tighter surveys; all use a feasible marine path.
|
||||
|
|
@ -4271,13 +4291,20 @@ function seaReference(a,b,express){
|
|||
const SEA_XF=new Map();
|
||||
function seaLatencyFactor(l){if(l.seaDesign==='optimized')return 1;if(l.seaDesign!=='express')return 1.1;
|
||||
const k=CIDX[l.a]*4096+CIDX[l.b];let f=SEA_XF.get(k);if(f===undefined){const c=seaReference(l.a,l.b,true);SEA_XF.set(k,f=Math.min(0.9,c?(CAB[c.cid].lat||1):0.9));}return f;}
|
||||
// The low-latency survey may also follow the corridor of the fastest cable already on this route, where that is shorter
|
||||
// (only a cable that is in service: one cut by a crisis proves nothing):
|
||||
// that cable proves the path, and it keeps the fastest design as fast as the fastest cable on the map.
|
||||
function seaCorridor(a,b){const c=cablesOk(a,b).sort((x,y)=>x.km*(CAB[x.cid].lat||1)-y.km*(CAB[y.cid].lat||1))[0];if(!c)return null;const P=CAB[c.cid].pairs.find(([x,y])=>x===c.a&&y===c.b);if(!P)return null;
|
||||
let ll=[[CITY[c.a].lon,CITY[c.a].lat],...P[2],[CITY[c.b].lon,CITY[c.b].lat]].map(q=>[seaLon(q[0]),q[1]]);if(c.a!==a)ll=ll.reverse();
|
||||
const pts=[ll[0]];for(let i=1;i<ll.length;i++)pts.push(...seaGC(ll[i-1],ll[i]));return {km:seaLength(pts),pts,shore:[pts[1],pts[pts.length-2]]};}
|
||||
function seaQuote(a,b,design='standard',upgrades={}){
|
||||
const D=SEA_DESIGNS[design],routes=seaRoutes(a,b),route=routes[Object.keys(SEA_DESIGNS).indexOf(design)],base=routes[0]?.km||Infinity,km=route?.km||Infinity;
|
||||
const D=SEA_DESIGNS[design],routes=seaRoutes(a,b),cor=design==='express'&&routes.length?seaCorridor(a,b):null;let route=routes[Object.keys(SEA_DESIGNS).indexOf(design)];if(cor&&route&&cor.km<route.km)route=cor;
|
||||
const base=routes[0]?.km||Infinity,km=route?.km||Infinity;
|
||||
// Higher survey and permitting costs dominate any savings from shorter glass.
|
||||
let cost=Math.round(ownCabCost(Math.max(base,km))*D.cost),days=Math.round(ownCabDays(Math.max(base,km))*D.time);
|
||||
for(const k of Object.keys(SUB_UPGRADES))if(upgrades[k]){cost+=subUpgradeCost({km},k);days+=SUB_UPGRADES[k].days;}
|
||||
const ms=linkLat({a,b,kind:'df',own:true,sub:true,km,seaDesign:design});
|
||||
return {km,cost,days,ms,pts:route?.pts,shore:route?.shore};
|
||||
return {km,cost,days,ms,pts:route?.pts,shore:route?.shore,cor:!!cor&&route===cor};
|
||||
}
|
||||
// Some pairs share a landmass and still have cables between them (Marseille–Singapore, Cairo–Palermo) (#67).
|
||||
const seaCab=(a,b)=>isSub(a,b)||(landing(a)&&landing(b)&&cablesFor(a,b).length>0);
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ test('#67 a subsea cable can be laid between landing stations that also share a
|
|||
assert.ok(ev("!!document.querySelector('#modalCard [data-act=ownCab]')"), 'the dark fiber window offers the cable');
|
||||
ev("ACT.ownCab()");
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /km of seabed/);
|
||||
ev("UI.seaengineering=true;ACT.orderCable()");
|
||||
ev("ACT.orderCable()");
|
||||
assert.ok(ev("S.links.some(l=>l.own&&l.sub&&l.a==='mrs'&&l.b==='sin')"), 'Marseille–Singapore cable ordered');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -699,8 +699,8 @@ test('NOC leased lines tab prices leased dark fiber, own fiber and cables agains
|
|||
const sub = JSON.parse(ev("JSON.stringify(leaseSwaps().find(x=>x.sub))"));
|
||||
assert.equal(sub.why, '');
|
||||
assert.ok(sub.opts.find(o => o.k === 'cab').up > ev("ownCabCost(ownCabKm('lon','nyc'))"));
|
||||
ev("for(const c of ['cai','pmo'])ACT.buildPop({city:c});for(const c in S.pops)S.pops[c].rgen=2;UI.via=null;openLinkModal('cai','pmo');ACT.buildLink({tier:2});closeModal();compute()");
|
||||
const ms = JSON.parse(ev("JSON.stringify(leaseSwaps().find(x=>x.a==='cai'&&x.b==='pmo'))"));
|
||||
ev("for(const c of ['mrs','sin'])ACT.buildPop({city:c});for(const c in S.pops)S.pops[c].rgen=2;UI.via=null;openLinkModal('mrs','sin');ACT.buildLink({tier:2});closeModal();compute()");
|
||||
const ms = JSON.parse(ev("JSON.stringify(leaseSwaps().find(x=>x.a==='mrs'&&x.b==='sin'))"));
|
||||
assert.ok(ms && ms.opts.some(o => o.k === 'cab'), 'landing stations on one landmass can swap a wave for your own cable (#67)');
|
||||
ev("ACT.leaseSwap({a:'ams',b:'fra',src:'lease'})");
|
||||
assert.equal(ev("document.getElementById('dash').hidden"), true);
|
||||
|
|
@ -1058,10 +1058,10 @@ test('#104 declining a loan offer clears the bank badge while paused', () => {
|
|||
test('#88 no subsea cable longer than any optic can light, and a refund for calling one off', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e10;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0");
|
||||
// New York to Sydney is too long for plain optics; the marine route needs optical engineering, so the order screen asks
|
||||
// New York to Sydney is too long for plain optics; since #78 premium terminals light it, so the order screen asks
|
||||
// for them instead of refusing. Only a length beyond even both upgrades is refused.
|
||||
assert.equal(ev("ownCabWhy('nyc','syd')"), '');
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(subNeed(ownCabKm('nyc','syd')))")), ['engineering']);
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(subNeed(ownCabKm('nyc','syd')))")), ['terminal']);
|
||||
assert.equal(ev('subNeed(26000)'), null, 'nothing lights 26,000 km');
|
||||
assert.equal(ev("ownCabWhy('lax','syd')"), '', 'Los Angeles to Sydney still works');
|
||||
assert.ok(ev("subCarrier(ownCabKm('lax','syd'))") > 0);
|
||||
|
|
|
|||
|
|
@ -708,7 +708,7 @@ test('subsea cable designs trade construction cost and time for previewed latenc
|
|||
assert.ok(quotes[1].cost >= quotes[0].cost * 3 && quotes[2].cost >= quotes[0].cost * 7);
|
||||
assert.ok(quotes[1].days >= Math.round(quotes[0].days * 1.3) && quotes[2].days >= Math.round(quotes[0].days * 1.7));
|
||||
assert.ok(quotes[2].days < 3 * 365, 'a low-latency Atlantic cable takes years, not most of a decade');
|
||||
assert.equal(quotes[2].km, ev("seaLength(seaRoutes('lon','nyc')[2].pts)"), 'express length follows its surveyed marine path');
|
||||
assert.equal(quotes[2].ms, ev("Math.min(...cablesFor('lon','nyc').map(c=>linkLat({kind:'wave',km:c.km,cable:c.cid})))"), 'express competes with Hibernia');
|
||||
for (const q of quotes) assert.ok(dom.window.document.getElementById('modalCard').textContent.includes(q.ms.toFixed(1) + ' ms one-way'), 'every latency is visible before ordering');
|
||||
for (const [i, design] of ['standard', 'optimized', 'express'].entries()) {
|
||||
ev("UI.lmode='df';UI.dfSrc='cable';openLinkModal('lon','nyc')");
|
||||
|
|
@ -842,22 +842,22 @@ test('own subsea cables after #78: refunds of what was paid, upgrades a route ne
|
|||
assert.equal(ev('UI.seaDesign'), 'standard', 'the next order starts from the standard design');
|
||||
// its latency is worked out once per route, and stays the same
|
||||
const ms = ev('linkLat(S.links.at(-1))'); assert.equal(ev('linkLat(S.links.at(-1))'), ms); assert.ok(ev('SEA_XF.size') >= 1);
|
||||
// New York to Sydney needs optical engineering: the screen says so and will not order without them
|
||||
// New York to Sydney needs premium terminals: the screen says so and will not order without them
|
||||
open('nyc', 'syd');
|
||||
assert.match(q('.why'), /Add Optical engineering/);
|
||||
assert.match(q('.why'), /Add Premium submarine terminals/);
|
||||
assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /A leased .* wave on this route/, 'no leased wave reaches that far, so no comparison with one');
|
||||
assert.equal(ev("document.querySelector('#modalCard [data-act=orderCable]').disabled"), true);
|
||||
const n = ev('S.links.length'); ev('ACT.orderCable()'); assert.equal(ev('S.links.length'), n, 'the order itself checks too');
|
||||
ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=engineering]').click()");
|
||||
assert.equal(q('.why'), null); assert.match(q('[data-act=seaPackage][data-args*=engineering]'), /\+180 days/);
|
||||
ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click()");
|
||||
assert.equal(q('.why'), null); assert.match(q('[data-act=seaPackage][data-args*=terminal]'), /\+30 days/);
|
||||
// leaving and coming back to another route starts fresh
|
||||
open('lon', 'nyc'); assert.equal(ev('!!UI.seaengineering'), false);
|
||||
open('nyc', 'syd'); ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=engineering]').click();ACT.orderCable()");
|
||||
open('lon', 'nyc'); assert.equal(ev('!!UI.seaterminal'), false);
|
||||
open('nyc', 'syd'); ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click();ACT.orderCable()");
|
||||
const syd = JSON.parse(ev("JSON.stringify(S.links.at(-1))"));
|
||||
assert.equal(syd.b, 'syd'); assert.equal(syd.subengineering, syd.ready);
|
||||
ev('S.day=S.links.at(-1).ready'); assert.equal(ev("optG('tp16',S.links.at(-1))"), 400, 'lit across the surveyed marine route');
|
||||
assert.equal(syd.b, 'syd'); assert.equal(syd.subterminal, syd.ready);
|
||||
ev('S.day=S.links.at(-1).ready'); assert.equal(ev("optG('tp16',S.links.at(-1))"), 400, 'lit across 18,387 km');
|
||||
// upgrades bought later count toward the price; sanitize keeps a sane price and drops junk
|
||||
ev("S.links.at(-1).subterminal=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'terminal'})");
|
||||
ev("S.links.at(-1).subengineering=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})");
|
||||
assert.ok(ev('S.links.at(-1).paid') > syd.paid);
|
||||
ev("S.links.at(-1).paid='lots';S.links[0].paid=-5;S=sanitize(S)");
|
||||
assert.equal(ev('S.links.at(-1).paid'), undefined); assert.equal(ev('S.links[0].paid'), undefined);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ const { load } = require('./harness');
|
|||
|
||||
// Check the surveyed part independently against the original coastline segments.
|
||||
// City markers may sit inland: their two short shore approaches are excluded.
|
||||
function assertMarine(path, start, end, coast) {
|
||||
// The overland passages (beside the Suez Canal, across Panama) are the only places a surveyed route may cross land.
|
||||
// A piece lies on a passage when both its ends sit on the straight line between that passage's two sea cells.
|
||||
const onLine = (x, [p, q]) => { const dx = q[0] - p[0], dy = q[1] - p[1], t = ((x[0] - p[0]) * dx + (x[1] - p[1]) * dy) / (dx * dx + dy * dy); return t > -1e-6 && t < 1 + 1e-6 && Math.hypot(p[0] + t * dx - x[0], p[1] + t * dy - x[1]) < 1e-6; };
|
||||
const isPass = (a, b, passes) => passes.some(P => onLine(a, P) && onLine(b, P));
|
||||
function assertMarine(path, start, end, coast, passes = []) {
|
||||
const at = p => path.findIndex(q => Math.abs(p[0] - q[0]) < 1e-8 && Math.abs(p[1] - q[1]) < 1e-8);
|
||||
const first = at(start), last = at(end);
|
||||
assert.ok(first >= 0 && last >= first, 'both shore approaches appear in the saved path');
|
||||
|
|
@ -13,6 +17,7 @@ function assertMarine(path, start, end, coast) {
|
|||
for (let i = first + 1; i <= last; i++) {
|
||||
const a = path[i - 1], b = [...path[i]];
|
||||
b[0] += 360 * Math.round((a[0] - b[0]) / 360);
|
||||
if (isPass(path[i - 1], path[i], passes)) continue;
|
||||
for (const [p, q] of edges) {
|
||||
const shift = 360 * Math.round((a[0] - p[0]) / 360), c = [p[0] + shift, p[1]], d = [q[0] + shift, q[1]];
|
||||
assert.ok(!(turn(a, b, c) * turn(a, b, d) < -1e-12 && turn(c, d, a) * turn(c, d, b) < -1e-12),
|
||||
|
|
@ -25,12 +30,14 @@ test('surveyed designs avoid land, use real path lengths and improve latency', (
|
|||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
const coast = JSON.parse(ev('JSON.stringify(COAST_LL)'));
|
||||
const passes = JSON.parse(ev('JSON.stringify([...seaPasses().entries()].flatMap(([u,L])=>L.map(P=>[seaPoint(u),seaPoint(P.to)])))'));
|
||||
for (const [a, b] of [['lag', 'bde'], ['cbo', 'nyc'], ['lax', 'tok'], ['mrs', 'sin'], ['cai', 'pmo']]) {
|
||||
const quotes = JSON.parse(ev(`JSON.stringify(Object.keys(SEA_DESIGNS).map(d=>seaQuote('${a}','${b}',d)))`));
|
||||
for (let i = 0; i < quotes.length; i++) {
|
||||
const q = quotes[i];
|
||||
assert.ok(Number.isFinite(q.km) && q.pts.length > 2);
|
||||
assertMarine(q.pts, ...q.shore, coast);
|
||||
// the fastest design may follow the corridor of an existing cable instead, which is drawn as that cable is
|
||||
if (!q.cor) assertMarine(q.pts, ...q.shore, coast, passes);
|
||||
assert.equal(q.km, ev(`seaLength(${JSON.stringify(q.pts)})`));
|
||||
if (i) {
|
||||
assert.ok(q.km <= quotes[i - 1].km, 'premium surveys never lengthen the route');
|
||||
|
|
@ -44,8 +51,14 @@ test('surveyed designs avoid land, use real path lengths and improve latency', (
|
|||
}
|
||||
assert.ok(ev("seaQuote('cai','pmo').km<3000"), 'Cairo approaches the Mediterranean rather than routing out of the Red Sea');
|
||||
assert.equal(ev("cablesFor('cbo','nyc').length"), 0, 'route works without an existing cable');
|
||||
assert.ok(ev("seaQuote('cbo','nyc').km > kmBetween('cbo','nyc')*1.3"), 'the route detours around Africa');
|
||||
assert.ok(ev("seaQuote('mrs','sin').pts.some(p=>p[0]>-7&&p[0]<-4&&p[1]>35&&p[1]<37)"), 'the Mediterranean route passes Gibraltar');
|
||||
assert.ok(ev("seaQuote('cbo','nyc').km > kmBetween('cbo','nyc')*1.1"), 'the route detours through the Mediterranean');
|
||||
// Europe to Asia crosses Egypt beside the Suez Canal, like real cables, instead of sailing round Africa
|
||||
assert.ok(ev("seaQuote('mrs','sin').km") < 13000, `Marseille–Singapore via Suez (${ev("seaQuote('mrs','sin').km")} km)`);
|
||||
assert.ok(ev("seaQuote('mrs','sin').pts.some(p=>p[0]>31.5&&p[0]<33.5&&p[1]>29.5&&p[1]<31.5)"), 'the route crosses at Suez');
|
||||
assert.equal(JSON.stringify(ev("subNeed(ownCabKm('mrs','sin'))")), '[]', 'no upgrades needed for Marseille–Singapore');
|
||||
// the Caribbean and the Pacific meet across Panama
|
||||
assert.ok(ev("seaQuote('mia','lim').km") < 6000, `Miami–Lima via Panama (${ev("seaQuote('mia','lim').km")} km)`);
|
||||
assert.ok(ev("seaQuote('mia','lim').pts.some(p=>p[0]>-80.5&&p[0]<-79&&p[1]>8.5&&p[1]<9.8)"), 'the route crosses Panama');
|
||||
assert.ok(ev("seaQuote('lax','tok').pts.some((p,i,a)=>i&&Math.abs(p[0]-a[i-1][0])>180)"), 'Pacific route wraps the date line');
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
|
|
@ -118,3 +131,29 @@ test('background surveys deduplicate requests and do not replace a later dialog'
|
|||
assert.equal(ev('SEA_SURVEY.pending.size'), 0);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('the fastest design is as fast as the fastest cable, and the Red Sea Crisis closes Suez', () => {
|
||||
const { ev, errors, dom } = load();
|
||||
try {
|
||||
// where a cable already runs, the low-latency design follows its corridor if that is shorter than its own survey
|
||||
for (const [a, b] of [['lon', 'nyc'], ['hfx', 'lon']]) {
|
||||
const best = ev(`Math.min(...cablesFor('${a}','${b}').map(c=>linkLat({kind:'wave',km:c.km,cable:c.cid})))`);
|
||||
const q = JSON.parse(ev(`JSON.stringify(seaQuote('${a}','${b}','express'))`));
|
||||
assert.ok(q.ms <= best + 1e-9, `${a}–${b}: ${q.ms.toFixed(2)} ms against ${best.toFixed(2)} ms`);
|
||||
assert.equal(q.km, ev(`seaLength(${JSON.stringify(q.pts)})`), 'map and price use the same path');
|
||||
}
|
||||
// and where the existing cable takes a detour, the survey beats it
|
||||
assert.ok(ev("seaQuote('lag','bde','express').ms") < ev("Math.min(...cablesFor('lag','bde').map(c=>linkLat({kind:'wave',km:c.km,cable:c.cid})))"));
|
||||
// the crisis shuts the canal for your own cables too, and the cache keeps the two cases apart
|
||||
const open = ev("seaQuote('mrs','sin').km");
|
||||
ev("ACT.startScn({id:'redsea',sure:1})");
|
||||
const shut = ev("seaQuote('mrs','sin').km");
|
||||
assert.ok(shut > open + 5000, `round Africa in the crisis (${shut} km against ${open} km)`);
|
||||
assert.ok(ev("seaQuote('mrs','sin','express').km") > open + 5000, 'the fastest design cannot borrow a cut cable');
|
||||
assert.ok(ev("seaQuote('mrs','sin').pts.some(p=>p[0]>-7&&p[0]<-4&&p[1]>35&&p[1]<37)"), 'out through Gibraltar');
|
||||
ev("ACT.start({})");
|
||||
assert.equal(ev("seaQuote('mrs','sin').km"), open, 'back to Suez in a normal game');
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue