- core/: Pure TS hex engine (axial coords, hex grid, terrain types, edge connectivity with constraint solver, HexMap state model) - src/map/: Leaflet L.CRS.Simple map init, Canvas-based hex overlay layer (L.GridLayer), click/edge interaction detection - src/ui/: Sidebar with toolbar (Select/Paint/Feature modes), terrain picker, hex inspector, map settings (hex size, grid, opacity) - pipeline/: Tile pyramid generator (sharp, from source image) - tests/: 32 passing tests for coords, hex-grid, edge-connectivity - Uses Kiepenkerl tiles (symlinked) for development Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { getHexesInBounds, hexAtPixel } from '@core/hex-grid';
|
|
|
|
describe('getHexesInBounds', () => {
|
|
const size = 32;
|
|
|
|
it('returns hexes covering a small area', () => {
|
|
const hexes = getHexesInBounds(
|
|
{ minX: 0, minY: 0, maxX: 100, maxY: 100 },
|
|
size,
|
|
);
|
|
expect(hexes.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('includes origin hex when bounds contain origin', () => {
|
|
const hexes = getHexesInBounds(
|
|
{ minX: -10, minY: -10, maxX: 10, maxY: 10 },
|
|
size,
|
|
);
|
|
const hasOrigin = hexes.some(h => h.q === 0 && h.r === 0);
|
|
expect(hasOrigin).toBe(true);
|
|
});
|
|
|
|
it('more hexes for larger area', () => {
|
|
const small = getHexesInBounds(
|
|
{ minX: 0, minY: 0, maxX: 100, maxY: 100 },
|
|
size,
|
|
);
|
|
const large = getHexesInBounds(
|
|
{ minX: 0, minY: 0, maxX: 500, maxY: 500 },
|
|
size,
|
|
);
|
|
expect(large.length).toBeGreaterThan(small.length);
|
|
});
|
|
|
|
it('smaller hex size yields more hexes', () => {
|
|
const bounds = { minX: 0, minY: 0, maxX: 200, maxY: 200 };
|
|
const big = getHexesInBounds(bounds, 64);
|
|
const small = getHexesInBounds(bounds, 16);
|
|
expect(small.length).toBeGreaterThan(big.length);
|
|
});
|
|
});
|
|
|
|
describe('hexAtPixel', () => {
|
|
it('origin pixel maps to origin hex', () => {
|
|
const coord = hexAtPixel({ x: 0, y: 0 }, 32);
|
|
expect(coord.q).toBe(0);
|
|
expect(coord.r).toBe(0);
|
|
});
|
|
});
|