aboutsummaryrefslogtreecommitdiff
path: root/test-client/util.ts
blob: 994e6acfa963c4d7d4681f2c79ad9f3d32854b0a (plain)
1
2
3
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 } }