time for a snapshot

This commit is contained in:
Schluffe
2026-07-11 17:48:28 +02:00
parent 135b7c3042
commit 7262752e16
47 changed files with 1712 additions and 61 deletions
+23
View File
@@ -0,0 +1,23 @@
import type { Vec } from "./given.ts";
/** The length (magnitude) of the arrow. */
export function length(a: Vec): number {
return Math.sqrt(a.x * a.x + a.y * a.y);
}
/**
* A unit-length vector pointing the same way as `a`.
* MUST return (0, 0) when `a` is the zero vector — do not divide by zero.
*/
export function normalize(a: Vec): Vec {
const len = length(a);
const x = a.x === 0 ? 0 : a.x / len;
const y = a.y === 0 ? 0 : a.y / len;
return { x, y };
}
/** The dot product a·b. */
export function dot(a: Vec, b: Vec): number {
return a.x * b.x + a.y * b.y;
}