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,24 +1931,35 @@ $.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);
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);
}
});
previousBest.pop(); previousBest.pop();
} }
return previousBest; 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 * @private
* @inner * @inner