import { describe, it, expect } from 'vitest'; import { computeBoundingBox, boundingBoxRing } from '$domain'; import type { LatLngTuple } from '$domain'; describe('computeBoundingBox', () => { it('returns null for an empty path', () => { expect(computeBoundingBox([])).toBeNull(); }); it('wraps the extremes and expands by the margin', () => { const path: LatLngTuple[] = [ [62.0, 129.0], [62.5, 130.0] ]; const box = computeBoundingBox(path, 0)!; expect(box.south).toBeCloseTo(62.0, 6); expect(box.north).toBeCloseTo(62.5, 6); expect(box.west).toBeCloseTo(129.0, 6); expect(box.east).toBeCloseTo(130.0, 6); const padded = computeBoundingBox(path, 5)!; expect(padded.south).toBeLessThan(62.0); expect(padded.north).toBeGreaterThan(62.5); expect(padded.west).toBeLessThan(129.0); expect(padded.east).toBeGreaterThan(130.0); }); }); describe('boundingBoxRing', () => { it('is a closed ring of 5 corners (SW repeated)', () => { const ring = boundingBoxRing({ south: 1, west: 2, north: 3, east: 4 }); expect(ring).toHaveLength(5); expect(ring[0]).toEqual(ring[4]); }); });