From b34f7b763e9c2884e3f9e51b4a1f6ae2f0cdad24 Mon Sep 17 00:00:00 2001 From: Alex Ilchenko Date: Wed, 6 Mar 2024 16:34:21 +0100 Subject: [PATCH] feat(engine): added getMultipliedVector function --- .../get-multiplied-vector.ts | 19 +++++++++++++++++++ .../utils/get-multiplied-vector/index.ts | 1 + 2 files changed, 20 insertions(+) create mode 100644 src/features/engine/utils/get-multiplied-vector/get-multiplied-vector.ts create mode 100644 src/features/engine/utils/get-multiplied-vector/index.ts diff --git a/src/features/engine/utils/get-multiplied-vector/get-multiplied-vector.ts b/src/features/engine/utils/get-multiplied-vector/get-multiplied-vector.ts new file mode 100644 index 0000000..bee7bad --- /dev/null +++ b/src/features/engine/utils/get-multiplied-vector/get-multiplied-vector.ts @@ -0,0 +1,19 @@ +import { Vector } from '../../types/entities'; + +export const getMultipliedVector = ({ + multiplier, + vector, +}: { + vector: Vector; + multiplier: number; +}): Vector => { + const result = { + x: vector.x * multiplier, + y: vector.y * multiplier, + }; + + return { + x: Object.is(result.x, -0) ? 0 : result.x, + y: Object.is(result.y, -0) ? 0 : result.y, + }; +}; diff --git a/src/features/engine/utils/get-multiplied-vector/index.ts b/src/features/engine/utils/get-multiplied-vector/index.ts new file mode 100644 index 0000000..e9b531f --- /dev/null +++ b/src/features/engine/utils/get-multiplied-vector/index.ts @@ -0,0 +1 @@ +export * from './get-multiplied-vector';