aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-23 23:11:42 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-23 23:11:42 -0500
commita59b6c0cfdeb469cecb00648cf6b3c03627322b8 (patch)
treec8bed9dceb150d630ef3eddf2ede5d79e06f571e /utils
parent6c912dc1511c7eb17b2c2ff43c1023e8fb9aff78 (diff)
added vec.js
Diffstat (limited to 'utils')
-rw-r--r--utils/vec.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/utils/vec.js b/utils/vec.js
new file mode 100644
index 0000000..9808c8b
--- /dev/null
+++ b/utils/vec.js
@@ -0,0 +1,26 @@
+// A utility library for vector (coordinate) operations.
+
+exports.mult = function(vec, scal){
+ for (let i = 0; i < vec.length; i++)
+ vec[i] = scal*vec[i];
+ return vec;
+}
+
+function elem(orig, vec, op){
+ let comb = [];
+ for (let i = 0; i < orig.length; i++){
+ comb.push(op(vec[i],orig[i]));
+ }
+ return comb;
+}
+exports.elem = elem;
+
+exports.add = function(orig, vec){
+ return elem(orig, vec, (a,b) => a+b);
+}
+exports.sub = function(orig, vec){
+ return elem(orig, vec, (a,b) => a-b);
+}
+exports.dot = function(orig,vec){
+ return elem(orig, vec, (a,b) => a*b);
+}