diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-07-16 13:14:33 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-07-16 13:14:33 -0400 |
commit | deb42c7d82675b04159a8c5032ff7fea96db5c6a (patch) | |
tree | 83795b3d880b6a12e14d5d5cd7bead8902f32769 | |
parent | 5cc071b82b8916a9c6fc213599a3714612b5cfcb (diff) |
vec.elem prevents NaN calc and charToTile uses .map
It used to return [], which caused some major calculation issues in
tools/search
-rw-r--r-- | utils/vec.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/utils/vec.js b/utils/vec.js index 57104df..4e65abd 100644 --- a/utils/vec.js +++ b/utils/vec.js @@ -7,6 +7,9 @@ exports.mult = function(vec, scal){ } exports.elem = function(orig, vec, op){ + if (orig.length > vec.length) throw "Vector length mismatch"; + if (orig.length && isNaN(orig[0])) throw "orig vec has a NaN"; + if (vec.length && isNaN(vec[0])) throw "new vec has a NaN"; let comb = []; for (let i = 0; i < orig.length; i++){ comb.push(op(vec[i],orig[i])); @@ -34,7 +37,7 @@ exports.tileToChar = function(orig){ return exports.dot(orig, [8,16]); } exports.charToTile = function(orig){ - return exports.elem(exports.dot(orig, [1/8, 1/16]), [], a => Math.floor(a)); + return exports.dot(orig, [1/8, 1/16]).map(a => Math.floor(a)); } exports.norm = function(orig){ let sum = orig.reduce( (acc, cur) => acc+cur ); |