diff options
Diffstat (limited to 'test-client/util.ts')
-rw-r--r-- | test-client/util.ts | 4 |
1 files changed, 4 insertions, 0 deletions
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 } } |