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 } }