From deb42c7d82675b04159a8c5032ff7fea96db5c6a Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Thu, 16 Jul 2020 13:14:33 -0400
Subject: vec.elem prevents NaN calc and charToTile uses .map
It used to return [], which caused some major calculation issues in
tools/search
---
utils/vec.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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 );
--
cgit