import test from 'node:test'; import assert from 'node:assert/strict'; import { inside, visible, nearestInside, concaveVertices, findPath } from '../src/engine/geometry.js'; // Una "L": il passaggio dall'alto a destra deve girare attorno all'angolo interno (100,100). const L = [[0, 0], [100, 0], [100, 100], [300, 100], [300, 200], [0, 200]]; test('punto dentro, fuori e sul bordo', () => { assert.ok(inside(L, [50, 50])); assert.ok(!inside(L, [200, 50])); assert.ok(inside(L, [100, 50])); }); test('la visibilità non attraversa i muri', () => { assert.ok(visible(L, [50, 50], [50, 150])); assert.ok(!visible(L, [50, 50], [250, 150])); }); test('un clic fuori finisce sul bordo più vicino', () => { assert.deepEqual(nearestInside(L, [200, 50]), [200, 100]); assert.deepEqual(nearestInside(L, [50, -20]), [50, 0]); }); test('solo l\'angolo interno è concavo', () => { assert.deepEqual(concaveVertices(L), [[100, 100]]); assert.deepEqual(concaveVertices([...L].reverse()), [[100, 100]]); }); test('il percorso gira attorno all\'angolo', () => { assert.deepEqual(findPath(L, [50, 50], [250, 150]), [[100, 100], [250, 150]]); assert.deepEqual(findPath(L, [10, 10], [90, 190]), [[90, 190]]); }); test('una destinazione fuori dall\'area viene avvicinata', () => { const path = findPath(L, [50, 50], [250, 20]); assert.deepEqual(path.at(-1), [250, 100]); for (let i = 1; i < path.length; i++) assert.ok(visible(L, path[i - 1], path[i])); });