mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
simplified constraint code
This commit is contained in:
parent
c91039b545
commit
36264c44ef
@ -495,62 +495,40 @@ $.Viewport.prototype = {
|
|||||||
bounds.width,
|
bounds.width,
|
||||||
bounds.height);
|
bounds.height);
|
||||||
|
|
||||||
var horizontalThreshold = this.visibilityRatio * newBounds.width;
|
|
||||||
var verticalThreshold = this.visibilityRatio * newBounds.height;
|
|
||||||
|
|
||||||
if (this.wrapHorizontal) {
|
if (this.wrapHorizontal) {
|
||||||
//do nothing
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
var dx = 0;
|
var horizontalThreshold = this.visibilityRatio * newBounds.width;
|
||||||
var thresholdLeft = newBounds.x + (newBounds.width - horizontalThreshold);
|
var boundsRight = newBounds.x + newBounds.width;
|
||||||
var leftDx = this._contentBoundsNoRotate.x - thresholdLeft;
|
|
||||||
var contentRight = this._contentBoundsNoRotate.x + this._contentBoundsNoRotate.width;
|
var contentRight = this._contentBoundsNoRotate.x + this._contentBoundsNoRotate.width;
|
||||||
var thresholdRight = newBounds.x + horizontalThreshold;
|
var leftDx = this._contentBoundsNoRotate.x - boundsRight + horizontalThreshold;
|
||||||
var rightDx = contentRight - thresholdRight;
|
var rightDx = contentRight - newBounds.x - horizontalThreshold;
|
||||||
|
|
||||||
if (this._contentBoundsNoRotate.x > thresholdLeft) {
|
if (horizontalThreshold > this._contentBoundsNoRotate.width) {
|
||||||
dx = leftDx;
|
|
||||||
}
|
|
||||||
if (contentRight < thresholdRight) {
|
|
||||||
if (dx) {
|
|
||||||
dx = (dx + rightDx) / 2;
|
|
||||||
} else {
|
|
||||||
dx = rightDx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (horizontalThreshold > this._contentBoundsNoRotate.width && (newBounds.x > -thresholdLeft || newBounds.x + horizontalThreshold < 1)) {
|
|
||||||
newBounds.x += (leftDx + rightDx) / 2;
|
newBounds.x += (leftDx + rightDx) / 2;
|
||||||
} else {
|
} else if (rightDx < 0) {
|
||||||
newBounds.x += dx;
|
newBounds.x += rightDx;
|
||||||
|
} else if (leftDx > 0) {
|
||||||
|
newBounds.x += leftDx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.wrapVertical) {
|
if (this.wrapVertical) {
|
||||||
//do nothing
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
var dy = 0;
|
var verticalThreshold = this.visibilityRatio * newBounds.height;
|
||||||
var thresholdTop = newBounds.y + (newBounds.height - verticalThreshold);
|
var boundsBottom = newBounds.y + newBounds.height;
|
||||||
var topDy = this._contentBoundsNoRotate.y - thresholdTop;
|
|
||||||
var contentBottom = this._contentBoundsNoRotate.y + this._contentBoundsNoRotate.height;
|
var contentBottom = this._contentBoundsNoRotate.y + this._contentBoundsNoRotate.height;
|
||||||
var thresholdBottom = newBounds.y + verticalThreshold;
|
var topDy = this._contentBoundsNoRotate.y - boundsBottom + verticalThreshold;
|
||||||
var bottomDy = contentBottom - thresholdBottom;
|
var bottomDy = contentBottom - newBounds.y - verticalThreshold;
|
||||||
|
|
||||||
if (this._contentBoundsNoRotate.y > thresholdTop) {
|
if (verticalThreshold > this._contentBoundsNoRotate.height) {
|
||||||
dy = topDy;
|
|
||||||
}
|
|
||||||
if (contentBottom < thresholdBottom) {
|
|
||||||
if (dy) {
|
|
||||||
dy = (dy + bottomDy) / 2;
|
|
||||||
} else {
|
|
||||||
dy = bottomDy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (verticalThreshold > this._contentBoundsNoRotate.height && (newBounds.y > -thresholdTop || newBounds.y + verticalThreshold < 1)) {
|
|
||||||
newBounds.y += (topDy + bottomDy) / 2;
|
newBounds.y += (topDy + bottomDy) / 2;
|
||||||
} else {
|
} else if (bottomDy < 0) {
|
||||||
newBounds.y += dy;
|
newBounds.y += bottomDy;
|
||||||
|
} else if (topDy > 0) {
|
||||||
|
newBounds.y += topDy;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.viewer) {
|
if (this.viewer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user