navmesh
Version:
A library for fast pathfinding using navigation meshes in JS
56 lines (50 loc) • 1.65 kB
text/typescript
import buildPolysFromGridMap from "./build-polys-from-grid-map";
describe("buildPolysFromGridMap", () => {
it("should return an empty array when passed in no walkable tiles", () => {
const polys = buildPolysFromGridMap([
[],
[],
[],
]);
expect(polys).toEqual([]);
});
it("should return one polygon for a grid of all walkable tiles", () => {
const polys = buildPolysFromGridMap([
[],
[],
[],
]);
expect(polys.length).toBe(1);
});
it("should return two polygons for a grid of two simple rectangular islands", () => {
const polys = buildPolysFromGridMap([
[],
[],
[],
[],
[],
]);
expect(polys.length).toBe(2);
});
it("should return 15 polygons for a grid with 15 1x1 islands", () => {
const polys = buildPolysFromGridMap([
[],
[],
[],
]);
expect(polys.length).toBe(15);
});
it("should return scale polygons based on given tile width and height", () => {
const tileWidth = 20;
const tileHeight = 40;
const grid = [
[],
[],
];
const polys = buildPolysFromGridMap(grid, tileWidth, tileHeight);
const topLeft = { x: 0, y: 0 };
const bottomRight = { x: tileWidth * 2, y: tileHeight * 2 };
expect(polys[0]).toContainEqual(topLeft);
expect(polys[0]).toContainEqual(bottomRight);
});
});