From 38e91f1fa58e2a1ddb5f0c91044927088e6a614c Mon Sep 17 00:00:00 2001 From: Jirka Date: Wed, 30 Mar 2022 13:27:23 +0200 Subject: [PATCH 1/2] Change coverage methods on TiledImage to be member methods. --- src/tiledimage.js | 231 +++++++++++++++++++++++----------------------- 1 file changed, 116 insertions(+), 115 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index afb5d48c..b955a30b 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1176,7 +1176,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag // Stop the loop if lower-res tiles would all be covered by // already drawn tiles - if ($.TiledImage._providesCoverage(this.coverage, level)) { + if (this._providesCoverage(this.coverage, level)) { break; } } @@ -1287,8 +1287,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag }); } - $.TiledImage._resetCoverage(this.coverage, level); - $.TiledImage._resetCoverage(this.loadingCoverage, level); + this._resetCoverage(this.coverage, level); + this._resetCoverage(this.loadingCoverage, level); //OK, a new drawing so do your calculations var cornerTiles = this._getCornerTiles(level, topLeftBound, bottomRightBound); @@ -1392,18 +1392,18 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag }); } - $.TiledImage._setCoverage( this.coverage, level, x, y, false ); + this._setCoverage( this.coverage, level, x, y, false ); - var loadingCoverage = tile.loaded || tile.loading || $.TiledImage._isCovered(this.loadingCoverage, level, x, y); - $.TiledImage._setCoverage(this.loadingCoverage, level, x, y, loadingCoverage); + var loadingCoverage = tile.loaded || tile.loading || this._isCovered(this.loadingCoverage, level, x, y); + this._setCoverage(this.loadingCoverage, level, x, y, loadingCoverage); if ( !tile.exists ) { return best; } if ( haveDrawn && !drawTile ) { - if ( $.TiledImage._isCovered( this.coverage, level, x, y ) ) { - $.TiledImage._setCoverage( this.coverage, level, x, y, true ); + if ( this._isCovered( this.coverage, level, x, y ) ) { + this._setCoverage( this.coverage, level, x, y, true ); } else { drawTile = true; } @@ -1789,7 +1789,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag this.lastDrawn.push( tile ); if ( opacity === 1 ) { - $.TiledImage._setCoverage( this.coverage, level, x, y, true ); + this._setCoverage( this.coverage, level, x, y, true ); this._hasOpaqueTile = true; } else if ( deltaTime < blendTimeMillis ) { return true; @@ -2080,124 +2080,125 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag } } } - } -}); + }, -/** - * @private - * @inner - * Returns true if the given tile provides coverage to lower-level tiles of - * lower resolution representing the same content. If neither x nor y is - * given, returns true if the entire visible level provides coverage. - * - * Note that out-of-bounds tiles provide coverage in this sense, since - * there's no content that they would need to cover. Tiles at non-existent - * levels that are within the image bounds, however, do not. - * - * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. - * @param {Number} level - The resolution level of the tile. - * @param {Number} x - The X position of the tile. - * @param {Number} y - The Y position of the tile. - * @returns {Boolean} - */ -$.TiledImage._providesCoverage = function( coverage, level, x, y ) { - var rows, - cols, - i, j; + /** + * @private + * @inner + * Returns true if the given tile provides coverage to lower-level tiles of + * lower resolution representing the same content. If neither x nor y is + * given, returns true if the entire visible level provides coverage. + * + * Note that out-of-bounds tiles provide coverage in this sense, since + * there's no content that they would need to cover. Tiles at non-existent + * levels that are within the image bounds, however, do not. + * + * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. + * @param {Number} level - The resolution level of the tile. + * @param {Number} x - The X position of the tile. + * @param {Number} y - The Y position of the tile. + * @returns {Boolean} + */ + _providesCoverage: function( coverage, level, x, y ) { + var rows, + cols, + i, j; - if ( !coverage[ level ] ) { - return false; - } + if ( !coverage[ level ] ) { + return false; + } - if ( x === undefined || y === undefined ) { - rows = coverage[ level ]; - for ( i in rows ) { - if ( Object.prototype.hasOwnProperty.call( rows, i ) ) { - cols = rows[ i ]; - for ( j in cols ) { - if ( Object.prototype.hasOwnProperty.call( cols, j ) && !cols[ j ] ) { - return false; + if ( x === undefined || y === undefined ) { + rows = coverage[ level ]; + for ( i in rows ) { + if ( Object.prototype.hasOwnProperty.call( rows, i ) ) { + cols = rows[ i ]; + for ( j in cols ) { + if ( Object.prototype.hasOwnProperty.call( cols, j ) && !cols[ j ] ) { + return false; + } } } } + + return true; } - return true; - } - - return ( - coverage[ level ][ x] === undefined || - coverage[ level ][ x ][ y ] === undefined || - coverage[ level ][ x ][ y ] === true - ); -}; - -/** - * @private - * @inner - * Returns true if the given tile is completely covered by higher-level - * tiles of higher resolution representing the same content. If neither x - * nor y is given, returns true if the entire visible level is covered. - * - * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. - * @param {Number} level - The resolution level of the tile. - * @param {Number} x - The X position of the tile. - * @param {Number} y - The Y position of the tile. - * @returns {Boolean} - */ -$.TiledImage._isCovered = function( coverage, level, x, y ) { - if ( x === undefined || y === undefined ) { - return this._providesCoverage( coverage, level + 1 ); - } else { return ( - this._providesCoverage( coverage, level + 1, 2 * x, 2 * y ) && - this._providesCoverage( coverage, level + 1, 2 * x, 2 * y + 1 ) && - this._providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y ) && - this._providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y + 1 ) + coverage[ level ][ x] === undefined || + coverage[ level ][ x ][ y ] === undefined || + coverage[ level ][ x ][ y ] === true ); + }, + + /** + * @private + * @inner + * Returns true if the given tile is completely covered by higher-level + * tiles of higher resolution representing the same content. If neither x + * nor y is given, returns true if the entire visible level is covered. + * + * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. + * @param {Number} level - The resolution level of the tile. + * @param {Number} x - The X position of the tile. + * @param {Number} y - The Y position of the tile. + * @returns {Boolean} + */ + _isCovered: function( coverage, level, x, y ) { + if ( x === undefined || y === undefined ) { + return this._providesCoverage( coverage, level + 1 ); + } else { + return ( + this._providesCoverage( coverage, level + 1, 2 * x, 2 * y ) && + this._providesCoverage( coverage, level + 1, 2 * x, 2 * y + 1 ) && + this._providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y ) && + this._providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y + 1 ) + ); + } + }, + + /** + * @private + * @inner + * Sets whether the given tile provides coverage or not. + * + * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. + * @param {Number} level - The resolution level of the tile. + * @param {Number} x - The X position of the tile. + * @param {Number} y - The Y position of the tile. + * @param {Boolean} covers - Whether the tile provides coverage. + */ + _setCoverage: function( coverage, level, x, y, covers ) { + if ( !coverage[ level ] ) { + $.console.warn( + "Setting coverage for a tile before its level's coverage has been reset: %s", + level + ); + return; + } + + if ( !coverage[ level ][ x ] ) { + coverage[ level ][ x ] = {}; + } + + coverage[ level ][ x ][ y ] = covers; + }, + + /** + * @private + * @inner + * Resets coverage information for the given level. This should be called + * after every draw routine. Note that at the beginning of the next draw + * routine, coverage for every visible tile should be explicitly set. + * + * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. + * @param {Number} level - The resolution level of tiles to completely reset. + */ + _resetCoverage: function( coverage, level ) { + coverage[ level ] = {}; } -}; +}); -/** - * @private - * @inner - * Sets whether the given tile provides coverage or not. - * - * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. - * @param {Number} level - The resolution level of the tile. - * @param {Number} x - The X position of the tile. - * @param {Number} y - The Y position of the tile. - * @param {Boolean} covers - Whether the tile provides coverage. - */ -$.TiledImage._setCoverage = function( coverage, level, x, y, covers ) { - if ( !coverage[ level ] ) { - $.console.warn( - "Setting coverage for a tile before its level's coverage has been reset: %s", - level - ); - return; - } - - if ( !coverage[ level ][ x ] ) { - coverage[ level ][ x ] = {}; - } - - coverage[ level ][ x ][ y ] = covers; -}; - -/** - * @private - * @inner - * Resets coverage information for the given level. This should be called - * after every draw routine. Note that at the beginning of the next draw - * routine, coverage for every visible tile should be explicitly set. - * - * @param {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean. - * @param {Number} level - The resolution level of tiles to completely reset. - */ -$.TiledImage._resetCoverage = function( coverage, level ) { - coverage[ level ] = {}; -}; /** * @private From 2c9d244023264ff170741ad03a5ad555ae7bc2b1 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 31 Mar 2022 13:55:53 -0700 Subject: [PATCH 2/2] Changelog for #2134 --- changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 303e1478..252a1d98 100644 --- a/changelog.txt +++ b/changelog.txt @@ -13,6 +13,8 @@ OPENSEADRAGON CHANGELOG * Fixed: Setting useCanvas to false would break the viewer (#2116 @rvv-bouvet) * Allow silencing multi-image warnings on viewport coordinate conversion functions (#2120 @claycoleman) * Fixed: Swiping fast multiple times made contact points in MouseTracker out of sync for touch events (#2121 @ronnymikalsen) +* Made MouseTracker more robust in certain scenarios (#2134 @Aiosa) +* Exposed TiledImage's private functions for better maintainability (#2134 @Aiosa) 3.0.0: