Faster routing and map: finished flows leave the rank loop, flows keep their exit table, lazy exit labels, off-screen links culled by box
This commit is contained in:
parent
fda5607238
commit
dd10a6c19c
4 changed files with 19 additions and 13 deletions
|
|
@ -2,7 +2,7 @@ function rng(seed){return()=>{seed|=0;seed=seed+0x6D2B79F5|0;let t=Math.imul(see
|
|||
// A point outside a ring's bounding box is outside the ring: the box is kept on the ring, so the hundreds of tests
|
||||
// at load (sea waves, hills, which islets the far view keeps) skip nearly every coastline without walking it.
|
||||
const polyBox=pts=>{let b=pts.box;if(!b){let x0=Infinity,y0=Infinity,x1=-Infinity,y1=-Infinity;for(const [x,y] of pts){if(x<x0)x0=x;if(x>x1)x1=x;if(y<y0)y0=y;if(y>y1)y1=y;}b=pts.box=[x0,y0,x1,y1];}return b;};
|
||||
function inPoly(x,y,pts){const b=polyBox(pts);if(x<b[0]||x>b[2]||y<b[1]||y>b[3])return false;let ins=false;for(let i=0,j=pts.length-1;i<pts.length;j=i++){const [xi,yi]=pts[i],[xj,yj]=pts[j];if(((yi>y)!==(yj>y))&&(x<(xj-xi)*(y-yi)/(yj-yi)+xi))ins=!ins;}return ins;}
|
||||
function inPoly(x,y,pts){const b=polyBox(pts);if(x<b[0]||x>b[2]||y<b[1]||y>b[3])return false;let ins=false;for(let i=0,j=pts.length-1;i<pts.length;j=i++){const P=pts[i],Q=pts[j],xi=P[0],yi=P[1],xj=Q[0],yj=Q[1];if(((yi>y)!==(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<n;i++){const nx=pts[(i+1)%n];m=mid(pts[i],nx);p.quadraticCurveTo(pts[i][0],pts[i][1],m[0],m[1]);}p.closePath();return p;}
|
||||
const LANDP_ALL=COAST.map(smoothPath);
|
||||
// Zoomed out, hundreds of tiny Arctic and Pacific islets, each with a thick outline, turn into noise.
|
||||
|
|
|
|||
|
|
@ -33,10 +33,12 @@ function drawFrame(now){
|
|||
const w=(vx?2.2:(2.5+Math.max(...grp.map(tierW))*1.8+(many?Math.min(1.5,(grp.length-1)*0.5):0)))*sc*(far?0.5:1),np=gm.pts.length;
|
||||
if(SX.length<np){SX=new Float64Array(np*2);SY=new Float64Array(np*2);}
|
||||
for(const k of ks){
|
||||
// Off screen (with room for the widest line and the markers at its middle): nothing of it would show. The line's
|
||||
// box is kept on its cached geometry, so a link off screen is skipped without projecting its points.
|
||||
const bb=gm.bb||(gm.bb=(()=>{let a=Infinity,b=-Infinity,c=Infinity,d=-Infinity;for(const p of gm.pts){if(p[0]<a)a=p[0];if(p[0]>b)b=p[0];if(p[1]<c)c=p[1];if(p[1]>d)d=p[1];}return [a,b,c,d];})());
|
||||
if((bb[1]+k*W-cam.x)*cam.z+CW/2<-40||(bb[0]+k*W-cam.x)*cam.z+CW/2>CW+40||(bb[3]-cam.y)*cam.z+CH/2<-40||(bb[2]-cam.y)*cam.z+CH/2>CH+40)continue;
|
||||
// Screen points as toS() gives them, kept in SX/SY.
|
||||
let mn=Infinity,mx=-Infinity,mny=Infinity,mxy=-Infinity;for(let i=0;i<np;i++){const p=gm.pts[i],x=(p[0]+k*W-cam.x)*cam.z+CW/2,y=(p[1]-cam.y)*cam.z+CH/2;SX[i]=x;SY[i]=y;if(x<mn)mn=x;if(x>mx)mx=x;if(y<mny)mny=y;if(y>mxy)mxy=y;}
|
||||
// Off screen (with room for the widest line and the markers at its middle): nothing of it would show.
|
||||
if(mx<-40||mn>CW+40||mxy<-40||mny>CH+40)continue;
|
||||
for(let i=0;i<np;i++){const p=gm.pts[i];SX[i]=(p[0]+k*W-cam.x)*cam.z+CW/2;SY[i]=(p[1]-cam.y)*cam.z+CH/2;}
|
||||
const path=()=>{ctx.beginPath();ctx.moveTo(SX[0],SY[0]);for(let i=1;i<np;i++)ctx.lineTo(SX[i],SY[i]);};
|
||||
ctx.lineCap='round';ctx.lineJoin='round';
|
||||
if(sel){ctx.strokeStyle='rgba(255,79,154,.35)';ctx.lineWidth=w+14;path();ctx.stroke();}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue