aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2020-01-07 10:03:31 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2020-01-07 10:03:31 -0500
commitecd45c98374fd9bdef33c7a0caeecc2bab594c04 (patch)
treeeaa0dc8d3abfda0911c8096c86e2a4de54b7e24d
parent03dfd44147de472de4f06c3a0ae9f40471e7352a (diff)
vec.equals comparator
-rw-r--r--examples/jarvis.js6
-rw-r--r--utils/vec.js16
2 files changed, 12 insertions, 10 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 49c425a..2294d7a 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -12,17 +12,13 @@ const ri = require('../utils/rectintersect');
var main = new Socket();
-function equals(arg1,arg2){ // Just takes the specific case argument of each being an int pair
- return arg1[0] == arg2[0] && arg1[1] == arg2[1]
-}
-
main.on('open', ()=>{ // Tries to identify itself with a cursor movement
console.log('socket opened');
let coords = [Math.floor(Math.random()*100000+16),Math.floor(Math.random()*100000+16)];
main.cursor(coords);
main.on('cursor',detect);
function detect(pos, send){
- if (equals(pos[0],coords)){
+ if (vec.equals(pos[0],coords)){
main.off('cursor', detect);
identity(send);
}
diff --git a/utils/vec.js b/utils/vec.js
index 3996fc2..d595989 100644
--- a/utils/vec.js
+++ b/utils/vec.js
@@ -6,23 +6,29 @@ exports.mult = function(vec, scal){
return vec;
}
-function elem(orig, vec, op){
+exports.elem = function(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.equals = function(orig, vec){
+ for (let i = 0; i < orig.length; i++){
+ if (orig[i] != vec[i]) return false;
+ }
+ return true;
+}
exports.add = function(orig, vec){
- return elem(orig, vec, (a,b) => a+b);
+ return exports.elem(orig, vec, (a,b) => a+b);
}
exports.sub = function(orig, vec){
- return elem(orig, vec, (a,b) => a-b);
+ return exports.elem(orig, vec, (a,b) => a-b);
}
exports.dot = function(orig,vec){
- return elem(orig, vec, (a,b) => a*b);
+ return exports.elem(orig, vec, (a,b) => a*b);
}
exports.tileToChar = function(orig){
return exports.dot(orig, [8,16]);