Skip to content

Commit

Permalink
correct tile sorting and fix rendering when mask is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Sep 15, 2017
1 parent d0085f5 commit c1efd53
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/render/tile_mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ function computeTileMasks(rootTile: TileCoord, ref: TileCoord, childArray: Array
// If the reference or any of its children is found in the list, we need to recurse.
for (let i = 0; i < childArray.length; i++) {
const childTile = childArray[i];
// childTile is from a larger wrap than the rootTile so it cannot be a child tile
if (lowerBound.isLessThan(childTile.coord)) break;
// The current tile is masked out, so we don't need to add them to the mask set.
if (ref.id === childTile.coord.id) {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ class Tile {
// using the global shared buffers for covering the entire tile.
if (util.deepEqual(mask, [0])) return;

// mask is empty because all four children are loaded
if (mask.length === 0) return;

const maskedBoundsArray = new RasterBoundsArray();
for (let i = 0; i < mask.length; i++) {
const maskCoord = TileCoord.fromID(mask[i]);
Expand Down
6 changes: 6 additions & 0 deletions src/source/tile_coord.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ class TileCoord {

isLessThan(rhs: TileCoord) {
if (this.w < rhs.w) return true;
if (this.w > rhs.w) return false;

if (this.z < rhs.z) return true;
if (this.z > rhs.z) return false;

if (this.x < rhs.x) return true;
if (this.x > rhs.x) return false;

if (this.y < rhs.y) return true;
return false;
}
Expand Down
46 changes: 46 additions & 0 deletions test/unit/source/tile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,52 @@ test('Tile#setMask', (t) => {

});

test('Tile#isLessThan', (t)=>{
t.test('correctly sorts tiles', (t)=>{
const tiles = [
new TileCoord(9, 146, 195, 0),
new TileCoord(9, 147, 195, 0),
new TileCoord(9, 148, 195, 0),
new TileCoord(9, 149, 195, 0),
new TileCoord(9, 144, 196, 1),
new TileCoord(9, 145, 196, 0),
new TileCoord(9, 146, 196, 0),
new TileCoord(9, 147, 196, 1),
new TileCoord(9, 145, 194, 0),
new TileCoord(9, 149, 196, 0),
new TileCoord(10, 293, 391, 0),
new TileCoord(10, 291, 390, 0),
new TileCoord(10, 293, 390, 1),
new TileCoord(10, 294, 390, 0),
new TileCoord(10, 295, 390, 0),
new TileCoord(10, 291, 391, 0),
];

const sortedTiles = tiles.sort((a, b) => { return a.isLessThan(b) ? -1 : b.isLessThan(a) ? 1 : 0; });

t.deepEqual(sortedTiles, [
new TileCoord(9, 145, 194, 0),
new TileCoord(9, 145, 196, 0),
new TileCoord(9, 146, 195, 0),
new TileCoord(9, 146, 196, 0),
new TileCoord(9, 147, 195, 0),
new TileCoord(9, 148, 195, 0),
new TileCoord(9, 149, 195, 0),
new TileCoord(9, 149, 196, 0),
new TileCoord(10, 291, 390, 0),
new TileCoord(10, 291, 391, 0),
new TileCoord(10, 293, 391, 0),
new TileCoord(10, 294, 390, 0),
new TileCoord(10, 295, 390, 0),
new TileCoord(9, 144, 196, 1),
new TileCoord(9, 147, 196, 1),
new TileCoord(10, 293, 390, 1)
]);
t.end();
});
t.end();
});

test('Tile#redoPlacement', (t) => {

test('redoPlacement on an empty tile', (t) => {
Expand Down

0 comments on commit c1efd53

Please sign in to comment.