Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort renderable tiles by y and x to match -native #5601

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ class SourceCache extends Evented {
* Return all tile ids ordered with z-order, and cast to numbers
*/
getIds(): Array<number> {

const compareKeyZoom = (a_, b_) => {
const a = TileCoord.fromID(a_);
const b = TileCoord.fromID(b_);
const rotatedA = (new Point(a.x, a.y)).rotate(this.transform.angle);
const rotatedB = (new Point(b.x, b.y)).rotate(this.transform.angle);
return a.z - b.z || rotatedB.y - rotatedA.y || rotatedB.x - rotatedA.x;
};

return Object.keys(this._tiles).map(Number).sort(compareKeyZoom);
}

Expand Down Expand Up @@ -714,10 +723,6 @@ function coordinateToTilePoint(tileCoord: TileCoord, sourceMaxZoom: number, coor
);
}

function compareKeyZoom(a, b) {
return (a % 32) - (b % 32);
}

function isRasterType(type) {
return type === 'raster' || type === 'image' || type === 'video';
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 25 additions & 24 deletions test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ test('SourceCache#update', (t) => {
sourceCache.update(transform);

t.deepEqual(sourceCache.getIds(), [
new TileCoord(1, 0, 0).id,
new TileCoord(1, 1, 0).id,
new TileCoord(1, 1, 1).id,
new TileCoord(1, 0, 1).id,
new TileCoord(1, 1, 1).id
new TileCoord(1, 1, 0).id,
new TileCoord(1, 0, 0).id
]);
t.end();
}
Expand Down Expand Up @@ -459,10 +459,10 @@ test('SourceCache#update', (t) => {

t.deepEqual(sourceCache.getIds(), [
new TileCoord(0, 0, 0).id,
new TileCoord(1, 0, 0).id,
new TileCoord(1, 1, 0).id,
new TileCoord(1, 1, 1).id,
new TileCoord(1, 0, 1).id,
new TileCoord(1, 1, 1).id
new TileCoord(1, 1, 0).id,
new TileCoord(1, 0, 0).id
]);
t.end();
}
Expand Down Expand Up @@ -493,10 +493,10 @@ test('SourceCache#update', (t) => {

t.deepEqual(sourceCache.getIds(), [
new TileCoord(0, 0, 0, 1).id,
new TileCoord(1, 0, 0, 1).id,
new TileCoord(1, 1, 0, 1).id,
new TileCoord(1, 1, 1, 1).id,
new TileCoord(1, 0, 1, 1).id,
new TileCoord(1, 1, 1, 1).id
new TileCoord(1, 1, 0, 1).id,
new TileCoord(1, 0, 0, 1).id
]);
t.end();
}
Expand Down Expand Up @@ -525,10 +525,10 @@ test('SourceCache#update', (t) => {
if (e.sourceDataType === 'metadata') {
sourceCache.update(transform);
t.deepEqual(sourceCache.getIds(), [
new TileCoord(2, 1, 1).id,
new TileCoord(2, 2, 1).id,
new TileCoord(2, 2, 2).id,
new TileCoord(2, 1, 2).id,
new TileCoord(2, 2, 2).id
new TileCoord(2, 2, 1).id,
new TileCoord(2, 1, 1).id
]);

transform.zoom = 0;
Expand Down Expand Up @@ -664,20 +664,20 @@ test('SourceCache#update', (t) => {
if (e.sourceDataType === 'metadata') {
sourceCache.update(transform);
t.deepEqual(sourceCache.getRenderableIds(), [
new TileCoord(16, 8191, 8191, 0).id,
new TileCoord(16, 8192, 8191, 0).id,
new TileCoord(16, 8192, 8192, 0).id,
new TileCoord(16, 8191, 8192, 0).id,
new TileCoord(16, 8192, 8192, 0).id
new TileCoord(16, 8192, 8191, 0).id,
new TileCoord(16, 8191, 8191, 0).id
]);

transform.zoom = 15;
sourceCache.update(transform);

t.deepEqual(sourceCache.getRenderableIds(), [
new TileCoord(16, 8191, 8191, 0).id,
new TileCoord(16, 8192, 8191, 0).id,
new TileCoord(16, 8192, 8192, 0).id,
new TileCoord(16, 8191, 8192, 0).id,
new TileCoord(16, 8192, 8192, 0).id
new TileCoord(16, 8192, 8191, 0).id,
new TileCoord(16, 8191, 8191, 0).id
]);
t.end();
}
Expand Down Expand Up @@ -1121,10 +1121,10 @@ test('SourceCache#tilesIn', (t) => {
sourceCache.update(transform);

t.deepEqual(sourceCache.getIds(), [
new TileCoord(1, 0, 0).id,
new TileCoord(1, 1, 0).id,
new TileCoord(1, 1, 1).id,
new TileCoord(1, 0, 1).id,
new TileCoord(1, 1, 1).id
new TileCoord(1, 1, 0).id,
new TileCoord(1, 0, 0).id
]);

const tiles = sourceCache.tilesIn([
Expand Down Expand Up @@ -1168,10 +1168,10 @@ test('SourceCache#tilesIn', (t) => {
sourceCache.update(transform);

t.deepEqual(sourceCache.getIds(), [
new TileCoord(2, 0, 0).id,
new TileCoord(2, 1, 0).id,
new TileCoord(2, 1, 1).id,
new TileCoord(2, 0, 1).id,
new TileCoord(2, 1, 1).id
new TileCoord(2, 1, 0).id,
new TileCoord(2, 0, 0).id
]);

const tiles = sourceCache.tilesIn([
Expand Down Expand Up @@ -1272,6 +1272,7 @@ test('SourceCache#getIds (ascending order by zoom level)', (t) => {
];

const sourceCache = createSourceCache({});
sourceCache.transform = new Transform();
for (let i = 0; i < ids.length; i++) {
sourceCache._tiles[ids[i].id] = {};
}
Expand Down