Skip to content

Commit

Permalink
Make symbolInstance lookups per SymbolBucket sort linear in number of…
Browse files Browse the repository at this point in the history
… symbols.
  • Loading branch information
ChrisLoer committed Aug 22, 2018
1 parent aef24c1 commit 180669e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,17 @@ class SymbolBucket implements Bucket {
const sin = Math.sin(angle),
cos = Math.cos(angle);

const rotatedYs = [];
const featureIndexes = [];
for (let i = 0; i < this.symbolInstances.length; i++) {
const symbolInstance = this.symbolInstances.get(i);
rotatedYs.push(Math.round(sin * symbolInstance.anchorX + cos * symbolInstance.anchorY) | 0);
featureIndexes.push(symbolInstance.featureIndex);
}

symbolInstanceIndexes.sort((aIndex, bIndex) => {
const a = this.symbolInstances.get(aIndex);
const b = this.symbolInstances.get(bIndex);
const aRotated = Math.round(sin * a.anchorX + cos * a.anchorY) | 0;
const bRotated = Math.round(sin * b.anchorX + cos * b.anchorY) | 0;
return (aRotated - bRotated) || (b.featureIndex - a.featureIndex);
return (rotatedYs[aIndex] - rotatedYs[bIndex]) ||
(featureIndexes[bIndex] - featureIndexes[aIndex]);
});

this.text.indexArray.clear();
Expand Down

0 comments on commit 180669e

Please sign in to comment.