From 45c6cf36f7ac6fb6c5efcce730a28fecf46b0c44 Mon Sep 17 00:00:00 2001 From: Brendan Kennedy Date: Thu, 17 Oct 2019 17:00:43 -0400 Subject: [PATCH 1/4] Ensure tiles have overlap applied --- lib/output.js | 2 +- package.json | 3 ++- test/unit/tile.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/output.js b/lib/output.js index 0e72d445a..09c3b5202 100644 --- a/lib/output.js +++ b/lib/output.js @@ -575,7 +575,7 @@ function tile (options) { if (options.overlap > this.options.tileSize) { throw is.invalidParameterError('overlap', `<= size (${this.options.tileSize})`, options.overlap); } - this.options.tileOverlap = tile.overlap; + this.options.tileOverlap = options.overlap; } else { throw is.invalidParameterError('overlap', 'integer between 0 and 8192', options.overlap); } diff --git a/package.json b/package.json index a01a73f6d..335727644 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ "Jordan Prudhomme ", "Ilya Ovdin ", "Andargor ", - "Paul Neave " + "Paul Neave ", + "Brendan Kennedy " ], "scripts": { "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)", diff --git a/test/unit/tile.js b/test/unit/tile.js index a3aad2d78..7868aea80 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -91,6 +91,40 @@ const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels, }); }; +// Verifies all square tiles in a given output directory are > size with overlap +const assertTileOverlap = function (directory, tileSize) { + // Get levels + const levels = fs.readdirSync(directory); + // Get tiles + const tiles = []; + levels.forEach(function (level) { + // Verify level directory name + assert.strictEqual(true, /^[0-9]+$/.test(level)); + fs.readdirSync(path.join(directory, level)).forEach(function (tile) { + // Verify tile file name + assert.strictEqual(true, /^[0-9]+_[0-9]+\.jpeg$/.test(tile)); + tiles.push(path.join(directory, level, tile)); + }); + }); + + eachLimit(tiles, 8, function (tile, done) { + sharp(tile).metadata(function (err, metadata) { + if (err) { + done(err); + } else { + // Only checks square tiles + if (metadata.width >= tileSize && metadata.height >= tileSize) { + // Tiles with an overlap should be larger than original size + assert.strictEqual(true, metadata.width > tileSize); + assert.strictEqual(true, metadata.height > tileSize); + } + + done(); + } + }); + }); +}; + describe('Tile', function () { it('Valid size values pass', function () { [1, 8192].forEach(function (size) { @@ -297,6 +331,7 @@ describe('Tile', function () { assert.strictEqual(2225, info.height); assert.strictEqual(3, info.channels); assert.strictEqual('undefined', typeof info.size); + assertTileOverlap(directory, 512, 16); assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done); }); }); From c9c3a03a750a633102c2b8ddc6914e88ebe18db3 Mon Sep 17 00:00:00 2001 From: Brendan Kennedy Date: Fri, 18 Oct 2019 11:27:46 -0400 Subject: [PATCH 2/4] Remove spacing and unused parameter --- test/unit/tile.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/tile.js b/test/unit/tile.js index 7868aea80..bf4104970 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -118,7 +118,6 @@ const assertTileOverlap = function (directory, tileSize) { assert.strictEqual(true, metadata.width > tileSize); assert.strictEqual(true, metadata.height > tileSize); } - done(); } }); @@ -331,7 +330,7 @@ describe('Tile', function () { assert.strictEqual(2225, info.height); assert.strictEqual(3, info.channels); assert.strictEqual('undefined', typeof info.size); - assertTileOverlap(directory, 512, 16); + assertTileOverlap(directory, 512); assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done); }); }); From 1dd68ab9376817db8a249b10b26f6cd9b2c22e4b Mon Sep 17 00:00:00 2001 From: Brendan Kennedy Date: Mon, 28 Oct 2019 16:51:14 -0400 Subject: [PATCH 3/4] Reduce test complexity by only testing square tiles --- test/unit/tile.js | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/test/unit/tile.js b/test/unit/tile.js index bf4104970..9f83d265a 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -91,36 +91,25 @@ const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels, }); }; -// Verifies all square tiles in a given output directory are > size with overlap +// Verifies tiles at specified level in a given output directory are > size+overlap const assertTileOverlap = function (directory, tileSize) { - // Get levels - const levels = fs.readdirSync(directory); - // Get tiles - const tiles = []; - levels.forEach(function (level) { - // Verify level directory name - assert.strictEqual(true, /^[0-9]+$/.test(level)); - fs.readdirSync(path.join(directory, level)).forEach(function (tile) { - // Verify tile file name - assert.strictEqual(true, /^[0-9]+_[0-9]+\.jpeg$/.test(tile)); - tiles.push(path.join(directory, level, tile)); - }); - }); - - eachLimit(tiles, 8, function (tile, done) { - sharp(tile).metadata(function (err, metadata) { - if (err) { - done(err); - } else { - // Only checks square tiles - if (metadata.width >= tileSize && metadata.height >= tileSize) { - // Tiles with an overlap should be larger than original size - assert.strictEqual(true, metadata.width > tileSize); - assert.strictEqual(true, metadata.height > tileSize); - } - done(); - } - }); + // Get sorted levels + const levels = fs.readdirSync(directory).sort((a, b) => a - b); + // Select the highest tile level + const highestLevel = levels[levels.length - 1]; + // Get sorted tiles from greatest level + const tiles = fs.readdirSync(path.join(directory, highestLevel)).sort(); + // Select a tile from the approximate center of the image + const squareTile = path.join(directory, highestLevel, tiles[Math.floor(tiles.length / 2)]); + + sharp(squareTile).metadata(function (err, metadata) { + if (err) { + throw err; + } else { + // Tile with an overlap should be larger than original size + assert.strictEqual(true, metadata.width > tileSize); + assert.strictEqual(true, metadata.height > tileSize); + } }); }; From b029c297c6ad5a402afbf56d87c85c5c6e7d0b66 Mon Sep 17 00:00:00 2001 From: Brendan Kennedy Date: Wed, 30 Oct 2019 13:18:10 -0400 Subject: [PATCH 4/4] Fix tile overlap test callback --- test/unit/tile.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unit/tile.js b/test/unit/tile.js index 9f83d265a..00c24e5e6 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -92,7 +92,7 @@ const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels, }; // Verifies tiles at specified level in a given output directory are > size+overlap -const assertTileOverlap = function (directory, tileSize) { +const assertTileOverlap = function (directory, tileSize, done) { // Get sorted levels const levels = fs.readdirSync(directory).sort((a, b) => a - b); // Select the highest tile level @@ -109,6 +109,7 @@ const assertTileOverlap = function (directory, tileSize) { // Tile with an overlap should be larger than original size assert.strictEqual(true, metadata.width > tileSize); assert.strictEqual(true, metadata.height > tileSize); + done(); } }); }; @@ -319,8 +320,9 @@ describe('Tile', function () { assert.strictEqual(2225, info.height); assert.strictEqual(3, info.channels); assert.strictEqual('undefined', typeof info.size); - assertTileOverlap(directory, 512); - assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done); + assertDeepZoomTiles(directory, 512 + (2 * 16), 13, function () { + assertTileOverlap(directory, 512, done); + }); }); }); });