diff --git a/src/viewport.js b/src/viewport.js index 65230f4a..9049e3d6 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -920,12 +920,12 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ /** * Convert pixel coordinates relative to the image to * viewer element coordinates. - * @param {OpenSeadragon.Point} point + * @param {OpenSeadragon.Point} pixel * @returns {OpenSeadragon.Point} */ - imageToViewerElementCoordinates: function( point ) { - var pixel = this.pixelFromPoint( point, true ); - return this.imageToViewportCoordinates( pixel ); + imageToViewerElementCoordinates: function( pixel ) { + var point = this.imageToViewportCoordinates( pixel ); + return this.pixelFromPoint( point, true ); }, /** diff --git a/test/units.js b/test/units.js index 348835b3..1ce10a09 100644 --- a/test/units.js +++ b/test/units.js @@ -26,12 +26,34 @@ function pointEqual(a, b, message) { - ok(a.x === b.x && a.y === b.y, message); + Util.assessNumericValue(a.x, b.x, 0.00000001, message); + Util.assessNumericValue(a.y, b.y, 0.00000001, message); } // ---------- asyncTest('Coordinates conversions', function() { + function checkPoint(context) { + var viewport = viewer.viewport; + + var point = new OpenSeadragon.Point(15, 12); + var result = viewport.viewerElementToImageCoordinates( + viewport.imageToViewerElementCoordinates(point)); + pointEqual(result, point, 'viewerElement and image ' + context); + + var result = viewport.windowToImageCoordinates( + viewport.imageToWindowCoordinates(point)); + pointEqual(result, point, 'window and image ' + context); + + var result = viewport.viewerElementToViewportCoordinates( + viewport.viewportToViewerElementCoordinates(point)); + pointEqual(result, point, 'viewerElement and viewport ' + context); + + var result = viewport.windowToViewportCoordinates( + viewport.viewportToWindowCoordinates(point)); + pointEqual(result, point, 'window and viewport ' + context); + } + viewer.addHandler("open", function () { var viewport = viewer.viewport; @@ -52,24 +74,13 @@ var pixel = viewport.viewerElementToImageCoordinates(viewerTopRight); pointEqual(pixel, imageTopRight, 'Viewer top right has viewport coordinates imageWidth,0.'); - var point = new OpenSeadragon.Point(15, 12); - var result = viewport.viewerElementToImageCoordinates( - viewport.imageToViewerElementCoordinates(point)); - pointEqual(result, point, 'viewerElement and image'); - - var result = viewport.windowToImageCoordinates( - viewport.imageToWindowCoordinates(point)); - pointEqual(result, point, 'window and image'); - - var result = viewport.viewerElementToViewportCoordinates( - viewport.viewportToViewerElementCoordinates(point)); - pointEqual(result, point, 'viewerElement and viewport'); - - var result = viewport.windowToViewportCoordinates( - viewport.viewportToWindowCoordinates(point)); - pointEqual(result, point, 'window and viewport'); - - start(); + checkPoint('after opening'); + viewer.addHandler('animation-finish', function animationHandler() { + viewer.removeHandler('animation-finish', animationHandler); + checkPoint('after zoom and pan'); + start(); + }); + viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2)); }); viewer.open('/test/data/testpattern.dzi'); }); @@ -104,14 +115,13 @@ checkZoom(); var zoomHandler = function() { - viewer.removeHandler('animationfinish', zoomHandler); + viewer.removeHandler('animation-finish', zoomHandler); checkZoom(); start(); }; - viewer.addHandler('animationfinish', zoomHandler); + viewer.addHandler('animation-finish', zoomHandler); viewport.zoomTo(2); - start(); }); viewer.open('/test/data/testpattern.dzi');