mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Add viewport.viewportToViewerElementRectangle
This commit is contained in:
parent
cac5f6dec3
commit
f6c09ca716
@ -110,6 +110,33 @@ $.Rect = function(x, y, width, height, degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds a rectangle having the 3 specified points as summits.
|
||||
* @static
|
||||
* @memberof OpenSeadragon.Rect
|
||||
* @param {OpenSeadragon.Point} topLeft
|
||||
* @param {OpenSeadragon.Point} topRight
|
||||
* @param {OpenSeadragon.Point} bottomLeft
|
||||
* @returns {OpenSeadragon.Rect}
|
||||
*/
|
||||
$.Rect.fromSummits = function(topLeft, topRight, bottomLeft) {
|
||||
var width = topLeft.distanceTo(topRight);
|
||||
var height = topLeft.distanceTo(bottomLeft);
|
||||
var diff = topRight.minus(topLeft);
|
||||
var radians = Math.atan(diff.y / diff.x);
|
||||
if (diff.x < 0) {
|
||||
radians += Math.PI;
|
||||
} else if (diff.y < 0) {
|
||||
radians += 2 * Math.PI;
|
||||
}
|
||||
return new $.Rect(
|
||||
topLeft.x,
|
||||
topLeft.y,
|
||||
width,
|
||||
height,
|
||||
radians / Math.PI * 180);
|
||||
};
|
||||
|
||||
/** @lends OpenSeadragon.Rect.prototype */
|
||||
$.Rect.prototype = {
|
||||
/**
|
||||
@ -284,7 +311,7 @@ $.Rect.prototype = {
|
||||
* Rotates a rectangle around a point.
|
||||
* @function
|
||||
* @param {Number} degrees The angle in degrees to rotate.
|
||||
* @param {OpenSeadragon.Point} pivot The point about which to rotate.
|
||||
* @param {OpenSeadragon.Point} [pivot] The point about which to rotate.
|
||||
* Defaults to the center of the rectangle.
|
||||
* @return {OpenSeadragon.Rect}
|
||||
*/
|
||||
|
@ -1262,6 +1262,20 @@ $.Viewport.prototype = {
|
||||
return this.pixelFromPoint( point, true );
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert a rectangle in viewport coordinates to pixel coordinates relative
|
||||
* to the viewer element.
|
||||
* @param {OpenSeadragon.Rect} rectangle the rectangle to convert
|
||||
* @returns {OpenSeadragon.Rect} the converted rectangle
|
||||
*/
|
||||
viewportToViewerElementRectangle: function(rectangle) {
|
||||
return $.Rect.fromSummits(
|
||||
this.pixelFromPoint(rectangle.getTopLeft(), true),
|
||||
this.pixelFromPoint(rectangle.getTopRight(), true),
|
||||
this.pixelFromPoint(rectangle.getBottomLeft(), true)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert pixel coordinates relative to the window to viewport coordinates.
|
||||
* @param {OpenSeadragon.Point} pixel
|
||||
|
Loading…
Reference in New Issue
Block a user