2014-12-12 23:51:50 +03:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual */
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
var viewer;
|
2014-11-19 00:05:58 +03:00
|
|
|
var VIEWER_ID = "example";
|
|
|
|
var PREFIX_URL = "/build/openseadragon/images";
|
|
|
|
var SPRING_STIFFNESS = 100; // Faster animation = faster tests
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
module("viewport", {
|
|
|
|
setup: function () {
|
|
|
|
var example = $('<div id="example"></div>').appendTo("#qunit-fixture");
|
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
|
|
|
|
viewer = OpenSeadragon({
|
2014-11-19 00:05:58 +03:00
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
teardown: function () {
|
|
|
|
if (viewer && viewer.close) {
|
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
|
|
|
}
|
|
|
|
});
|
2014-10-28 03:58:59 +03:00
|
|
|
|
|
|
|
// helpers and constants
|
2014-10-24 03:13:02 +04:00
|
|
|
|
|
|
|
var ZOOM_FACTOR = 2; // the image will be twice as large as the viewer.
|
2014-12-14 22:08:54 +03:00
|
|
|
var VIEWER_PADDING = new OpenSeadragon.Point(0.25, 0.25);
|
2014-12-12 23:51:50 +03:00
|
|
|
var DZI_PATH = '/test/data/testpattern.dzi';
|
|
|
|
var TALL_PATH = '/test/data/tall.dzi';
|
2014-10-03 00:20:28 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var testZoomLevels = [-1, 0, 0.1, 0.5, 4, 10];
|
|
|
|
|
|
|
|
var testPoints = [
|
|
|
|
new OpenSeadragon.Point(0, 0),
|
|
|
|
new OpenSeadragon.Point(0.001, 0.001),
|
|
|
|
new OpenSeadragon.Point(0.25, 0.5),
|
2014-10-29 19:42:19 +03:00
|
|
|
new OpenSeadragon.Point(0.99, 0.99),
|
2014-10-28 03:58:59 +03:00
|
|
|
new OpenSeadragon.Point(1, 1)
|
|
|
|
];
|
|
|
|
|
|
|
|
var testRects = [
|
|
|
|
new OpenSeadragon.Rect(0, 0, 0, 0),
|
|
|
|
new OpenSeadragon.Rect(0.001, 0.005, 0.001, 0.003),
|
|
|
|
new OpenSeadragon.Rect(0.25, 0.25, 0.25, 0.25),
|
|
|
|
new OpenSeadragon.Rect(0.999, 0.999, 0.999, 0.999),
|
|
|
|
new OpenSeadragon.Rect(1, 1, 1, 1)
|
|
|
|
];
|
|
|
|
|
2014-10-03 00:20:28 +04:00
|
|
|
// ----------
|
|
|
|
/*
|
|
|
|
asyncTest('template', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
*/
|
2014-11-14 04:19:36 +03:00
|
|
|
asyncTest('getContainerSize', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-14 04:19:36 +03:00
|
|
|
|
2014-12-12 23:51:50 +03:00
|
|
|
propEqual(viewport.getContainerSize(), new OpenSeadragon.Point(500, 500), "Test container size");
|
2014-11-14 04:19:36 +03:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2014-11-13 20:04:11 +03:00
|
|
|
asyncTest('getAspectRatio', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-13 20:04:11 +03:00
|
|
|
|
2014-12-12 23:51:50 +03:00
|
|
|
equal(viewport.getAspectRatio(), 1, "Test aspect ratio");
|
2014-11-13 20:04:11 +03:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2014-11-13 19:55:15 +03:00
|
|
|
asyncTest('getMinZoomDefault', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-12-14 22:08:54 +03:00
|
|
|
equal(viewport.getMinZoom(), 0.9, "Test default min zoom level");
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getMaxZoomDefault', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-12-12 23:51:50 +03:00
|
|
|
equal(viewport.getMaxZoom(), 2.2, "Test default max zoom level");
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getMinZoom', function() {
|
|
|
|
var expected, level, i = 0;
|
|
|
|
var openHandler = function(event) {
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-12-12 23:51:50 +03:00
|
|
|
if(level === 0) { // 0 means use the default
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 0.9;
|
2014-11-19 00:05:58 +03:00
|
|
|
} else if(level > 1){
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 1; // min zoom won't go bigger than 1.
|
|
|
|
}
|
|
|
|
|
|
|
|
equal(
|
|
|
|
viewport.getMinZoom(),
|
|
|
|
expected,
|
|
|
|
"Test getMinZoom with zoom level of " + level
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS,
|
|
|
|
minZoomLevel: level
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.minZoomLevel = level;
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getMaxZoom', function() {
|
|
|
|
var expected, level, i = 0;
|
|
|
|
var openHandler = function(event) {
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2014-12-12 23:51:50 +03:00
|
|
|
if(level === 0){ // 0 means use the default
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 2.2;
|
2014-11-19 00:05:58 +03:00
|
|
|
} else if(level < 1){
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 1; // max zoom won't go smaller than 1.
|
|
|
|
}
|
|
|
|
|
|
|
|
equal(
|
|
|
|
viewport.getMaxZoom(),
|
|
|
|
expected,
|
|
|
|
"Test getMaxZoom with zoom level of " + level
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS,
|
|
|
|
maxZoomLevel: level
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.maxZoomLevel = level;
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeBounds', function() {
|
|
|
|
var expected, i = 0;
|
|
|
|
var openHandler = function(event) {
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-13 19:55:15 +03:00
|
|
|
|
|
|
|
// Have to special case this to avoid dividing by 0
|
2014-12-12 23:51:50 +03:00
|
|
|
if(testZoomLevels[i] === 0){
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = new OpenSeadragon.Rect(0, 0, 1, 1);
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
var sideLength = 1.0 / viewer.defaultZoomLevel; // it's a square in this case
|
|
|
|
var position = 0.5 - (sideLength / 2.0);
|
|
|
|
expected = new OpenSeadragon.Rect(position, position, sideLength, sideLength);
|
|
|
|
}
|
|
|
|
propEqual(
|
|
|
|
viewport.getHomeBounds(),
|
|
|
|
expected,
|
|
|
|
"Test getHomeBounds with default zoom level of " + viewer.defaultZoomLevel
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS,
|
|
|
|
defaultZoomLevel: testZoomLevels[i]
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.defaultZoomLevel = testZoomLevels[i];
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeZoom', function() {
|
|
|
|
var expected, i = 0;
|
|
|
|
var openHandler = function(event) {
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-13 19:55:15 +03:00
|
|
|
|
|
|
|
// If the default zoom level is set to 0, then we expect the home zoom to be 1.
|
2014-12-12 23:51:50 +03:00
|
|
|
if(expected === 0){
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 1;
|
|
|
|
}
|
|
|
|
equal(
|
|
|
|
viewport.getHomeZoom(),
|
|
|
|
expected,
|
|
|
|
"Test getHomeZoom with default zoom level of " + expected
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
|
|
|
expected = testZoomLevels[i];
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS,
|
|
|
|
defaultZoomLevel: expected
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
expected = testZoomLevels[i];
|
|
|
|
viewer.defaultZoomLevel = expected;
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeZoomWithHomeFillsViewer', function() {
|
2014-11-19 00:05:58 +03:00
|
|
|
var expected, level, i = 0;
|
2014-11-13 19:55:15 +03:00
|
|
|
var openHandler = function(event) {
|
2014-11-19 00:05:58 +03:00
|
|
|
viewer.removeHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-13 19:55:15 +03:00
|
|
|
|
|
|
|
// If the default zoom level is set to 0, then we expect the home zoom to be 1.
|
2014-12-12 23:51:50 +03:00
|
|
|
if(level === 0){
|
2014-11-13 19:55:15 +03:00
|
|
|
expected = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
equal(
|
|
|
|
viewport.getHomeZoom(),
|
|
|
|
expected,
|
|
|
|
"Test getHomeZoom with homeFillsViewer = true and default zoom level of " + expected
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
|
|
|
viewer = OpenSeadragon({
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS,
|
|
|
|
defaultZoomLevel: level,
|
|
|
|
homeFillsViewer: true
|
|
|
|
});
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.open(TALL_PATH); // use a different image for homeFillsViewer
|
2014-11-19 00:05:58 +03:00
|
|
|
} else {
|
2014-11-13 19:55:15 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-11-19 00:05:58 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
2014-11-13 19:55:15 +03:00
|
|
|
viewer.homeFillsViewer = true;
|
|
|
|
viewer.defaultZoomLevel = expected;
|
|
|
|
viewer.open(TALL_PATH); // use a different image for homeFillsViewer
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('deltaPixelsFromPoints', function() {
|
2014-11-07 05:30:24 +03:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-07 05:30:24 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
|
|
|
expected = orig.times(viewport.getContainerSize().x * ZOOM_FACTOR);
|
|
|
|
actual = viewport.deltaPixelsFromPoints(orig);
|
2014-12-14 22:08:54 +03:00
|
|
|
propEqual(actual, expected, "Correctly got delta pixels from points" + orig);
|
2014-11-07 05:30:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('deltaPointsFromPixels', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-11-07 05:30:24 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewport.getContainerSize().x);
|
|
|
|
|
|
|
|
expected = orig.divide(viewport.getContainerSize().x * ZOOM_FACTOR);
|
|
|
|
actual = viewport.deltaPointsFromPixels(orig);
|
2014-12-14 22:08:54 +03:00
|
|
|
propEqual(actual, expected, "Correctly got delta points from pixels " + orig);
|
2014-11-07 05:30:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
asyncTest('pixelFromPoint', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-30 07:10:15 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.plus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).minus(viewport.getContainerSize());
|
2014-10-30 07:10:15 +03:00
|
|
|
actual = viewport.pixelFromPoint(orig, false);
|
|
|
|
propEqual(
|
|
|
|
actual,
|
|
|
|
expected,
|
2014-12-14 22:08:54 +03:00
|
|
|
"Correctly converted coordinates " + orig
|
2014-10-30 07:10:15 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('pointFromPixel', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-30 07:10:15 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewport.getContainerSize().x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.divide(viewer.source.dimensions.x).plus(VIEWER_PADDING);
|
2014-10-30 07:10:15 +03:00
|
|
|
actual = viewport.pointFromPixel(orig, false);
|
|
|
|
propEqual(
|
|
|
|
actual,
|
|
|
|
expected,
|
2014-12-14 22:08:54 +03:00
|
|
|
"Correctly converted coordinates " + orig
|
2014-10-30 07:10:15 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
asyncTest('viewportToImageCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-30 07:10:15 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewport.getContainerSize().x);
|
|
|
|
expected = orig.divide(viewer.source.dimensions.x);
|
|
|
|
actual = viewport.imageToViewportCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('imageToViewportCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-30 07:10:15 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
|
|
|
expected = orig.divide(ZOOM_FACTOR * viewport.getContainerSize().x);
|
|
|
|
actual = viewport.imageToViewportCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
2014-10-24 03:13:02 +04:00
|
|
|
asyncTest('imageToViewportRectangle', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-24 03:13:02 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testRects.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testRects[i].times(viewer.source.dimensions.x);
|
2014-10-28 03:58:59 +03:00
|
|
|
expected = new OpenSeadragon.Rect(
|
2014-10-29 19:42:19 +03:00
|
|
|
orig.x / viewer.source.dimensions.x,
|
|
|
|
orig.y / viewer.source.dimensions.x,
|
|
|
|
orig.width / viewer.source.dimensions.x,
|
|
|
|
orig.height / viewer.source.dimensions.x
|
2014-10-28 03:58:59 +03:00
|
|
|
);
|
|
|
|
actual = viewport.imageToViewportRectangle(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-24 03:13:02 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-24 03:13:02 +04:00
|
|
|
});
|
|
|
|
|
2014-10-21 22:19:41 +04:00
|
|
|
asyncTest('viewportToImageRectangle', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-21 22:19:41 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testRects.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testRects[i].times(viewport.getContainerSize().x);
|
2014-10-28 03:58:59 +03:00
|
|
|
expected = new OpenSeadragon.Rect(
|
2014-10-29 19:42:19 +03:00
|
|
|
orig.x * viewer.source.dimensions.x,
|
|
|
|
orig.y * viewer.source.dimensions.x,
|
|
|
|
orig.width * viewer.source.dimensions.x,
|
|
|
|
orig.height * viewer.source.dimensions.x
|
2014-10-28 03:58:59 +03:00
|
|
|
);
|
|
|
|
actual = viewport.viewportToImageRectangle(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-21 22:19:41 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-21 22:19:41 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewerElementToImageCoordinates', function() {
|
2014-10-16 04:00:11 +04:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-16 04:00:11 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(viewport.getContainerSize().x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.plus(viewport.getContainerSize().divide(2));
|
2014-10-28 03:58:59 +03:00
|
|
|
actual = viewport.viewerElementToImageCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-16 04:00:11 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-16 04:00:11 +04:00
|
|
|
});
|
|
|
|
|
2014-10-16 03:54:09 +04:00
|
|
|
asyncTest('imageToViewerElementCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-16 03:54:09 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.minus(viewport.getContainerSize().divide(2));
|
2014-10-28 03:58:59 +03:00
|
|
|
actual = viewport.imageToViewerElementCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-16 03:54:09 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-16 03:54:09 +04:00
|
|
|
});
|
|
|
|
|
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-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-03 00:20:28 +04:00
|
|
|
|
2014-10-29 19:42:19 +03:00
|
|
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
2014-12-14 22:08:54 +03:00
|
|
|
var orig, expected, actual, position, pos_point;
|
|
|
|
position = viewer.element.getBoundingClientRect();
|
|
|
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
2014-10-28 03:58:59 +03:00
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(window_boundary);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
2014-10-28 03:58:59 +03:00
|
|
|
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);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
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;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-15 22:45:19 +04:00
|
|
|
|
2014-12-14 22:08:54 +03:00
|
|
|
var position, orig, expected, actual, pos_point;
|
|
|
|
position = viewer.element.getBoundingClientRect();
|
|
|
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
2014-10-28 03:58:59 +03:00
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.plus(pos_point).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
|
2014-10-28 03:58:59 +03:00
|
|
|
actual = viewport.imageToWindowCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-16 03:54:09 +04:00
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
|
2014-10-29 19:42:19 +03:00
|
|
|
asyncTest('windowToViewportCoordinates', function() {
|
2014-10-15 22:45:19 +04:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-15 22:45:19 +04:00
|
|
|
|
2014-10-29 19:42:19 +03:00
|
|
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
2014-12-14 22:08:54 +03:00
|
|
|
var orig, expected, actual, position;
|
|
|
|
position = viewer.element.getBoundingClientRect();
|
|
|
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
2014-10-28 03:58:59 +03:00
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(window_boundary);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
2014-10-28 03:58:59 +03:00
|
|
|
actual = viewport.windowToViewportCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToWindowCoordinates', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-03 00:20:28 +04:00
|
|
|
|
2014-12-14 22:08:54 +03:00
|
|
|
var orig, expected, actual, position;
|
|
|
|
position = viewer.element.getBoundingClientRect();
|
|
|
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
2014-10-28 03:58:59 +03:00
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
2014-10-29 19:42:19 +03:00
|
|
|
orig = testPoints[i].times(viewer.source.dimensions.x);
|
2014-12-14 22:08:54 +03:00
|
|
|
expected = orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(pos_point);
|
2014-10-28 03:58:59 +03:00
|
|
|
actual = viewport.viewportToWindowCoordinates(orig);
|
|
|
|
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToImageZoom', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-03 00:20:28 +04:00
|
|
|
|
2014-10-28 03:58:59 +03:00
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testZoomLevels[i];
|
|
|
|
expected = orig / ZOOM_FACTOR;
|
|
|
|
actual = viewport.viewportToImageZoom(orig);
|
|
|
|
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('imageToViewportZoom', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-10-24 03:13:02 +04:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2014-12-14 22:08:54 +03:00
|
|
|
viewport.update(); // need to call this even with immediately=true
|
2014-10-28 03:58:59 +03:00
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
orig = testZoomLevels[i];
|
|
|
|
expected = orig * ZOOM_FACTOR;
|
|
|
|
actual = viewport.imageToViewportZoom(orig);
|
|
|
|
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
2014-10-29 19:42:19 +03:00
|
|
|
})();
|