diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/vec.js | 26 |
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); +} |