From cd4c4d38ed6938339beb623e34e80aea30a2373c Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Sun, 6 Aug 2017 15:00:50 +0200 Subject: [PATCH] Fix getTileAtPoint floating point computation error --- src/tilesource.js | 3 ++- test/modules/tilesource.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tilesource.js b/src/tilesource.js index b40598ae..84aa5a82 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -360,7 +360,8 @@ $.TileSource.prototype = { if (point.x >= 1) { x = this.getNumTiles(level).x - 1; } - if (point.y >= 1 / this.aspectRatio) { + var EPSILON = 1e-16; + if (point.y >= 1 / this.aspectRatio - EPSILON) { y = this.getNumTiles(level).y - 1; } diff --git a/test/modules/tilesource.js b/test/modules/tilesource.js index 21a9f30c..bac637c8 100644 --- a/test/modules/tilesource.js +++ b/test/modules/tilesource.js @@ -96,6 +96,17 @@ maxLevel: 0, }); assertTileAtPoint(0, new OpenSeadragon.Point(1, 1009 / 1006), new OpenSeadragon.Point(0, 0)); + + // Test for issue #1276 + tileSource = new OpenSeadragon.TileSource({ + width: 4036, + height: 1239, + tileWidth: 4036, + tileHeight: 1239, + tileOverlap: 0, + maxLevel: 0, + }); + assertTileAtPoint(0, new OpenSeadragon.Point(1, 1239 / 4036), new OpenSeadragon.Point(0, 0)); }); }());