Files
sunrise/tests/harbour.test.ts

28 lines
1.3 KiB
TypeScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {Raycaster,Vector3} from 'three';
import {createHarbour,insideHarbour,isGisamun} from '../src/scene/harbour.ts';
import {GISAMUN_HARBOUR as PORT} from '../src/constants/harbour.ts';
import {GISAMUN} from '../src/constants/gisamun.ts';
test('Gisamun harbour keeps its basin and entrance open with solid raised quays',()=>{
const port=createHarbour(.1375735);
port.group.updateMatrixWorld(true);
for(const [x,z] of [[-80,-250],[70,-155],[140,-150]]) {
assert.equal(insideHarbour(PORT.land,x,z),false,'water must not become pavement');
assert.equal(new Raycaster(new Vector3(x,100,z),new Vector3(0,-1,0)).intersectObject(port.group,true).length,0);
}
assert.equal(insideHarbour(PORT.basin,-80,-250),true);
assert.equal(insideHarbour(PORT.basin,140,-150),false);
for(const [x,z] of [[-150,-280],[20,-155],[100,-165],[-25,-350]]) {
const y=port.heightAt(x,z);
assert.ok(y!==undefined && y>2.8);
const hit=new Raycaster(new Vector3(x,100,z),new Vector3(0,-1,0)).intersectObject(port.group,true)[0];
assert.ok(hit,'quay roof must face upward');
assert.ok(Math.abs(hit.point.y-y)<.01,'walking height matches the roof');
}
assert.equal(isGisamun(GISAMUN),true);
assert.equal(isGisamun({latitude:38.0231,longitude:128.7254}),false);
port.dispose();
});