From 05997d359c5af56e3e31988b7b3e055d3e2ef646 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 5 Dec 2022 19:38:46 -0500 Subject: [PATCH] reverted Viewport.setRotation, created Viewport.setRotationWithPivot --- src/viewport.js | 23 +++++++++++++++++------ test/modules/drawer.js | 2 +- test/modules/units.js | 4 ++-- test/modules/viewport.js | 22 +++++++++++----------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 4a68849c..a820ea1b 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -617,7 +617,6 @@ $.Viewport.prototype = { var bounds = this.getBoundsNoRotate(); var constrainedBounds = this._applyBoundaryConstraints(bounds); - this._raiseConstraintsEvent(immediately); if (bounds.x !== constrainedBounds.x || bounds.y !== constrainedBounds.y || @@ -913,17 +912,15 @@ $.Viewport.prototype = { }, /** - * Rotates this viewport to the angle specified. Alias for rotateTo. + * Rotates this viewport to the angle specified. * @function * @param {Number} degrees The degrees to set the rotation to. - * @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates - * around which the rotation should be performed. Defaults to the center of the viewport. * @param {Boolean} [immediately=false] Whether to animate to the new angle * or rotate immediately. * * @returns {OpenSeadragon.Viewport} Chainable. */ - setRotation: function(degrees, pivot, immediately) { - return this.rotateTo(degrees, pivot, immediately); + setRotation: function(degrees, immediately) { + return this.rotateTo(degrees, null, immediately); }, /** @@ -938,6 +935,20 @@ $.Viewport.prototype = { this.degreesSpring.target.value; }, + /** + * Rotates this viewport to the angle specified around a pivot point. Alias for rotateTo. + * @function + * @param {Number} degrees The degrees to set the rotation to. + * @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates + * around which the rotation should be performed. Defaults to the center of the viewport. + * @param {Boolean} [immediately=false] Whether to animate to the new angle + * or rotate immediately. + * * @returns {OpenSeadragon.Viewport} Chainable. + */ + setRotationWithPivot: function(degrees, pivot, immediately) { + return this.rotateTo(degrees, pivot, immediately); + }, + /** * Rotates this viewport to the angle specified. * @function diff --git a/test/modules/drawer.js b/test/modules/drawer.js index e39b48b5..d40c47c1 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -46,7 +46,7 @@ }); viewer.addHandler('open', function handler(event) { - viewer.viewport.setRotation(30, null, true); + viewer.viewport.setRotation(30, true); Util.spyOnce(viewer.drawer.context, 'rotate', function() { assert.ok(true, 'drawing with new rotation'); done(); diff --git a/test/modules/units.js b/test/modules/units.js index 9f350130..ee47ebe1 100644 --- a/test/modules/units.js +++ b/test/modules/units.js @@ -212,13 +212,13 @@ checkPoint(assert, ' after zoom and pan'); //Restore rotation - viewer.viewport.setRotation(0, null, true); + viewer.viewport.setRotation(0, true); done(); }); viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2)); }); - viewer.viewport.setRotation(45, null, true); + viewer.viewport.setRotation(45, true); viewer.open([{ tileSource: "/test/data/testpattern.dzi" }, { diff --git a/test/modules/viewport.js b/test/modules/viewport.js index 1e4c91f8..e8267efc 100644 --- a/test/modules/viewport.js +++ b/test/modules/viewport.js @@ -247,7 +247,7 @@ function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - viewport.setRotation(-675, null, true); + viewport.setRotation(-675, true); Util.assertRectangleEquals( assert, viewport.getHomeBoundsNoRotate(), @@ -269,7 +269,7 @@ function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - viewport.setRotation(-675, null, true); + viewport.setRotation(-675, true); Util.assertRectangleEquals( assert, viewport.getHomeBounds(), @@ -533,7 +533,7 @@ var openHandler = function() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - viewport.setRotation(45, null, true); + viewport.setRotation(45, true); viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true); viewport.applyConstraints(true); var bounds = viewport.getBounds(); @@ -557,7 +557,7 @@ var viewport = viewer.viewport; viewport.setFlip(true); - viewport.setRotation(45, null, true); + viewport.setRotation(45, true); viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true); viewport.applyConstraints(true); @@ -659,7 +659,7 @@ var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - viewport.setRotation(45, null, true); + viewport.setRotation(45, true); for(var i = 0; i < testRectsFitBounds.length; i++){ var rect = testRectsFitBounds[i]; @@ -1066,12 +1066,12 @@ var viewport = viewer.viewport; assert.propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees"); - viewport.setRotation(90, null, true); + viewport.setRotation(90, true); assert.propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees"); - viewport.setRotation(-75, null, true); + viewport.setRotation(-75, true); assert.propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees"); - viewport.setRotation(0, null, true); + viewport.setRotation(0, true); assert.strictEqual(viewport.getRotation(true), 0, 'viewport has default current rotation'); assert.strictEqual(viewport.getRotation(false), 0, 'viewport has default target rotation'); @@ -1079,7 +1079,7 @@ assert.strictEqual(viewport.getRotation(true), 0, 'current rotation is not changed'); assert.strictEqual(viewport.getRotation(false), 33, 'target rotation is set correctly'); - viewport.setRotation(200, null, true); + viewport.setRotation(200, true); assert.strictEqual(viewport.getRotation(true), 200, 'current rotation is set correctly'); assert.strictEqual(viewport.getRotation(false), 200, 'target rotation is set correctly'); @@ -1099,9 +1099,9 @@ viewport.setFlip(true); assert.propEqual(viewport.getRotation, 0, "Original flipped rotation should be 0 degrees"); - viewport.setRotation(90, null, true); + viewport.setRotation(90, true); assert.propEqual(viewport.getRotation, 90, "Flipped rotation should be 90 degrees"); - viewport.setRotation(-75, null, true); + viewport.setRotation(-75, true); assert.propEqual(viewport.getRotation, -75, "Flipped rotation should be -75 degrees"); done();