aboutsummaryrefslogtreecommitdiff
path: root/utils/vec.js
blob: f4a625c79eb7324f06837eaf635c658bfc71bdd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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);
}
exports.tileToChar = function(orig){
  return exports.dot(orig, [8,16]);
}