From 3353bd5f6941f2b06c008ac2c3c4eab193bad453 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 13 Aug 2014 15:52:20 +0100 Subject: [PATCH 1/7] Support other rotation angles. --- src/drawer.js | 9 ++++++++- src/rectangle.js | 3 --- src/viewport.js | 3 --- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 0165d1f3..a8db0265 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -398,11 +398,18 @@ function updateViewport( drawer ) { } //Change bounds for rotation - if (degrees === 90 || degrees === 270) { + if (degrees !== 0) { var rotatedBounds = viewportBounds.rotate( degrees ); viewportTL = rotatedBounds.getTopLeft(); viewportBR = rotatedBounds.getBottomRight(); } + else if (degrees !== 0) { + var factor = 0.5 / drawer.viewer.viewport.getZoom(); + viewportTL.x -= factor; + viewportTL.y -= factor; + viewportBR.x += factor; + viewportBR.y += factor; + } //Don't draw if completely outside of the viewport if ( !drawer.wrapHorizontal && diff --git a/src/rectangle.js b/src/rectangle.js index 99172e7d..b518190e 100644 --- a/src/rectangle.js +++ b/src/rectangle.js @@ -194,9 +194,6 @@ $.Rect.prototype = /** @lends OpenSeadragon.Rect.prototype */{ newTopLeft; degrees = ( degrees + 360 ) % 360; - if( degrees % 90 !== 0 ) { - throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.'); - } if( degrees === 0 ){ return new $.Rect( diff --git a/src/viewport.js b/src/viewport.js index ccc50a8a..fb64c1df 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -726,9 +726,6 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ } degrees = ( degrees + 360 ) % 360; - if( degrees % 90 !== 0 ) { - throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.'); - } this.degrees = degrees; this.viewer.forceRedraw(); From 50f9a82089c134ed9f81295a294311563f8737ca Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 15 Aug 2014 15:47:50 +0100 Subject: [PATCH 2/7] Small rotation fixes. --- src/drawer.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index a8db0265..5e4b59b7 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -398,13 +398,20 @@ function updateViewport( drawer ) { } //Change bounds for rotation - if (degrees !== 0) { + if (degrees === 90 || degrees === 270) { var rotatedBounds = viewportBounds.rotate( degrees ); viewportTL = rotatedBounds.getTopLeft(); viewportBR = rotatedBounds.getBottomRight(); } else if (degrees !== 0) { - var factor = 0.5 / drawer.viewer.viewport.getZoom(); + /* + var factor1 = drawer.viewer.viewport.imageToViewportRectangle(0, 0, 256, 256); + viewportBounds.width += factor1.width; + viewportBounds.height += factor1.width; + viewportTL = viewportBounds.getTopLeft(); + viewportBR = viewportBounds.getBottomRight(); + */ + var factor = 0.3 / drawer.viewer.viewport.getZoom(); viewportTL.x -= factor; viewportTL.y -= factor; viewportBR.x += factor; From e00e4c53ef5d38cfabf7bbad841fb665648f559c Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 19 Aug 2014 09:51:27 +0100 Subject: [PATCH 3/7] Proper viewport bounds changes for rotation. --- src/drawer.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 5e4b59b7..64d2b671 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -404,18 +404,15 @@ function updateViewport( drawer ) { viewportBR = rotatedBounds.getBottomRight(); } else if (degrees !== 0) { - /* - var factor1 = drawer.viewer.viewport.imageToViewportRectangle(0, 0, 256, 256); - viewportBounds.width += factor1.width; - viewportBounds.height += factor1.width; + var orthBounds = viewportBounds.rotate(90); + var halfWidth = orthBounds.width / 2; + var halfHeight = orthBounds.height / 2; + viewportBounds.x -= halfWidth / 2; + viewportBounds.y -= halfHeight / 2; + viewportBounds.width += halfWidth; + viewportBounds.height += halfHeight; viewportTL = viewportBounds.getTopLeft(); viewportBR = viewportBounds.getBottomRight(); - */ - var factor = 0.3 / drawer.viewer.viewport.getZoom(); - viewportTL.x -= factor; - viewportTL.y -= factor; - viewportBR.x += factor; - viewportBR.y += factor; } //Don't draw if completely outside of the viewport From 1c63c96f0415ed2a1c65f6b438b24e3be8903904 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 19 Aug 2014 15:56:23 +0100 Subject: [PATCH 4/7] Increase viewport bounds slightly for rotation. --- src/drawer.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 64d2b671..248266ba 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -405,12 +405,10 @@ function updateViewport( drawer ) { } else if (degrees !== 0) { var orthBounds = viewportBounds.rotate(90); - var halfWidth = orthBounds.width / 2; - var halfHeight = orthBounds.height / 2; - viewportBounds.x -= halfWidth / 2; - viewportBounds.y -= halfHeight / 2; - viewportBounds.width += halfWidth; - viewportBounds.height += halfHeight; + viewportBounds.x -= orthBounds.width / 2; + viewportBounds.y -= orthBounds.height / 2; + viewportBounds.width += orthBounds.width; + viewportBounds.height += orthBounds.height; viewportTL = viewportBounds.getTopLeft(); viewportBR = viewportBounds.getBottomRight(); } From ea80c05a05f2693f8df2ca88debca269ef40bc9a Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 20 Aug 2014 09:21:02 +0100 Subject: [PATCH 5/7] Replace error for non right-angle rotations in Rect.rotate. --- src/drawer.js | 1 + src/navigator.js | 2 +- src/rectangle.js | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/drawer.js b/src/drawer.js index 248266ba..34cf3506 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -404,6 +404,7 @@ function updateViewport( drawer ) { viewportBR = rotatedBounds.getBottomRight(); } else if (degrees !== 0) { + // This is just an approximation. var orthBounds = viewportBounds.rotate(90); viewportBounds.x -= orthBounds.width / 2; viewportBounds.y -= orthBounds.height / 2; diff --git a/src/navigator.js b/src/navigator.js index d07a2bba..9e18d6ca 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -241,7 +241,7 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* (this.container.clientHeight === 0 ? 1 : this.container.clientHeight) ); if ( !containerSize.equals( this.oldContainerSize ) ) { - var oldBounds = this.viewport.getBounds().rotate(this.viewport.degrees); + var oldBounds = this.viewport.getBounds(); var oldCenter = this.viewport.getCenter(); this.viewport.resize( containerSize, true ); var imageHeight = 1 / this.source.aspectRatio; diff --git a/src/rectangle.js b/src/rectangle.js index b518190e..1bac049f 100644 --- a/src/rectangle.js +++ b/src/rectangle.js @@ -195,6 +195,11 @@ $.Rect.prototype = /** @lends OpenSeadragon.Rect.prototype */{ degrees = ( degrees + 360 ) % 360; + if (degrees % 90 !== 0) + { + throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.'); + } + if( degrees === 0 ){ return new $.Rect( this.x, From c3b292cfb16f041502dca3f0447cc4c2837142e9 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 22 Aug 2014 14:57:20 +0100 Subject: [PATCH 6/7] Fix code style issue. --- src/rectangle.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rectangle.js b/src/rectangle.js index 1bac049f..4e3746eb 100644 --- a/src/rectangle.js +++ b/src/rectangle.js @@ -194,9 +194,7 @@ $.Rect.prototype = /** @lends OpenSeadragon.Rect.prototype */{ newTopLeft; degrees = ( degrees + 360 ) % 360; - - if (degrees % 90 !== 0) - { + if (degrees % 90 !== 0) { throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.'); } From e9382ffbf70be2369368994edc40748e4a8bd676 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 26 Aug 2014 14:56:24 +0100 Subject: [PATCH 7/7] Fixes doc comment. --- src/viewport.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 02b262f8..4de54f96 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -713,10 +713,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ }, /** - * Currently only 90 degree rotation is supported and it only works - * with the canvas. Additionally, the navigator does not rotate yet, - * debug mode doesn't rotate yet, and overlay rotation is only - * partially supported. + * Rotates this viewport to the angle specified. * @function * @return {OpenSeadragon.Viewport} Chainable. */