From b8a1762a95a5e4375fe6cd2e452877d118cc36dc Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Fri, 21 Nov 2014 17:05:14 -0800 Subject: [PATCH] Unit tests for TiledImage unit conversion --- test/modules/tiledimage.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index 186d6686..4901de01 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual */ (function() { var viewer; @@ -45,6 +45,20 @@ checkBounds(image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); + var scale = image.getContentSize().x / image.getBounds().width; + var viewportPoint = new OpenSeadragon.Point(10, 11); + var imagePoint = viewportPoint.minus(image.getBounds().getTopLeft()).times(scale); + + propEqual(image.viewportToImageCoordinates(viewportPoint), imagePoint, 'viewportToImageCoordinates'); + propEqual(image.imageToViewportCoordinates(imagePoint), viewportPoint, 'imageToViewportCoordinates'); + + var viewportRect = new OpenSeadragon.Rect(viewportPoint.x, viewportPoint.y, 6, 7); + var imageRect = new OpenSeadragon.Rect(imagePoint.x, imagePoint.y, + viewportRect.width * scale, viewportRect.height * scale); + + propEqual(image.viewportToImageRectangle(viewportRect), imageRect, 'viewportToImageRectangle'); + propEqual(image.imageToViewportRectangle(imageRect), viewportRect, 'imageToViewportRectangle'); + image.addHandler('bounds-change', function boundsChangeHandler(event) { image.removeHandler('bounds-change', boundsChangeHandler); handlerCount++;