mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
Merge pull request #1027 from rdlester/square
Use the squared distance when comparing tiles.
This commit is contained in:
commit
77ff2bfd05
12
src/point.js
12
src/point.js
@ -148,6 +148,18 @@ $.Point.prototype = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the squared distance between this point and another point.
|
||||||
|
* Useful for optimizing things like comparing distances.
|
||||||
|
* @function
|
||||||
|
* @param {OpenSeadragon.Point} point The point to compute the squared distance with.
|
||||||
|
* @returns {Number} The squared distance between the 2 points
|
||||||
|
*/
|
||||||
|
squaredDistanceTo: function( point ) {
|
||||||
|
return Math.pow( this.x - point.x, 2 ) +
|
||||||
|
Math.pow( this.y - point.y, 2 );
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a function to each coordinate of this point and return a new point.
|
* Apply a function to each coordinate of this point and return a new point.
|
||||||
* @function
|
* @function
|
||||||
|
@ -154,11 +154,13 @@ $.Tile = function(level, x, y, bounds, exists, url, context2D) {
|
|||||||
*/
|
*/
|
||||||
this.opacity = null;
|
this.opacity = null;
|
||||||
/**
|
/**
|
||||||
* The distance of this tile to the viewport center.
|
* The squared distance of this tile to the viewport center.
|
||||||
* @member {Number} distance
|
* Use for comparing tiles.
|
||||||
|
* @private
|
||||||
|
* @member {Number} squaredDistance
|
||||||
* @memberof OpenSeadragon.Tile#
|
* @memberof OpenSeadragon.Tile#
|
||||||
*/
|
*/
|
||||||
this.distance = null;
|
this.squaredDistance = null;
|
||||||
/**
|
/**
|
||||||
* The visibility score of this tile.
|
* The visibility score of this tile.
|
||||||
* @member {Number} visibility
|
* @member {Number} visibility
|
||||||
|
@ -1300,7 +1300,7 @@ function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility,
|
|||||||
sizeC = viewport.deltaPixelsFromPointsNoRotate(boundsSize, true),
|
sizeC = viewport.deltaPixelsFromPointsNoRotate(boundsSize, true),
|
||||||
sizeT = viewport.deltaPixelsFromPointsNoRotate(boundsSize, false),
|
sizeT = viewport.deltaPixelsFromPointsNoRotate(boundsSize, false),
|
||||||
tileCenter = positionT.plus( sizeT.divide( 2 ) ),
|
tileCenter = positionT.plus( sizeT.divide( 2 ) ),
|
||||||
tileDistance = viewportCenter.distanceTo( tileCenter );
|
tileSquaredDistance = viewportCenter.squaredDistanceTo( tileCenter );
|
||||||
|
|
||||||
if ( !overlap ) {
|
if ( !overlap ) {
|
||||||
sizeC = sizeC.plus( new $.Point( 1, 1 ) );
|
sizeC = sizeC.plus( new $.Point( 1, 1 ) );
|
||||||
@ -1308,7 +1308,7 @@ function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility,
|
|||||||
|
|
||||||
tile.position = positionC;
|
tile.position = positionC;
|
||||||
tile.size = sizeC;
|
tile.size = sizeC;
|
||||||
tile.distance = tileDistance;
|
tile.squaredDistance = tileSquaredDistance;
|
||||||
tile.visibility = levelVisibility;
|
tile.visibility = levelVisibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1452,7 +1452,7 @@ function compareTiles( previousBest, tile ) {
|
|||||||
if ( tile.visibility > previousBest.visibility ) {
|
if ( tile.visibility > previousBest.visibility ) {
|
||||||
return tile;
|
return tile;
|
||||||
} else if ( tile.visibility == previousBest.visibility ) {
|
} else if ( tile.visibility == previousBest.visibility ) {
|
||||||
if ( tile.distance < previousBest.distance ) {
|
if ( tile.squaredDistance < previousBest.squaredDistance ) {
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user