diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-02 16:04:13 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-02 16:04:13 -0600 |
commit | 5a55b5fa0c678ff03842d2adec8543e754546718 (patch) | |
tree | 4f615829acc10045d81a9d553c757a14792bf81a /src/utils/unitizeVector.js | |
parent | 4d34b0b4b890e957030fbf6e3c8e1d4a02d2a627 (diff) | |
download | bbiy-5a55b5fa0c678ff03842d2adec8543e754546718.tar.gz bbiy-5a55b5fa0c678ff03842d2adec8543e754546718.zip |
Grid system & simple physics
Diffstat (limited to 'src/utils/unitizeVector.js')
-rw-r--r-- | src/utils/unitizeVector.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/unitizeVector.js b/src/utils/unitizeVector.js new file mode 100644 index 0000000..6297ca8 --- /dev/null +++ b/src/utils/unitizeVector.js @@ -0,0 +1,11 @@ +const unitize = (vector) => { + // Not *technically* a unit vector, but has x,y components of |magnitude| = 1 + Object.keys(vector).forEach((key) => { + if (typeof vector[key] === 'object') { + vector[key] = vector[key].unitize(); + } else if (typeof vector[key] === 'number') { + vector[key] = (vector[key] === 0 ? 0 : vector[key] / Math.abs(vector[key])); + } + }); + return vector; +}
\ No newline at end of file |