Reduce code complexity

This commit is contained in:
Christian Paul 2022-05-01 14:54:18 +02:00
parent 59d1934a34
commit b0d19f529f
5 changed files with 11 additions and 20 deletions

View File

@ -113,9 +113,8 @@ export default class BrailleBuffer {
}
//TODO Optimize this part
var i, k;
const results = [];
for (i = k = 1; k <= 255; i = ++k) {
for (let i = 1; i <= 255; i++) {
const braille = (i & 7) + ((i & 56) << 1) + ((i & 64) >> 3) + (i & 128);
results.push(this.asciiToBraille[i] = masks.reduce((function(best, mask) {
const covered = utils.population(mask.mask & braille);

View File

@ -163,9 +163,8 @@ export default class Canvas {
const b = this._bresenham(pointA, pointC);
const c = this._bresenham(pointA, pointB);
const points = a.concat(b).concat(c).filter((point) => {
var ref;
return (0 <= (ref = point.y) && ref < this.height);
const points = a.concat(b).concat(c).filter(({y}) => {
return 0 <= y && y < this.height;
}).sort(function(a, b) {
if (a.y === b.y) {
return a.x - b.x;

View File

@ -13,7 +13,6 @@ export default class Styler {
constructor(style) {
this.styleById = {};
this.styleByLayer = {};
var base, name;
this.styleName = style.name;
if (style.constants) {
this._replaceConstants(style.constants, style.layers);
@ -30,10 +29,7 @@ export default class Styler {
layer.appliesTo = this._compileFilter(layer.filter);
//TODO Better translation of: @styleByLayer[style['source-layer']] ?= []
if ((base = this.styleByLayer)[name = layer['source-layer']] == null) {
base[name] = [];
}
this.styleByLayer[layer['source-layer']] ??= [];
this.styleByLayer[layer['source-layer']].push(layer);
this.styleById[layer.id] = layer;
}

View File

@ -18,14 +18,10 @@ export default class Tile {
this.styler = styler;
}
load(buffer) {
return this._unzipIfNeeded(buffer).then((buffer) => {
return this._loadTile(buffer);
}).then(() => {
return this._loadLayers();
}).then(() => {
return this;
});
async load(buffer) {
const unzippedBuffer = await this._unzipIfNeeded(buffer);
await this._loadTile(unzippedBuffer);
await this._loadLayers();
}
_loadTile(buffer) {

View File

@ -133,12 +133,13 @@ export default class TileSource {
});
}
_createTile(z, x, y, buffer) {
async _createTile(z, x, y, buffer) {
const name = [z, x, y].join('-');
this.cached.push(name);
const tile = this.cache[name] = new Tile(this.styler);
return tile.load(buffer);
await tile.load(buffer);
return tile;
}
_initPersistence() {