Files
Paradise/tgui/packages/common/vector.js
AffectedArc07 58aa86cb9f TGUI-V3 (#13310)
* I need that gitignore file

* Temp Commit - DOES NOT COMPILE

* THE SHIT WORKS

* Readme change

* Disposal Unit --> TGUI

* mmmm yes CI which may not actually work

* New GitIgnore

* ITS TGUI-NEXT BABY

* Doc update

* CI tweak

* Chmod

* And again

* *sigh*

* Lets appreciate the irony of me failing CI stages

* 0/1 --> True/False

* Fixes some update nonsense

* CI Update

* Lets try this

* What about this maybe

* NVM is hurting me

* I swear to god

* A little bit of validation in my life

* V3 BABYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

* Fixes

* Fixes NaN appearing for a few frames when UIs open

* Fixes + Crew Monitor

* Corn + Steel + Mochi Fixes

* Forgot this

* Fixes from stylemistake

* Code Change

* Adds logout proc

* Offline implications + Resizeable crew monitor

* Change locate() to locateUID()

* Change div --> box
2020-06-30 03:51:36 -04:00

49 lines
1.1 KiB
JavaScript

import { map, reduce, zipWith } from './collections';
/**
* Creates a vector, with as many dimensions are there are arguments.
*/
export const vecCreate = (...components) => {
if (Array.isArray(components[0])) {
return [...components[0]];
}
return components;
};
const ADD = (a, b) => a + b;
const SUB = (a, b) => a - b;
const MUL = (a, b) => a * b;
const DIV = (a, b) => a / b;
export const vecAdd = (...vecs) => {
return reduce((a, b) => zipWith(ADD)(a, b))(vecs);
};
export const vecSubtract = (...vecs) => {
return reduce((a, b) => zipWith(SUB)(a, b))(vecs);
};
export const vecMultiply = (...vecs) => {
return reduce((a, b) => zipWith(MUL)(a, b))(vecs);
};
export const vecDivide = (...vecs) => {
return reduce((a, b) => zipWith(DIV)(a, b))(vecs);
};
export const vecScale = (vec, n) => {
return map(x => x * n)(vec);
};
export const vecInverse = vec => {
return map(x => -x)(vec);
};
export const vecLength = vec => {
return Math.sqrt(reduce(ADD)(zipWith(MUL)(vec, vec)));
};
export const vecNormalize = vec => {
return vecDivide(vec, vecLength(vec));
};