jumpstorm/client/lib/utils/normalizeVector.ts

9 lines
227 B
TypeScript
Raw Normal View History

2023-07-19 23:38:24 -04:00
import type { Coord2D } from "../interfaces";
export const normalizeVector = (vector: Coord2D): Coord2D => {
const { x, y } = vector;
const length = Math.sqrt(x * x + y * y);
return { x: x / length, y: y / length };
};