From c6dd2f213d642963ca9454497d187665ad9cb419 Mon Sep 17 00:00:00 2001 From: nein09 Date: Wed, 15 Oct 2014 16:54:09 -0700 Subject: [PATCH] imageToViewerElementCoordinates and imageToWindowCoordinates --- test/viewport.js | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/test/viewport.js b/test/viewport.js index 5d822abd..941ea3d3 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -47,6 +47,26 @@ viewer.open('/test/data/testpattern.dzi'); }); */ + asyncTest('imageToViewerElementCoordinates', function() { + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + var orig = new OpenSeadragon.Point( + getRandom(0, 1000), getRandom(0, 1000) + ); + // The image is twice as large as the viewer. + // Multiplying instead of dividing to avoid precision errors + var expected = orig.times(0.500); + var actual = viewport.imageToViewerElementCoordinates(orig); + propEqual(actual, expected, "Coordinates converted correctly for " + orig); + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open('/test/data/testpattern.dzi'); + }); + asyncTest('windowToImageCoordinates', function() { var openHandler = function(event) { viewer.removeHandler('open', openHandler); @@ -56,7 +76,8 @@ getRandom(100, 3000), getRandom(100, 3000) ); // 500 is the viewer size; there's 20 px of padding (I think) - var expected = orig.divide(500).plus( new OpenSeadragon.Point(20, 20) ); + // Multiplying instead of dividing to avoid precision errors + var expected = orig.times(0.002).plus( new OpenSeadragon.Point(20, 20) ); var actual = viewport.windowToViewportCoordinates(orig); propEqual(actual, expected, "Coordinates converted correctly for " + orig); @@ -66,7 +87,6 @@ viewer.open('/test/data/testpattern.dzi'); }); -/* Need imagetoViewerElementCoordinates first to figure out this one asyncTest('imageToWindowCoordinates', function() { var openHandler = function(event) { viewer.removeHandler('open', openHandler); @@ -76,17 +96,18 @@ var orig = new OpenSeadragon.Point( getRandom(0, 1000), getRandom(0, 1000) ); - var expected = orig.plus( new OpenSeadragon.Point(20, 20) ); - console.log(expected); + // The image is twice as large as the viewer. + // Multiplying instead of dividing to avoid precision errors + // don't know why I have to subtract 10000 though. + var expected = orig.times(0.500).minus( new OpenSeadragon.Point(10000, 10000) ); var actual = viewport.imageToWindowCoordinates(orig); - console.log(actual); - ok(actual.equals(expected), "Coordinates converted correctly for " + orig); + propEqual(actual, expected, "Coordinates converted correctly for " + orig); start(); }; viewer.addHandler('open', openHandler); viewer.open('/test/data/testpattern.dzi'); - });*/ + }); asyncTest('WindowToViewportCoordinates', function() { var openHandler = function(event) { @@ -98,7 +119,8 @@ ); // 500 is the viewport container size; there's 20 px of padding (I think) - var expected = orig.divide(500).plus( new OpenSeadragon.Point(20, 20) ); + // Multiplying instead of dividing to avoid precision errors + var expected = orig.times(0.002).plus( new OpenSeadragon.Point(20, 20) ); var actual = viewport.windowToViewportCoordinates(orig); propEqual(actual, expected, "Coordinates converted correctly for " + orig);