32 lines
3.4 KiB
JavaScript

const assert=require('node:assert/strict');
const E=require('../../PlotLine/wwwroot/js/maps-engine.js');
const a=E.makeFeature('Town',0,0,'a'),b=E.makeFeature('Town',10,10,'b'),c=E.makeFeature('Village',30,0,'c');
const rel=[{relationshipID:'r1',sourceID:'b',targetID:'a',direction:'NW',relativeDistance:'Far',measuredDistance:126},{relationshipID:'r2',sourceID:'c',targetID:'b',direction:'E',relativeDistance:'Very close',measuredDistance:2}];
const first=E.arrange([a,b,c],rel),second=E.arrange([a,b,c],rel);
assert.deepEqual(first,second,'arrangement deterministic');
assert.equal(E.suggestedDirection(first.features[1],first.features[0]),'NW');
assert.equal(E.suggestedDirection(first.features[2],first.features[1]),'E');
assert.deepEqual(first,E.arrange([a,b,c],rel.map(r=>({...r,measuredDistance:999999999}))), 'physical distance never drives canvas spacing');
assert.equal(a.x,0,'preview never mutates author data');
a.x=.123456;a.y=-.987654;b.isPlaced=false;const partial=E.arrange([a,b,c],rel,true);assert.equal(partial.features[0].x,a.x);assert.equal(partial.features[2].x,c.x);
b.x=10.123456;b.isLocked=true;assert.equal(E.arrange([a,b],rel).features[1].x,b.x,'locked positions retain full precision');b.isLocked=false;
const conflicts=E.arrange([a,b],[{relationshipID:'1',sourceID:'a',targetID:'b',direction:'N'},{relationshipID:'2',sourceID:'b',targetID:'a',direction:'N'}]);assert(conflicts.warnings.length,'contradictions are observations');
const route=E.makeFeature('Road',0,0,'road');route.startFeatureID='a';route.endFeatureID='b';a.x=150;a.y=0;b.x=700;
const points=E.pathPoints(route,[a,b]);assert.deepEqual(points[0],[150,0]);assert.deepEqual(points.at(-1),[700,10]);
const island=E.makeFeature('Island',0,0,'island');assert.equal(E.curve(E.coastline(island),true),E.curve(E.coastline(island),true));
assert(E.library.length>70);assert(E.library.some(x=>x.type==='Forest'&&x.geometryClass==='Area'));assert(E.library.some(x=>x.type==='River'&&x.geometryClass==='Path'));
console.log('PASS Maps arrangement determinism, bounded physical distance, graph relationships, conflicts, locks, unplaced-only, attached routes and deterministic coasts');
// A free endpoint transforms the path around its opposite end; attachments remain authoritative.
{
const path=E.makeFeature('Road',40,50,'endpoint-test'),before=E.pathPoints(path,[]),target=[before[0][0]+80,before[0][1]+100];
const next=E.transformEndpoint(path,0,target,[]),after=E.pathPoints(next,[]);
const near=(a,b)=>assert(Math.hypot(a[0]-b[0],a[1]-b[1])<1e-8);
near(after[0],target);near(after.at(-1),before.at(-1));assert.notEqual(next.rotation,path.rotation);
const place=E.makeFeature('Town',250,300,'anchor');path.endFeatureID=place.featureID;
const attached=E.transformEndpoint(path,0,target,[place]);near(E.pathPoints(attached,[place]).at(-1),[250,300]);
path.startFeatureID=place.featureID;assert.deepEqual(E.transformEndpoint(path,0,target,[place]),path);
const symbols=require('../../PlotLine/wwwroot/js/maps-symbols.js');assert.equal(symbols.types.length,75);for(const asset of E.library)assert(symbols.content(asset.type),'Every map piece has a semantic SVG pictogram: '+asset.type);
assert.equal(new Set(E.library.map(a=>symbols.content(a.type))).size,75,'All palette symbols have distinct semantic treatments');
console.log('PASS Maps endpoint similarity transforms, authoritative attachments and complete distinct 75-piece SVG symbol library');
}