mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 20:56:09 +03:00
Merge pull request #965 from MrP/master
Fix issue #890 in applyConstraints
This commit is contained in:
commit
6f4235c7f3
@ -495,51 +495,40 @@ $.Viewport.prototype = {
|
||||
bounds.width,
|
||||
bounds.height);
|
||||
|
||||
var horizontalThreshold = this.visibilityRatio * newBounds.width;
|
||||
var verticalThreshold = this.visibilityRatio * newBounds.height;
|
||||
|
||||
if (this.wrapHorizontal) {
|
||||
//do nothing
|
||||
} else {
|
||||
var dx = 0;
|
||||
var thresholdLeft = newBounds.x + (newBounds.width - horizontalThreshold);
|
||||
if (this._contentBoundsNoRotate.x > thresholdLeft) {
|
||||
dx = this._contentBoundsNoRotate.x - thresholdLeft;
|
||||
}
|
||||
|
||||
var horizontalThreshold = this.visibilityRatio * newBounds.width;
|
||||
var boundsRight = newBounds.x + newBounds.width;
|
||||
var contentRight = this._contentBoundsNoRotate.x + this._contentBoundsNoRotate.width;
|
||||
var thresholdRight = newBounds.x + horizontalThreshold;
|
||||
if (contentRight < thresholdRight) {
|
||||
var newDx = contentRight - thresholdRight;
|
||||
if (dx) {
|
||||
dx = (dx + newDx) / 2;
|
||||
} else {
|
||||
dx = newDx;
|
||||
}
|
||||
var leftDx = this._contentBoundsNoRotate.x - boundsRight + horizontalThreshold;
|
||||
var rightDx = contentRight - newBounds.x - horizontalThreshold;
|
||||
|
||||
if (horizontalThreshold > this._contentBoundsNoRotate.width) {
|
||||
newBounds.x += (leftDx + rightDx) / 2;
|
||||
} else if (rightDx < 0) {
|
||||
newBounds.x += rightDx;
|
||||
} else if (leftDx > 0) {
|
||||
newBounds.x += leftDx;
|
||||
}
|
||||
newBounds.x += dx;
|
||||
}
|
||||
|
||||
if (this.wrapVertical) {
|
||||
//do nothing
|
||||
} else {
|
||||
var dy = 0;
|
||||
var thresholdTop = newBounds.y + (newBounds.height - verticalThreshold);
|
||||
if (this._contentBoundsNoRotate.y > thresholdTop) {
|
||||
dy = this._contentBoundsNoRotate.y - thresholdTop;
|
||||
}
|
||||
|
||||
var verticalThreshold = this.visibilityRatio * newBounds.height;
|
||||
var boundsBottom = newBounds.y + newBounds.height;
|
||||
var contentBottom = this._contentBoundsNoRotate.y + this._contentBoundsNoRotate.height;
|
||||
var thresholdBottom = newBounds.y + verticalThreshold;
|
||||
if (contentBottom < thresholdBottom) {
|
||||
var newDy = contentBottom - thresholdBottom;
|
||||
if (dy) {
|
||||
dy = (dy + newDy) / 2;
|
||||
} else {
|
||||
dy = newDy;
|
||||
}
|
||||
var topDy = this._contentBoundsNoRotate.y - boundsBottom + verticalThreshold;
|
||||
var bottomDy = contentBottom - newBounds.y - verticalThreshold;
|
||||
|
||||
if (verticalThreshold > this._contentBoundsNoRotate.height) {
|
||||
newBounds.y += (topDy + bottomDy) / 2;
|
||||
} else if (bottomDy < 0) {
|
||||
newBounds.y += bottomDy;
|
||||
} else if (topDy > 0) {
|
||||
newBounds.y += topDy;
|
||||
}
|
||||
newBounds.y += dy;
|
||||
}
|
||||
|
||||
if (this.viewer) {
|
||||
|
@ -820,8 +820,8 @@
|
||||
Util.assessNumericValue(zoom, 0.002, epsilon,
|
||||
"Zoom should not be prevented");
|
||||
Util.assertRectangleEquals(
|
||||
new OpenSeadragon.Rect(-249.5, -0.25, 500, 0.5),
|
||||
bounds,
|
||||
new OpenSeadragon.Rect(-250, -0.25, 500, 0.5),
|
||||
epsilon,
|
||||
'Pan should not be prevented');
|
||||
|
||||
|
@ -437,8 +437,8 @@
|
||||
viewport.applyConstraints(true);
|
||||
var bounds = viewport.getBounds();
|
||||
Util.assertRectangleEquals(
|
||||
bounds,
|
||||
new OpenSeadragon.Rect(0.7, 0.7, 1, 1),
|
||||
bounds,
|
||||
EPSILON,
|
||||
"Viewport.applyConstraints should move viewport.");
|
||||
start();
|
||||
@ -447,6 +447,27 @@
|
||||
viewer.open(DZI_PATH);
|
||||
});
|
||||
|
||||
asyncTest('applyConstraints with visibilityRatio = 1 shouldn\'t bounce around', function() {
|
||||
var openHandler = function() {
|
||||
viewer.removeHandler('open', openHandler);
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
viewport.visibilityRatio = 1;
|
||||
viewport.zoomTo(0.5, undefined, true);
|
||||
viewport.panBy(new OpenSeadragon.Point(0.75, 0), true);
|
||||
viewport.applyConstraints(true);
|
||||
var bounds = viewport.getBounds();
|
||||
Util.assertRectangleEquals(
|
||||
new OpenSeadragon.Rect(-0.5, 1, 2, 2),
|
||||
bounds,
|
||||
EPSILON,
|
||||
"Viewport.applyConstraints should move viewport to the center, not to a side.");
|
||||
start();
|
||||
};
|
||||
viewer.addHandler('open', openHandler);
|
||||
viewer.open(TALL_PATH);
|
||||
});
|
||||
|
||||
asyncTest('applyConstraints with rotation', function() {
|
||||
var openHandler = function() {
|
||||
viewer.removeHandler('open', openHandler);
|
||||
|
Loading…
Reference in New Issue
Block a user