diff --git a/test/node/ol/array.test.js b/test/node/ol/array.test.js index 12bcc24bb4..fe5db08b19 100644 --- a/test/node/ol/array.test.js +++ b/test/node/ol/array.test.js @@ -475,34 +475,94 @@ describe('ol/array.js', function () { expect(linearFindNearest(arr, 1000, 1)).to.eql(0); expect(linearFindNearest(arr, 1000, -1)).to.eql(0); + expect(linearFindNearest(arr, 999, -1)).to.eql(1); + + expect( + linearFindNearest(arr, 901, function (value, high, low) { + return value - (low + (high - low) * 0.8); + }) + ).to.eql(0); + + expect( + linearFindNearest(arr, 900, function (value, high, low) { + return value - (low + (high - low) * 0.8); + }) + ).to.eql(1); + expect(linearFindNearest(arr, 900, 0)).to.eql(0); expect(linearFindNearest(arr, 900, 1)).to.eql(0); expect(linearFindNearest(arr, 900, -1)).to.eql(1); + expect(linearFindNearest(arr, 751, 0)).to.eql(0); + expect(linearFindNearest(arr, 750, 0)).to.eql(1); expect(linearFindNearest(arr, 750, 1)).to.eql(0); expect(linearFindNearest(arr, 750, -1)).to.eql(1); + expect( + linearFindNearest(arr, 551, function (value, high, low) { + return value - (low + (high - low) * 0.1); + }) + ).to.eql(0); + + expect( + linearFindNearest(arr, 550, function (value, high, low) { + return value - (low + (high - low) * 0.1); + }) + ).to.eql(1); + expect(linearFindNearest(arr, 550, 0)).to.eql(1); expect(linearFindNearest(arr, 550, 1)).to.eql(0); expect(linearFindNearest(arr, 550, -1)).to.eql(1); + expect(linearFindNearest(arr, 501, 1)).to.eql(0); + expect(linearFindNearest(arr, 500, 0)).to.eql(1); expect(linearFindNearest(arr, 500, 1)).to.eql(1); expect(linearFindNearest(arr, 500, -1)).to.eql(1); + expect(linearFindNearest(arr, 499, -1)).to.eql(2); + + expect( + linearFindNearest(arr, 451, function (value, high, low) { + return value - (low + (high - low) * 0.875); + }) + ).to.eql(1); + + expect( + linearFindNearest(arr, 450, function (value, high, low) { + return value - (low + (high - low) * 0.875); + }) + ).to.eql(2); + expect(linearFindNearest(arr, 450, 0)).to.eql(1); expect(linearFindNearest(arr, 450, 1)).to.eql(1); expect(linearFindNearest(arr, 450, -1)).to.eql(2); + expect(linearFindNearest(arr, 301, 0)).to.eql(1); + expect(linearFindNearest(arr, 300, 0)).to.eql(2); expect(linearFindNearest(arr, 300, 1)).to.eql(1); expect(linearFindNearest(arr, 300, -1)).to.eql(2); + expect( + linearFindNearest(arr, 201, function (value, high, low) { + return value - (low + (high - low) * 0.25); + }) + ).to.eql(1); + + expect( + linearFindNearest(arr, 200, function (value, high, low) { + return value - (low + (high - low) * 0.25); + }) + ).to.eql(2); + expect(linearFindNearest(arr, 200, 0)).to.eql(2); expect(linearFindNearest(arr, 200, 1)).to.eql(1); expect(linearFindNearest(arr, 200, -1)).to.eql(2); + expect(linearFindNearest(arr, 101, 1)).to.eql(1); + expect(linearFindNearest(arr, 100, 0)).to.eql(2); expect(linearFindNearest(arr, 100, 1)).to.eql(2); expect(linearFindNearest(arr, 100, -1)).to.eql(2); diff --git a/test/node/ol/tilegrid/TileGrid.test.js b/test/node/ol/tilegrid/TileGrid.test.js index a3cfb3c816..4f3e9d0d82 100644 --- a/test/node/ol/tilegrid/TileGrid.test.js +++ b/test/node/ol/tilegrid/TileGrid.test.js @@ -1177,6 +1177,64 @@ describe('ol/tilegrid/TileGrid.js', function () { }); }); + describe('getZForResolution (NearestDirectionFunction)', function () { + it('returns the expected z value', function () { + const tileGrid = new TileGrid({ + resolutions: resolutions, + origin: origin, + tileSize: tileSize, + }); + + expect( + tileGrid.getZForResolution(626, function (value, high, low) { + return value - (low + (high - low) * 0.25); + }) + ).to.eql(0); + + expect( + tileGrid.getZForResolution(625, function (value, high, low) { + return value - (low + (high - low) * 0.25); + }) + ).to.eql(1); + + expect( + tileGrid.getZForResolution(476, function (value, high, low) { + return value - (low + (high - low) * 0.9); + }) + ).to.eql(1); + + expect( + tileGrid.getZForResolution(475, function (value, high, low) { + return value - (low + (high - low) * 0.9); + }) + ).to.eql(2); + + expect( + tileGrid.getZForResolution(201, function (value, high, low) { + return value - (low + (high - low) * 0.666666667); + }) + ).to.eql(2); + + expect( + tileGrid.getZForResolution(200, function (value, high, low) { + return value - (low + (high - low) * 0.666666667); + }) + ).to.eql(3); + + expect( + tileGrid.getZForResolution(126, function (value, high, low) { + return value - (low + (high - low) * 0.166666667); + }) + ).to.eql(2); + + expect( + tileGrid.getZForResolution(125, function (value, high, low) { + return value - (low + (high - low) * 0.166666667); + }) + ).to.eql(3); + }); + }); + describe('getTileRangeForTileCoordAndZ()', function () { const tileGrid = createForExtent( getProjection('EPSG:3857').getExtent(),