diff --git a/site/index.html b/site/index.html index fd66f9e..55fe564 100644 --- a/site/index.html +++ b/site/index.html @@ -3360,7 +3360,11 @@ for(const t of [300,1000])setTimeout(()=>{resize();WL.key=null;},t);addEventList function rng(seed){return()=>{seed|=0;seed=seed+0x6D2B79F5|0;let t=Math.imul(seed^seed>>>15,1|seed);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};} function inPoly(x,y,pts){let ins=false;for(let i=0,j=pts.length-1;iy)!==(yj>y))&&(x<(xj-xi)*(y-yi)/(yj-yi)+xi))ins=!ins;}return ins;} function smoothPath(pts){const p=new Path2D();const n=pts.length;const mid=(a,b)=>[(a[0]+b[0])/2,(a[1]+b[1])/2];let m=mid(pts[n-1],pts[0]);p.moveTo(m[0],m[1]);for(let i=0;i{let a=0;for(let i=0,j=p.length-1;iringArea(p)>=600||CITIES.some(c=>inPoly(c.x,c.y,p))?LANDP_ALL[i]:null).filter(Boolean); const ALLPOLY=COAST; const onLand=(x,y)=>ALLPOLY.some(p=>inPoly(x,y,p)); const R1=rng(7),WAVES=[],HILLS=[]; @@ -3520,7 +3524,7 @@ function draw(now){ } function drawCone(x,y,now){const b=Math.sin(now/300)*1.5;ctx.save();ctx.translate(x,y-12+b);ctx.strokeStyle='#1E2640';ctx.lineWidth=2;ctx.fillStyle='#FF8A3D';ctx.beginPath();ctx.moveTo(-7,9);ctx.lineTo(0,-10);ctx.lineTo(7,9);ctx.closePath();ctx.fill();ctx.stroke();ctx.fillStyle='#fff';ctx.fillRect(-4,-1,8,3);ctx.fillStyle='#1E2640';rr(-10,8,20,4,2);ctx.fill();ctx.restore();} // Static land + cable map, rendered once per zoom bucket into an offscreen canvas. -function paintWorld(c,z,withCables){ +function paintWorld(c,z,withCables){const LANDP=lodFar()?LANDP_FAR:LANDP_ALL; for(const o of [0,W,-W]){c.save();c.translate(o+5/z,7/z);c.fillStyle='rgba(20,90,130,.35)';for(const p of LANDP)c.fill(p);c.restore();} c.strokeStyle='#F8E6A8';c.lineWidth=10/z;c.lineJoin='round';for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.stroke(p);c.restore();} c.fillStyle='#9BDA6C';for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.fill(p);c.restore();} diff --git a/tests/regions.test.js b/tests/regions.test.js index 7249205..655017f 100644 --- a/tests/regions.test.js +++ b/tests/regions.test.js @@ -377,3 +377,12 @@ test('more UK and Norway: Manchester, Edinburgh, Bude and Stavanger with North S assert.ok(ev("['btt','sky','vmo'].every(n=>NET[n].pops.includes('man'))")); assert.deepEqual(errors, []); }); + +test('#41 real coastlines: every city is on land, and the far view drops tiny islands but keeps every city', () => { + const { ev, errors } = load(); + assert.deepEqual(JSON.parse(ev('JSON.stringify(CITIES.filter(c=>!onLand(c.x,c.y)).map(c=>c.id))')), [], 'no city in the sea'); + assert.ok(ev('LANDP_FAR.length') < ev('LANDP_ALL.length'), 'the far view is simpler'); + assert.equal(ev('CITIES.every(c=>COAST.some((p,i)=>inPoly(c.x,c.y,p)&&LANDP_FAR.includes(LANDP_ALL[i])))'), true, 'no city loses its island when zoomed out'); + ev('ACT.start({});cam.z=0.5;draw(0);cam.z=2;draw(0)'); + assert.deepEqual(errors, []); +});