🚀 add test for path to pose + fix path to pose

This commit is contained in:
platane
2020-11-03 22:33:24 +01:00
parent 2d1d70a10c
commit cd458e61d3
4 changed files with 76 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
import "./menu";
import { createCanvas } from "./canvas";
import { createSnakeFromCells, snakeToCells } from "@snk/types/snake";
import { grid, snake } from "./sample";
import { getPathToPose } from "@snk/compute/getPathToPose";
const { canvas, ctx, draw, highlightCell } = createCanvas(grid);
canvas.style.pointerEvents = "auto";
const target = createSnakeFromCells(
snakeToCells(snake).map((p) => ({ ...p, x: p.x - 1 }))
);
let chain = [snake, ...getPathToPose(snake, target)!];
let i = 0;
const onChange = () => {
ctx.clearRect(0, 0, 9999, 9999);
draw(grid, chain[i], []);
chain
.map(snakeToCells)
.flat()
.forEach(({ x, y }) => highlightCell(x, y));
};
onChange();
const inputI = document.createElement("input") as any;
inputI.type = "range";
inputI.value = 0;
inputI.max = chain ? chain.length - 1 : 0;
inputI.step = 1;
inputI.min = 0;
inputI.style.width = "90%";
inputI.style.padding = "20px 0";
inputI.addEventListener("input", () => {
i = +inputI.value;
onChange();
});
document.body.append(inputI);

View File

@@ -1 +1,9 @@
["interactive", "getBestTunnel", "getBestRoute", "outside", "getPathTo", "svg"]
[
"interactive",
"getBestTunnel",
"getBestRoute",
"outside",
"getPathToPose",
"getPathTo",
"svg"
]