From fe164b52e7dd3468e53c8d5d4883b432cce18fbf Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 17 Jun 2024 01:06:14 +0200 Subject: basic movement --- test-client/util.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test-client/util.ts (limited to 'test-client/util.ts') diff --git a/test-client/util.ts b/test-client/util.ts new file mode 100644 index 00000000..994e6acf --- /dev/null +++ b/test-client/util.ts @@ -0,0 +1,4 @@ +export interface V2 { x: number, y: number } +export function length(p: V2): number { return Math.sqrt(p.x * p.x + p.y * p.y) } +export function normalize_mut(p: V2) { const l = length(p); if (l == 0) return; p.x /= l; p.y /= l } +export function normalize(p: V2): V2 { let l = length(p); if (l == 0) l = 1; return { x: p.x / l, y: p.y / l } } -- cgit v1.2.3-70-g09d2