From 17873001b8ad7a3f14f470dcebbe6dbb843fa3b0 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 28 Jul 2023 13:15:47 +0200 Subject: [PATCH] outsourced tile sorting from tile comparing. --- src/tiledimage.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index e28ed224..42319144 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1931,24 +1931,35 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag } previousBest.push(tile); if (previousBest.length > maxNTiles) { - previousBest.sort(function (a, b) { - if (a === null) { - return 1; - } - if (b === null) { - return -1; - } - if (a.visibility === b.visibility) { - return (a.squaredDistance - b.squaredDistance); - } else { - return (a.visibility - b.visibility); - } - }); + this._sortTiles(previousBest); previousBest.pop(); } return previousBest; }, + /** + * @private + * @inner + * Sorts tiles in an array according to distance and visibility. + * + * @param {OpenSeadragon.Tile[]} tiles The tiles. + */ + _sortTiles: function( tiles ) { + tiles.sort(function (a, b) { + if (a === null) { + return 1; + } + if (b === null) { + return -1; + } + if (a.visibility === b.visibility) { + return (a.squaredDistance - b.squaredDistance); + } else { + return (a.visibility - b.visibility); + } + }); + }, + /** * @private * @inner