Merge pull request #309 from fjaeckel/claude/fix-305
This commit is contained in:
commit
efd7a42edd
5 changed files with 35 additions and 3 deletions
|
|
@ -6,6 +6,8 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- Your own subsea cables now land right on the city's dot, also in Fujairah, Dubai, Karachi, Barcelona, Osaka and other cities the map shifts slightly so they do not overlap (#305).
|
||||
|
||||
## [2.10.1] — 2026-11-05
|
||||
|
||||
- "Meet halfway" on a renewal now offers the price halfway between what the customer pays and what they ask, and the button shows it before you press (#293).
|
||||
|
|
|
|||
|
|
@ -155,7 +155,9 @@ function seaReady(a,b){seaSync();const key=seaKey(a,b);
|
|||
}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)=>{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;}
|
||||
// The ends sit on the cities' dots, which the map may nudge off their exact lon/lat (#305).
|
||||
function seaMapPoints(pts,a,b){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);}
|
||||
const n=out.length,end=(i,c)=>{if(c)out[i]=[c.x+W*Math.round((out[i][0]-c.x)/W),c.y];};if(n>1){end(0,CITY[a]);end(n-1,CITY[b]);}return out;}
|
||||
|
||||
// Designs pay for progressively tighter surveys; all use a feasible marine path.
|
||||
const SEA_DESIGNS={standard:{n:N_('common.standard'),cost:1,time:1},optimized:{n:N_('common.optimized'),cost:3,time:1.3},express:{n:N_('common.low_latency'),cost:7,time:1.7}};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function linkGroups(){const m=new Map();for(const l of S.links){const key=gKey(l
|
|||
// Mixed sizes are spelled out per size ("2×800G + 400G"): "2 × 1.2T" read like two 1.2T waves (#56).
|
||||
function groupLabel(grp,up){const n=[];for(const x of grp)n[x.tier]=(n[x.tier]||0)+1;let s='';for(let t=n.length-1;t>=0;t--)if(n[t])s+=(s?' + ':'')+(n[t]>1||n[t]===grp.length?n[t]+'×':'')+LT[t].n;return s+(up.length<grp.length?` · ${up.length}/${grp.length} ${tr('common.up')}`:'');}
|
||||
function linkGeom(l,pl){const i=lineIdx(l,pl);const key=l.id+'|'+i+'|'+(l.cable||'');const h=GEO.get(key);if(h)return h;
|
||||
let pts=l.kind==='df'&&l.own&&l.sub&&Array.isArray(l.seaPath)?seaMapPoints(l.seaPath):null;if(!pts&&l.cable){const cp=cablePair(l.cable,l.a,l.b);if(cp){pts=cp.pts.map(p=>p.slice());const same=pairLinks(l.a,l.b).filter(x=>x.cable===l.cable).indexOf(l);if(same>0)for(let j=1;j<pts.length-1;j++){pts[j][1]+=same*5;}}}
|
||||
let pts=l.kind==='df'&&l.own&&l.sub&&Array.isArray(l.seaPath)?seaMapPoints(l.seaPath,l.a,l.b):null;if(!pts&&l.cable){const cp=cablePair(l.cable,l.a,l.b);if(cp){pts=cp.pts.map(p=>p.slice());const same=pairLinks(l.a,l.b).filter(x=>x.cable===l.cable).indexOf(l);if(same>0)for(let j=1;j<pts.length-1;j++){pts[j][1]+=same*5;}}}
|
||||
// Your own subsea cable (#64) follows the shortest commercial cable on the same route, drawn alongside it; with
|
||||
// none, a gentle curve. Its shape must not depend on how many waves already run between the two cities.
|
||||
if(!pts&&l.kind==='df'&&l.own&&l.sub){const k=pairLinks(l.a,l.b).filter(x=>x.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);
|
||||
|
|
|
|||
28
tests/own-cable-landing.test.js
Normal file
28
tests/own-cable-landing.test.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// #305, #308: your own subsea cable lands on the city's dot, also where the map nudges a city off its exact spot.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
test('#305 an own subsea cable ends on both cities, nudged or not', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
ev("ACT.start({});S.cash=1e12;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0");
|
||||
// Fujairah, Karachi, Dubai, Barcelona and Osaka are all drawn a few pixels away from their exact lon/lat.
|
||||
for (const [a, b] of [['fuj', 'bom'], ['khi', 'bom'], ['dxb', 'bom'], ['bcn', 'mrs'], ['osa', 'tpe']]) {
|
||||
ev(`for(const city of ['${a}','${b}'])if(!S.pops[city])ACT.buildPop({city});UI.lmode='df';UI.dfSrc='cable';UI.pending={a:'${a}',b:'${b}'};UI.seaDesign='standard';ACT.orderCable()`);
|
||||
const l = JSON.parse(ev('JSON.stringify(S.links.at(-1))'));
|
||||
assert.deepEqual([l.a, l.b, l.own, l.sub, Array.isArray(l.seaPath)], [a, b, true, true, true], `${a}–${b} cable ordered`);
|
||||
ev('GEO.clear()');
|
||||
const g = JSON.parse(ev('JSON.stringify(linkGeom(S.links.at(-1)).pts)'));
|
||||
const A = JSON.parse(ev(`JSON.stringify([CITY.${a}.x,CITY.${a}.y])`)), B = JSON.parse(ev(`JSON.stringify([CITY.${b}.x,CITY.${b}.y])`));
|
||||
const W = ev('W'), at = (p, c) => Math.abs(p[1] - c[1]) < 1e-9 && Math.abs(((p[0] - c[0]) % W + W + W / 2) % W - W / 2) < 1e-9;
|
||||
assert.ok(at(g[0], A), `${a}–${b} starts on ${a}: ${g[0]} vs ${A}`);
|
||||
assert.ok(at(g[g.length - 1], B), `${a}–${b} ends on ${b}: ${g[g.length - 1]} vs ${B}`);
|
||||
// The map line keeps the surveyed route in between, and the saved path stays the real one.
|
||||
assert.equal(g.length, l.seaPath.length);
|
||||
const ll = JSON.parse(ev(`JSON.stringify([CITY.${a}.lon,CITY.${a}.lat])`));
|
||||
assert.ok(Math.abs(l.seaPath[0][0] - ll[0]) < 1e-9 && Math.abs(l.seaPath[0][1] - ll[1]) < 1e-9, 'saved path starts at the real landing');
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
|
@ -93,7 +93,7 @@ test('orders, previews, saved paths and map geometry agree; legacy cables retain
|
|||
ev('S=migrate(JSON.parse(JSON.stringify(S)));GEO.clear()');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.links.at(-1).seaPath)')), q.pts);
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(linkGeom(S.links.at(-1)).pts)')),
|
||||
JSON.parse(ev('JSON.stringify(seaMapPoints(S.links.at(-1).seaPath))')));
|
||||
JSON.parse(ev('JSON.stringify(seaMapPoints(S.links.at(-1).seaPath,"lag","bde"))')));
|
||||
ev("UI.dfSrc='cable';openLinkModal('lag','bde')");
|
||||
}
|
||||
ev("S.links.push({id:'legacy',a:'lag',b:'bde',kind:'df',own:true,sub:true,seaDesign:'optimized',sys:'roadm',km:7515,ch:[],ready:0,mo:1,cut:0});S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue