diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-02-13 01:37:24 +0000 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-02-13 01:37:24 +0000 |
commit | 2e5bd9ce80a6190d307daf2d59767e1e729e00d8 (patch) | |
tree | f266e31c85434d4f653fcbb2bc0610bf43c07596 | |
parent | 4fde8d201b089587aef027627cc5490a3671a884 (diff) | |
parent | 3f124e1abb0979f460c79d95041f1eb23c3b74e8 (diff) |
Merge branch 'master' of https://git.hrhr.dev/ywot-clean
-rw-r--r-- | utils/raster.js | 2 | ||||
-rw-r--r-- | utils/vec.js | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/utils/raster.js b/utils/raster.js index 44f4678..1e17838 100644 --- a/utils/raster.js +++ b/utils/raster.js @@ -6,7 +6,7 @@ const vec = require('./vec'); module.exports = function(space){ // just use .subsection let tiles = {}; - dim = ms(space).map(coord => vec.dot(coord,[1/8, 1/16])).map(tile => vec.elem(tile, [], a => Math.floor(a))); + dim = ms(space).map(coord => vec.charToTile(coord)); for (let y=dim[0][0]; y<=dim[0][1]; y++) for (let x=dim[1][0]; x<=dim[1][1]; x++){ let tile = tileToChar([y,x]); tiles[tile] = space.subsection(tile, vec.add(tile, [8,16])); diff --git a/utils/vec.js b/utils/vec.js index d595989..57104df 100644 --- a/utils/vec.js +++ b/utils/vec.js @@ -33,6 +33,9 @@ exports.dot = function(orig,vec){ 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)); +} exports.norm = function(orig){ let sum = orig.reduce( (acc, cur) => acc+cur ); return exports.dot(orig, 1/sum); |