refactor: map gen?
This commit is contained in:
@@ -213,6 +213,80 @@ describe('generatePointCrawlMap', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should not have crossing edges in wild→settlement transitions', () => {
|
||||
const map = generatePointCrawlMap(12345);
|
||||
const wildToSettlementTransitions = [
|
||||
{ src: 2, tgt: 3 },
|
||||
{ src: 5, tgt: 6 },
|
||||
];
|
||||
|
||||
for (const transition of wildToSettlementTransitions) {
|
||||
const srcLayer = map.layers[transition.src];
|
||||
const tgtLayer = map.layers[transition.tgt];
|
||||
|
||||
// Collect edges as pairs of indices
|
||||
const edges: Array<{ srcIndex: number; tgtIndex: number }> = [];
|
||||
for (let s = 0; s < srcLayer.nodeIds.length; s++) {
|
||||
const srcNode = map.nodes.get(srcLayer.nodeIds[s]);
|
||||
for (const tgtId of srcNode!.childIds) {
|
||||
const t = tgtLayer.nodeIds.indexOf(tgtId);
|
||||
edges.push({ srcIndex: s, tgtIndex: t });
|
||||
}
|
||||
}
|
||||
|
||||
// Check for crossings
|
||||
for (let e1 = 0; e1 < edges.length; e1++) {
|
||||
for (let e2 = e1 + 1; e2 < edges.length; e2++) {
|
||||
const { srcIndex: s1, tgtIndex: t1 } = edges[e1];
|
||||
const { srcIndex: s2, tgtIndex: t2 } = edges[e2];
|
||||
|
||||
if (s1 === s2) continue;
|
||||
if (t1 === t2) continue;
|
||||
|
||||
const crosses = (s1 < s2 && t1 > t2) || (s1 > s2 && t1 < t2);
|
||||
expect(crosses).toBe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should not have crossing edges in settlement→wild transitions', () => {
|
||||
const map = generatePointCrawlMap(12345);
|
||||
const settlementToWildTransitions = [
|
||||
{ src: 3, tgt: 4 },
|
||||
{ src: 6, tgt: 7 },
|
||||
];
|
||||
|
||||
for (const transition of settlementToWildTransitions) {
|
||||
const srcLayer = map.layers[transition.src];
|
||||
const tgtLayer = map.layers[transition.tgt];
|
||||
|
||||
// Collect edges as pairs of indices
|
||||
const edges: Array<{ srcIndex: number; tgtIndex: number }> = [];
|
||||
for (let s = 0; s < srcLayer.nodeIds.length; s++) {
|
||||
const srcNode = map.nodes.get(srcLayer.nodeIds[s]);
|
||||
for (const tgtId of srcNode!.childIds) {
|
||||
const t = tgtLayer.nodeIds.indexOf(tgtId);
|
||||
edges.push({ srcIndex: s, tgtIndex: t });
|
||||
}
|
||||
}
|
||||
|
||||
// Check for crossings
|
||||
for (let e1 = 0; e1 < edges.length; e1++) {
|
||||
for (let e2 = e1 + 1; e2 < edges.length; e2++) {
|
||||
const { srcIndex: s1, tgtIndex: t1 } = edges[e1];
|
||||
const { srcIndex: s2, tgtIndex: t2 } = edges[e2];
|
||||
|
||||
if (s1 === s2) continue;
|
||||
if (t1 === t2) continue;
|
||||
|
||||
const crosses = (s1 < s2 && t1 > t2) || (s1 > s2 && t1 < t2);
|
||||
expect(crosses).toBe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should assign encounters to nodes', () => {
|
||||
const map = generatePointCrawlMap(456);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user