summaryrefslogtreecommitdiff
path: root/engine/utils/normalizeVector.ts
diff options
context:
space:
mode:
Diffstat (limited to 'engine/utils/normalizeVector.ts')
-rw-r--r--engine/utils/normalizeVector.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/engine/utils/normalizeVector.ts b/engine/utils/normalizeVector.ts
new file mode 100644
index 0000000..e6dfd7f
--- /dev/null
+++ b/engine/utils/normalizeVector.ts
@@ -0,0 +1,8 @@
+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 };
+};