imageToViewerElementCoordinates and imageToWindowCoordinates

This commit is contained in:
nein09 2014-10-15 16:54:09 -07:00
parent 38e9a4b10b
commit c6dd2f213d

View File

@ -47,6 +47,26 @@
viewer.open('/test/data/testpattern.dzi'); 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() { asyncTest('windowToImageCoordinates', function() {
var openHandler = function(event) { var openHandler = function(event) {
viewer.removeHandler('open', openHandler); viewer.removeHandler('open', openHandler);
@ -56,7 +76,8 @@
getRandom(100, 3000), getRandom(100, 3000) getRandom(100, 3000), getRandom(100, 3000)
); );
// 500 is the viewer size; there's 20 px of padding (I think) // 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); var actual = viewport.windowToViewportCoordinates(orig);
propEqual(actual, expected, "Coordinates converted correctly for " + orig); propEqual(actual, expected, "Coordinates converted correctly for " + orig);
@ -66,7 +87,6 @@
viewer.open('/test/data/testpattern.dzi'); viewer.open('/test/data/testpattern.dzi');
}); });
/* Need imagetoViewerElementCoordinates first to figure out this one
asyncTest('imageToWindowCoordinates', function() { asyncTest('imageToWindowCoordinates', function() {
var openHandler = function(event) { var openHandler = function(event) {
viewer.removeHandler('open', openHandler); viewer.removeHandler('open', openHandler);
@ -76,17 +96,18 @@
var orig = new OpenSeadragon.Point( var orig = new OpenSeadragon.Point(
getRandom(0, 1000), getRandom(0, 1000) getRandom(0, 1000), getRandom(0, 1000)
); );
var expected = orig.plus( new OpenSeadragon.Point(20, 20) ); // The image is twice as large as the viewer.
console.log(expected); // 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); var actual = viewport.imageToWindowCoordinates(orig);
console.log(actual); propEqual(actual, expected, "Coordinates converted correctly for " + orig);
ok(actual.equals(expected), "Coordinates converted correctly for " + orig);
start(); start();
}; };
viewer.addHandler('open', openHandler); viewer.addHandler('open', openHandler);
viewer.open('/test/data/testpattern.dzi'); viewer.open('/test/data/testpattern.dzi');
});*/ });
asyncTest('WindowToViewportCoordinates', function() { asyncTest('WindowToViewportCoordinates', function() {
var openHandler = function(event) { var openHandler = function(event) {
@ -98,7 +119,8 @@
); );
// 500 is the viewport container size; there's 20 px of padding (I think) // 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); var actual = viewport.windowToViewportCoordinates(orig);
propEqual(actual, expected, "Coordinates converted correctly for " + orig); propEqual(actual, expected, "Coordinates converted correctly for " + orig);