outsourced tile sorting from tile comparing.

This commit is contained in:
Peter 2023-07-28 13:15:47 +02:00
parent ccb4ae9f86
commit 17873001b8

View File

@ -1931,7 +1931,21 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
} }
previousBest.push(tile); previousBest.push(tile);
if (previousBest.length > maxNTiles) { if (previousBest.length > maxNTiles) {
previousBest.sort(function (a, b) { 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) { if (a === null) {
return 1; return 1;
} }
@ -1944,9 +1958,6 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
return (a.visibility - b.visibility); return (a.visibility - b.visibility);
} }
}); });
previousBest.pop();
}
return previousBest;
}, },
/** /**