This commit is contained in:
Matthieu Jolimaitre 2024-04-10 00:37:18 +02:00
parent a633cb7252
commit 6bf8f60a45
5 changed files with 15 additions and 63 deletions

View file

@ -1,9 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.221.0/assert/mod.ts";
import { Awaitable, log_from, Prototyped, Vec2 } from "../common/utils.ts";
import { ClassMap } from "../common/utils.ts";
import { wait } from "../common/utils.ts";
import { Constructible } from "../common/utils.ts";
import { first } from "../common/utils.ts";
import { Awaitable, ClassMap, Constructible, first, log_from, Prototyped, wait } from "../common/utils.ts";
const log = log_from(import.meta);
export class Entity {
@ -90,37 +85,6 @@ export class Engine {
}
}
function* displacement_steps(position: Vec2, displacement: Vec2) {
let pos = position;
let left = displacement;
while (left.len() >= 1) {
if (left.x() >= 1) {
pos = pos.add(new Vec2(1, 0));
left = left.sub(new Vec2(1, 0));
}
if (left.x() <= -1) {
pos = pos.add(new Vec2(-1, 0));
left = left.sub(new Vec2(-1, 0));
}
if (left.y() >= 1) {
pos = pos.add(new Vec2(0, 1));
left = left.sub(new Vec2(0, 1));
}
if (left.y() <= -1) {
pos = pos.add(new Vec2(0, -1));
left = left.sub(new Vec2(0, -1));
}
yield pos;
}
}
Deno.test("test_displacement", () => {
assertEquals(
[...displacement_steps(new Vec2(1, 1), new Vec2(4, 6))],
[new Vec2(2, 2), new Vec2(3, 3), new Vec2(4, 4), new Vec2(5, 5), new Vec2(5, 6), new Vec2(5, 7)],
);
});
export class Query {
private test;