mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-18 07:43:13 +03:00
Add unit test and fix code review comments.
This commit is contained in:
parent
65b59c08d6
commit
a9f5e7ec73
@ -479,9 +479,9 @@ $.Drawer.prototype = {
|
|||||||
if ( this.viewport.degrees !== 0 ) {
|
if ( this.viewport.degrees !== 0 ) {
|
||||||
this._offsetForRotation(this.viewport.degrees);
|
this._offsetForRotation(this.viewport.degrees);
|
||||||
}
|
}
|
||||||
if (tiledImage.degrees) {
|
if (tiledImage.getRotation() !== 0) {
|
||||||
this._offsetForRotation(
|
this._offsetForRotation(
|
||||||
tiledImage.degrees,
|
tiledImage.getRotation(),
|
||||||
tiledImage.viewport.pixelFromPointNoRotate(
|
tiledImage.viewport.pixelFromPointNoRotate(
|
||||||
tiledImage.getBounds(true).getTopLeft(), true));
|
tiledImage.getBounds(true).getTopLeft(), true));
|
||||||
}
|
}
|
||||||
@ -547,7 +547,7 @@ $.Drawer.prototype = {
|
|||||||
if ( this.viewport.degrees !== 0 ) {
|
if ( this.viewport.degrees !== 0 ) {
|
||||||
this._restoreRotationChanges();
|
this._restoreRotationChanges();
|
||||||
}
|
}
|
||||||
if (tiledImage.degrees) {
|
if (tiledImage.getRotation() !== 0) {
|
||||||
this._restoreRotationChanges();
|
this._restoreRotationChanges();
|
||||||
}
|
}
|
||||||
context.restore();
|
context.restore();
|
||||||
|
@ -132,6 +132,9 @@ $.TiledImage = function( options ) {
|
|||||||
var fitBoundsPlacement = options.fitBoundsPlacement || OpenSeadragon.Placement.CENTER;
|
var fitBoundsPlacement = options.fitBoundsPlacement || OpenSeadragon.Placement.CENTER;
|
||||||
delete options.fitBoundsPlacement;
|
delete options.fitBoundsPlacement;
|
||||||
|
|
||||||
|
this._degrees = $.positiveModulo(options.degrees || 0, 360);
|
||||||
|
delete options.degrees;
|
||||||
|
|
||||||
$.extend( true, this, {
|
$.extend( true, this, {
|
||||||
|
|
||||||
//internal state properties
|
//internal state properties
|
||||||
@ -159,8 +162,7 @@ $.TiledImage = function( options ) {
|
|||||||
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy,
|
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy,
|
||||||
placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle,
|
placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle,
|
||||||
opacity: $.DEFAULT_SETTINGS.opacity,
|
opacity: $.DEFAULT_SETTINGS.opacity,
|
||||||
compositeOperation: $.DEFAULT_SETTINGS.compositeOperation,
|
compositeOperation: $.DEFAULT_SETTINGS.compositeOperation
|
||||||
degrees: 0
|
|
||||||
}, options );
|
}, options );
|
||||||
|
|
||||||
this._xSpring = new $.Spring({
|
this._xSpring = new $.Spring({
|
||||||
@ -280,13 +282,13 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
this._ySpring.current.value,
|
this._ySpring.current.value,
|
||||||
this._worldWidthCurrent,
|
this._worldWidthCurrent,
|
||||||
this._worldHeightCurrent,
|
this._worldHeightCurrent,
|
||||||
this.degrees) :
|
this._degrees) :
|
||||||
new $.Rect(
|
new $.Rect(
|
||||||
this._xSpring.target.value,
|
this._xSpring.target.value,
|
||||||
this._ySpring.target.value,
|
this._ySpring.target.value,
|
||||||
this._worldWidthTarget,
|
this._worldWidthTarget,
|
||||||
this._worldHeightTarget,
|
this._worldHeightTarget,
|
||||||
this.degrees);
|
this._degrees);
|
||||||
},
|
},
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
@ -311,7 +313,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
bounds.y + clip.y,
|
bounds.y + clip.y,
|
||||||
clip.width,
|
clip.width,
|
||||||
clip.height,
|
clip.height,
|
||||||
this.degrees);
|
this._degrees);
|
||||||
}
|
}
|
||||||
return bounds;
|
return bounds;
|
||||||
},
|
},
|
||||||
@ -698,7 +700,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
* @returns {Number} the current rotation of this tiled image in degrees.
|
* @returns {Number} the current rotation of this tiled image in degrees.
|
||||||
*/
|
*/
|
||||||
getRotation: function() {
|
getRotation: function() {
|
||||||
return this.degrees;
|
return this._degrees;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -706,8 +708,13 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
* @param {Number} the rotation in degrees.
|
* @param {Number} the rotation in degrees.
|
||||||
*/
|
*/
|
||||||
setRotation: function(degrees) {
|
setRotation: function(degrees) {
|
||||||
this.degrees = $.positiveModulo(degrees, 360);
|
degrees = $.positiveModulo(degrees, 360);
|
||||||
|
if (this._degrees === degrees) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._degrees = degrees;
|
||||||
this._needsDraw = true;
|
this._needsDraw = true;
|
||||||
|
this._raiseBoundsChange();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1498,9 +1505,9 @@ function drawTiles( tiledImage, lastDrawn ) {
|
|||||||
tiledImage._drawer._offsetForRotation(
|
tiledImage._drawer._offsetForRotation(
|
||||||
tiledImage.viewport.degrees, useSketch);
|
tiledImage.viewport.degrees, useSketch);
|
||||||
}
|
}
|
||||||
if (tiledImage.degrees !== 0) {
|
if (tiledImage._degrees !== 0) {
|
||||||
tiledImage._drawer._offsetForRotation(
|
tiledImage._drawer._offsetForRotation(
|
||||||
tiledImage.degrees,
|
tiledImage._degrees,
|
||||||
tiledImage.viewport.pixelFromPointNoRotate(
|
tiledImage.viewport.pixelFromPointNoRotate(
|
||||||
tiledImage.getBounds(true).getTopLeft(), true),
|
tiledImage.getBounds(true).getTopLeft(), true),
|
||||||
useSketch);
|
useSketch);
|
||||||
@ -1573,7 +1580,7 @@ function drawTiles( tiledImage, lastDrawn ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sketchScale) {
|
if (!sketchScale) {
|
||||||
if (tiledImage.degrees !== 0) {
|
if (tiledImage._degrees !== 0) {
|
||||||
tiledImage._drawer._restoreRotationChanges(useSketch);
|
tiledImage._drawer._restoreRotationChanges(useSketch);
|
||||||
}
|
}
|
||||||
if (tiledImage.viewport.degrees !== 0) {
|
if (tiledImage.viewport.degrees !== 0) {
|
||||||
@ -1587,9 +1594,9 @@ function drawTiles( tiledImage, lastDrawn ) {
|
|||||||
tiledImage._drawer._offsetForRotation(
|
tiledImage._drawer._offsetForRotation(
|
||||||
tiledImage.viewport.degrees, false);
|
tiledImage.viewport.degrees, false);
|
||||||
}
|
}
|
||||||
if (tiledImage.degrees !== 0) {
|
if (tiledImage._degrees !== 0) {
|
||||||
tiledImage._drawer._offsetForRotation(
|
tiledImage._drawer._offsetForRotation(
|
||||||
tiledImage.degrees,
|
tiledImage._degrees,
|
||||||
tiledImage.viewport.pixelFromPointNoRotate(
|
tiledImage.viewport.pixelFromPointNoRotate(
|
||||||
tiledImage.getBounds(true).getTopLeft(), true),
|
tiledImage.getBounds(true).getTopLeft(), true),
|
||||||
useSketch);
|
useSketch);
|
||||||
@ -1603,7 +1610,7 @@ function drawTiles( tiledImage, lastDrawn ) {
|
|||||||
bounds: bounds
|
bounds: bounds
|
||||||
});
|
});
|
||||||
if (sketchScale) {
|
if (sketchScale) {
|
||||||
if (tiledImage.degrees !== 0) {
|
if (tiledImage._degrees !== 0) {
|
||||||
tiledImage._drawer._restoreRotationChanges(false);
|
tiledImage._drawer._restoreRotationChanges(false);
|
||||||
}
|
}
|
||||||
if (tiledImage.viewport.degrees !== 0) {
|
if (tiledImage.viewport.degrees !== 0) {
|
||||||
|
@ -1228,6 +1228,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
* (portions of the image outside of this area will not be visible). Only works on
|
* (portions of the image outside of this area will not be visible). Only works on
|
||||||
* browsers that support the HTML5 canvas.
|
* browsers that support the HTML5 canvas.
|
||||||
* @param {Number} [options.opacity] Opacity the tiled image should be drawn at by default.
|
* @param {Number} [options.opacity] Opacity the tiled image should be drawn at by default.
|
||||||
|
* @param {Number} [options.degrees=0] Initial rotation of the tiled image around
|
||||||
|
* it top left corner in degrees.
|
||||||
* @param {String} [options.compositeOperation] How the image is composited onto other images.
|
* @param {String} [options.compositeOperation] How the image is composited onto other images.
|
||||||
* @param {String} [options.crossOriginPolicy] The crossOriginPolicy for this specific image,
|
* @param {String} [options.crossOriginPolicy] The crossOriginPolicy for this specific image,
|
||||||
* overriding viewer.crossOriginPolicy.
|
* overriding viewer.crossOriginPolicy.
|
||||||
|
@ -292,6 +292,35 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ----------
|
||||||
|
asyncTest('rotation', function() {
|
||||||
|
|
||||||
|
function testDefaultRotation() {
|
||||||
|
var image = viewer.world.getItemAt(0);
|
||||||
|
strictEqual(image.getRotation(), 0, 'image has default rotation');
|
||||||
|
|
||||||
|
image.setRotation(400);
|
||||||
|
strictEqual(image.getRotation(), 40, 'rotation is set correctly');
|
||||||
|
|
||||||
|
viewer.addOnceHandler('open', testTileSourceRotation);
|
||||||
|
viewer.open({
|
||||||
|
tileSource: '/test/data/testpattern.dzi',
|
||||||
|
degrees: -60
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTileSourceRotation() {
|
||||||
|
var image = viewer.world.getItemAt(0);
|
||||||
|
strictEqual(image.getRotation(), 300, 'image has correct rotation');
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
viewer.addOnceHandler('open', testDefaultRotation);
|
||||||
|
viewer.open({
|
||||||
|
tileSource: '/test/data/testpattern.dzi',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
asyncTest('fitBounds', function() {
|
asyncTest('fitBounds', function() {
|
||||||
|
|
||||||
function assertRectEquals(actual, expected, message) {
|
function assertRectEquals(actual, expected, message) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user