2014-10-03 00:20:28 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
var viewer;
|
|
|
|
|
|
|
|
module("viewport", {
|
|
|
|
setup: function () {
|
|
|
|
var example = $('<div id="example"></div>').appendTo("#qunit-fixture");
|
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
|
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: 'example',
|
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
});
|
|
|
|
},
|
|
|
|
teardown: function () {
|
|
|
|
if (viewer && viewer.close) {
|
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
|
|
|
}
|
|
|
|
});
|
2014-10-10 03:58:45 +04:00
|
|
|
// helper
|
|
|
|
var getRandom = function(min, max){
|
|
|
|
return min + Math.floor(Math.random() * (max - min + 1));
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
/*
|
|
|
|
asyncTest('template', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
// do stuff here
|
|
|
|
var orig = ;
|
|
|
|
var expected = ;
|
|
|
|
var actual = ;
|
|
|
|
equal(expected, actual, "what are you testing");
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
*/
|
2014-10-16 04:00:11 +04:00
|
|
|
asyncTest('viewerElementToImageCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
var orig = new OpenSeadragon.Point(
|
|
|
|
getRandom(0, 500), getRandom(0, 500)
|
|
|
|
);
|
|
|
|
// The image is twice as large as the viewer.
|
|
|
|
var expected = orig.times(2);
|
|
|
|
var actual = viewport.viewerElementToImageCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
2014-10-16 03:54:09 +04:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2014-10-15 23:22:52 +04:00
|
|
|
asyncTest('windowToImageCoordinates', function() {
|
2014-10-03 00:20:28 +04:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-10-15 23:22:52 +04:00
|
|
|
var orig = new OpenSeadragon.Point(
|
|
|
|
getRandom(100, 3000), getRandom(100, 3000)
|
|
|
|
);
|
|
|
|
// 500 is the viewer size; there's 20 px of padding (I think)
|
2014-10-16 03:54:09 +04:00
|
|
|
// Multiplying instead of dividing to avoid precision errors
|
|
|
|
var expected = orig.times(0.002).plus( new OpenSeadragon.Point(20, 20) );
|
2014-10-15 23:22:52 +04:00
|
|
|
var actual = viewport.windowToViewportCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2014-10-15 23:22:52 +04:00
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
asyncTest('imageToWindowCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
// test image is 1000 x 1000
|
|
|
|
var orig = new OpenSeadragon.Point(
|
|
|
|
getRandom(0, 1000), getRandom(0, 1000)
|
|
|
|
);
|
2014-10-16 03:54:09 +04:00
|
|
|
// 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) );
|
2014-10-15 22:45:19 +04:00
|
|
|
var actual = viewport.imageToWindowCoordinates(orig);
|
2014-10-16 03:54:09 +04:00
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
2014-10-16 03:54:09 +04:00
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
asyncTest('WindowToViewportCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-10-15 23:22:52 +04:00
|
|
|
var orig = new OpenSeadragon.Point(
|
|
|
|
getRandom(100, 3000), getRandom(100, 3000)
|
|
|
|
);
|
2014-10-10 03:58:45 +04:00
|
|
|
|
|
|
|
// 500 is the viewport container size; there's 20 px of padding (I think)
|
2014-10-16 03:54:09 +04:00
|
|
|
// Multiplying instead of dividing to avoid precision errors
|
|
|
|
var expected = orig.times(0.002).plus( new OpenSeadragon.Point(20, 20) );
|
2014-10-03 00:20:28 +04:00
|
|
|
var actual = viewport.windowToViewportCoordinates(orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToWindowCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-10-15 23:22:52 +04:00
|
|
|
var orig = new OpenSeadragon.Point(
|
|
|
|
getRandom(0, 1000), getRandom(0, 1000)
|
|
|
|
);
|
2014-10-10 03:58:45 +04:00
|
|
|
|
|
|
|
// 500 is the viewport container size; there's 20 px of padding (I think)
|
|
|
|
var expected = orig.minus( new OpenSeadragon.Point(20, 20) ).times(500);
|
2014-10-03 00:20:28 +04:00
|
|
|
var actual = viewport.viewportToWindowCoordinates(orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToImageZoom', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-10-10 03:58:45 +04:00
|
|
|
var orig = getRandom(0, 4);
|
2014-10-15 22:45:19 +04:00
|
|
|
// because the container is 500 x 500 and the image is 1000 x 1000
|
|
|
|
var expected = orig / 2;
|
2014-10-03 00:20:28 +04:00
|
|
|
var actual = viewport.viewportToImageZoom(orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
2014-10-03 00:20:28 +04:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('imageToViewportZoom', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-10-10 03:58:45 +04:00
|
|
|
var orig = getRandom(0, 4);
|
2014-10-15 22:45:19 +04:00
|
|
|
// because the container is 500 x 500 and the image is 1000 x 1000
|
|
|
|
var expected = orig * 2;
|
2014-10-03 00:20:28 +04:00
|
|
|
var actual = viewport.imageToViewportZoom(orig);
|
2014-10-15 22:45:19 +04:00
|
|
|
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
2014-10-03 00:20:28 +04:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open('/test/data/testpattern.dzi');
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|