aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/vec.js5
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 );