Map: test land polygons against their bounding box first
The sea waves, hills and the far view's islet list test points against every coastline polygon while the page loads: about 0.8 s of a throttled phone's load. A point outside a ring's box is outside the ring, so nearly every test stops there. Waves, hills and the far view's islands come out byte-identical.
This commit is contained in:
parent
94b27eadf3
commit
adc312f27b
2 changed files with 19 additions and 1 deletions
15
tests/load-time.test.js
Normal file
15
tests/load-time.test.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Work done once when a game loads (the possible-diversity map, link curves, the map's sea and hills) has shortcuts;
|
||||
// each must give exactly what the plain version gives.
|
||||
|
||||
test('land test: the bounding box shortcut agrees with walking every coastline', (t) => {
|
||||
const { ev, dom, errors } = load(); t.after(() => dom.window.close());
|
||||
const bad = ev(`(()=>{const plain=(x,y,pts)=>{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;};
|
||||
let bad=0;for(let x=0;x<W;x+=7)for(let y=0;y<H;y+=7)for(const p of COAST)if(inPoly(x,y,p)!==plain(x,y,p))bad++;for(const c of CITIES)for(const p of COAST)if(inPoly(c.x,c.y,p)!==plain(c.x,c.y,p))bad++;return bad;})()`);
|
||||
assert.equal(bad, 0);
|
||||
assert.equal(ev('WAVES.length+HILLS.length'), 350);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue