mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Coordinate conversion rounding errors were causing test breakages; fixed
This commit is contained in:
parent
b8a1762a95
commit
66517dab8d
@ -184,6 +184,12 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
return new $.Point(this.source.dimensions.x, this.source.dimensions.y);
|
return new $.Point(this.source.dimensions.x, this.source.dimensions.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
_viewportToImageDelta: function( viewerX, viewerY ) {
|
||||||
|
return new $.Point(viewerX * (this.source.dimensions.x / this._scale),
|
||||||
|
viewerY * ((this.source.dimensions.y * this.contentAspectX) / this._scale));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates from OpenSeadragon viewer coordinate system to image coordinate system.
|
* Translates from OpenSeadragon viewer coordinate system to image coordinate system.
|
||||||
* This method can be called either by passing X,Y coordinates or an
|
* This method can be called either by passing X,Y coordinates or an
|
||||||
@ -200,9 +206,13 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
return this.viewportToImageCoordinates( viewerX.x, viewerX.y );
|
return this.viewportToImageCoordinates( viewerX.x, viewerX.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentSize = this.source.dimensions;
|
return this._viewportToImageDelta(viewerX - this._worldX, viewerY - this._worldY);
|
||||||
return new $.Point((viewerX - this._worldX) * (contentSize.x / this._scale),
|
},
|
||||||
(viewerY - this._worldY) * ((contentSize.y * this.contentAspectX) / this._scale));
|
|
||||||
|
// private
|
||||||
|
_imageToViewportDelta: function( imageX, imageY ) {
|
||||||
|
return new $.Point((imageX / this.source.dimensions.x) * this._scale,
|
||||||
|
(imageY / this.source.dimensions.y / this.contentAspectX) * this._scale);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,9 +231,10 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
return this.imageToViewportCoordinates( imageX.x, imageX.y );
|
return this.imageToViewportCoordinates( imageX.x, imageX.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentSize = this.source.dimensions;
|
var point = this._imageToViewportDelta(imageX, imageY);
|
||||||
return new $.Point(this._worldX + ((imageX / contentSize.x) * this._scale),
|
point.x += this._worldX;
|
||||||
this._worldY + ((imageY / contentSize.y / this.contentAspectX) * this._scale));
|
point.y += this._worldY;
|
||||||
|
return point;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,14 +265,14 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
coordA = this.imageToViewportCoordinates(
|
coordA = this.imageToViewportCoordinates(
|
||||||
imageX, imageY
|
imageX, imageY
|
||||||
);
|
);
|
||||||
coordB = this.imageToViewportCoordinates(
|
coordB = this._imageToViewportDelta(
|
||||||
imageX + pixelWidth, imageY + pixelHeight
|
pixelWidth, pixelHeight
|
||||||
);
|
);
|
||||||
return new $.Rect(
|
return new $.Rect(
|
||||||
coordA.x,
|
coordA.x,
|
||||||
coordA.y,
|
coordA.y,
|
||||||
coordB.x - coordA.x,
|
coordB.x,
|
||||||
coordB.y - coordA.y
|
coordB.y
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -291,12 +302,12 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
||||||
coordB = this.viewportToImageCoordinates(viewerX + pointWidth, viewerY + pointHeight);
|
coordB = this._viewportToImageDelta(pointWidth, pointHeight);
|
||||||
return new $.Rect(
|
return new $.Rect(
|
||||||
coordA.x,
|
coordA.x,
|
||||||
coordA.y,
|
coordA.y,
|
||||||
coordB.x - coordA.x,
|
coordB.x,
|
||||||
coordB.y - coordA.y
|
coordB.y
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -938,6 +938,13 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
_viewportToImageDelta: function( viewerX, viewerY ) {
|
||||||
|
var scale = this.homeBounds.width;
|
||||||
|
return new $.Point(viewerX * (this.contentSize.x / scale),
|
||||||
|
viewerY * ((this.contentSize.y * this.contentAspectX) / scale));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates from OpenSeadragon viewer coordinate system to image coordinate system.
|
* Translates from OpenSeadragon viewer coordinate system to image coordinate system.
|
||||||
* This method can be called either by passing X,Y coordinates or an
|
* This method can be called either by passing X,Y coordinates or an
|
||||||
@ -959,9 +966,14 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
|||||||
$.console.error('[Viewport.viewportToImageCoordinates] is not accurate with multi-image; use TiledImage.viewportToImageCoordinates instead.');
|
$.console.error('[Viewport.viewportToImageCoordinates] is not accurate with multi-image; use TiledImage.viewportToImageCoordinates instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._viewportToImageDelta(viewerX - this.homeBounds.x, viewerY - this.homeBounds.y);
|
||||||
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
_imageToViewportDelta: function( imageX, imageY ) {
|
||||||
var scale = this.homeBounds.width;
|
var scale = this.homeBounds.width;
|
||||||
return new $.Point((viewerX - this.homeBounds.x) * (this.contentSize.x / scale),
|
return new $.Point((imageX / this.contentSize.x) * scale,
|
||||||
(viewerY - this.homeBounds.y) * ((this.contentSize.y * this.contentAspectX) / scale));
|
(imageY / this.contentSize.y / this.contentAspectX) * scale);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -985,9 +997,10 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
|||||||
$.console.error('[Viewport.imageToViewportCoordinates] is not accurate with multi-image; use TiledImage.imageToViewportCoordinates instead.');
|
$.console.error('[Viewport.imageToViewportCoordinates] is not accurate with multi-image; use TiledImage.imageToViewportCoordinates instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var scale = this.homeBounds.width;
|
var point = this._imageToViewportDelta(imageX, imageY);
|
||||||
return new $.Point(this.homeBounds.x + ((imageX / this.contentSize.x) * scale),
|
point.x += this.homeBounds.x;
|
||||||
this.homeBounds.y + ((imageY / this.contentSize.y / this.contentAspectX) * scale));
|
point.y += this.homeBounds.y;
|
||||||
|
return point;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1020,14 +1033,14 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
|||||||
coordA = this.imageToViewportCoordinates(
|
coordA = this.imageToViewportCoordinates(
|
||||||
imageX, imageY
|
imageX, imageY
|
||||||
);
|
);
|
||||||
coordB = this.imageToViewportCoordinates(
|
coordB = this._imageToViewportDelta(
|
||||||
imageX + pixelWidth, imageY + pixelHeight
|
pixelWidth, pixelHeight
|
||||||
);
|
);
|
||||||
return new $.Rect(
|
return new $.Rect(
|
||||||
coordA.x,
|
coordA.x,
|
||||||
coordA.y,
|
coordA.y,
|
||||||
coordB.x - coordA.x,
|
coordB.x,
|
||||||
coordB.y - coordA.y
|
coordB.y
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1059,12 +1072,12 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
|||||||
}
|
}
|
||||||
|
|
||||||
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
||||||
coordB = this.viewportToImageCoordinates(viewerX + pointWidth, viewerY + pointHeight);
|
coordB = this._viewportToImageDelta(pointWidth, pointHeight);
|
||||||
return new $.Rect(
|
return new $.Rect(
|
||||||
coordA.x,
|
coordA.x,
|
||||||
coordA.y,
|
coordA.y,
|
||||||
coordB.x - coordA.x,
|
coordB.x,
|
||||||
coordB.y - coordA.y
|
coordB.y
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user