diff --git a/site/index.html b/site/index.html index 55fe564..9ed1851 100644 --- a/site/index.html +++ b/site/index.html @@ -1366,12 +1366,16 @@ function traceModal(src,to){const pops=Object.keys(S.pops).sort((a,b)=>CITY[a].n
${btn(tr('Copy'),'traceCopy',{},'ghost sm')}
`);UI.trText=r.text;} /* ---------- share card ---------- */ +// Straight link segments in map coordinates for flat maps. A link across the date line leaves one edge +// and comes back in at the other, so it becomes two segments, one per edge (#42). +function linkSegs(){const out=[];for(const l of S.links){const A=CITY[l.a],B=CITY[l.b];if(!A||!B)continue;const d=Math.abs(B.x-A.x)>W/2?(B.xi?g.lineTo(mx+q[0]*sx,my+q[1]*sy):g.moveTo(mx+q[0]*sx,my+q[1]*sy));g.closePath();g.fill();g.stroke();} - g.strokeStyle='#FF4F9A';g.lineWidth=2.5;for(const l of S.links){const A=CITY[l.a],B=CITY[l.b];let bx=B.x;if(Math.abs(bx-A.x)>W/2)bx+=bx { + const { ev, errors } = load(); + base(ev); + ev("S.links.push({id:'x1',a:'tok',b:'sea',kind:'wave',tier:0,km:7700,mult:1,mo:0},{id:'x2',a:'sea',b:'tok',kind:'wave',tier:0,km:7700,mult:1,mo:0},{id:'x3',a:'fra',b:'ams',kind:'wave',tier:0,km:400,mult:1,mo:0})"); + const segs = JSON.parse(ev('JSON.stringify(linkSegs())')); + assert.equal(segs.length, 5, 'two segments for each date-line link, one for the short one'); + for (const id of ['x1', 'x2']) { + const mine = JSON.parse(ev(`JSON.stringify((()=>{S.links=S.links.filter(l=>l.id==='${id}');return linkSegs();})())`)); + ev("S.links=[]"); + assert.ok(mine.some(([a, , b]) => Math.min(a, b) < 0), `${id} reaches past the left edge`); + assert.ok(mine.some(([a, , b]) => Math.max(a, b) > ev('W')), `${id} reaches past the right edge`); + ev("S.links.push({id:'x1',a:'tok',b:'sea',kind:'wave',tier:0,km:7700,mult:1,mo:0},{id:'x2',a:'sea',b:'tok',kind:'wave',tier:0,km:7700,mult:1,mo:0})"); + } + ev('shareCanvas()'); + assert.deepEqual(errors, []); +});