2015-01-20 02:51:55 +03:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual, console */
|
2014-10-03 00:20:28 +04:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
var viewer;
|
2014-11-19 00:05:58 +03:00
|
|
|
var VIEWER_ID = "example";
|
2015-01-03 01:24:05 +03:00
|
|
|
var PREFIX_URL = "/build/openseadragon/images/";
|
2014-11-19 00:05:58 +03:00
|
|
|
var SPRING_STIFFNESS = 100; // Faster animation = faster tests
|
2016-05-05 05:26:33 +03:00
|
|
|
var EPSILON = 0.0000000001;
|
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';
|
2015-01-17 03:14:18 +03:00
|
|
|
var WIDE_PATH = '/test/data/wide.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-12-15 00:15:50 +03:00
|
|
|
// Test helper - a lot of these tests loop through a few possible
|
|
|
|
// values for zoom levels, and reopen the viewer for each iteration.
|
|
|
|
var reopenViewerHelper = function(config) {
|
|
|
|
var expected, level, actual, i = 0;
|
2014-10-03 00:20:28 +04:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2014-12-15 00:15:50 +03:00
|
|
|
expected = config.processExpected(level, expected);
|
|
|
|
actual = viewport[config.method]();
|
2014-10-03 00:20:28 +04:00
|
|
|
|
2014-12-15 00:15:50 +03:00
|
|
|
propEqual(
|
|
|
|
actual,
|
|
|
|
expected,
|
|
|
|
"Test " + config.method + " with zoom level of " + level + ". Expected : " + expected + ", got " + actual
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
if(i < testZoomLevels.length){
|
|
|
|
level = expected = testZoomLevels[i];
|
|
|
|
var viewerConfig = {
|
|
|
|
id: VIEWER_ID,
|
|
|
|
prefixUrl: PREFIX_URL,
|
|
|
|
springStiffness: SPRING_STIFFNESS
|
|
|
|
};
|
|
|
|
|
|
|
|
viewerConfig[config.property] = level;
|
|
|
|
viewer = OpenSeadragon(viewerConfig);
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
} else {
|
|
|
|
start();
|
|
|
|
}
|
2014-10-03 00:20:28 +04:00
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
2014-12-15 00:15:50 +03:00
|
|
|
level = expected = testZoomLevels[i];
|
|
|
|
viewer[config.property] = level;
|
2014-10-29 19:42:19 +03:00
|
|
|
viewer.open(DZI_PATH);
|
2014-12-15 00:15:50 +03:00
|
|
|
};
|
|
|
|
|
2014-12-15 20:41:32 +03:00
|
|
|
// Test helper - a lot of these tests loop through a test data
|
|
|
|
// array and test different values. This helper does not reopen the viewer.
|
|
|
|
var loopingTestHelper = function(config) {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
|
|
|
|
|
|
|
var orig, expected, actual;
|
|
|
|
for (var i = 0; i < config.testArray.length; i++){
|
|
|
|
orig = config.getOrig(config.testArray[i], viewport);
|
|
|
|
expected = config.getExpected(orig, viewport);
|
|
|
|
actual = viewport[config.method](orig);
|
|
|
|
propEqual(
|
|
|
|
actual,
|
|
|
|
expected,
|
|
|
|
"Correctly converted coordinates " + orig
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
};
|
|
|
|
|
2014-12-15 00:15:50 +03:00
|
|
|
// Tests start here.
|
2015-01-15 23:36:01 +03: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-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-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() {
|
2014-12-15 00:15:50 +03:00
|
|
|
reopenViewerHelper({
|
|
|
|
property: 'minZoomLevel',
|
|
|
|
method: 'getMinZoom',
|
|
|
|
processExpected: function(level, expected){
|
|
|
|
if(level === 0) { // 0 means use the default
|
|
|
|
expected = 0.9;
|
|
|
|
} else if(level > 1) {
|
|
|
|
expected = 1; // min zoom won't go bigger than 1.
|
|
|
|
}
|
|
|
|
return expected;
|
2014-11-13 19:55:15 +03:00
|
|
|
}
|
2014-12-15 00:15:50 +03:00
|
|
|
});
|
2014-11-13 19:55:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getMaxZoom', function() {
|
2014-12-15 00:15:50 +03:00
|
|
|
reopenViewerHelper({
|
|
|
|
property: 'maxZoomLevel',
|
|
|
|
method: 'getMaxZoom',
|
|
|
|
processExpected: function(level, expected) {
|
|
|
|
if(level === 0){ // 0 means use the default
|
|
|
|
expected = 2.2;
|
|
|
|
} else if(level < 1){
|
|
|
|
expected = 1; // max zoom won't go smaller than 1.
|
|
|
|
}
|
|
|
|
return expected;
|
2014-11-13 19:55:15 +03:00
|
|
|
}
|
|
|
|
|
2014-12-15 00:15:50 +03:00
|
|
|
});
|
2014-11-13 19:55:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeBounds', function() {
|
2014-12-15 00:15:50 +03:00
|
|
|
reopenViewerHelper({
|
|
|
|
property: 'defaultZoomLevel',
|
|
|
|
method: 'getHomeBounds',
|
|
|
|
processExpected: function(level, expected) {
|
|
|
|
// Have to special case this to avoid dividing by 0
|
2015-01-02 22:44:35 +03:00
|
|
|
if(level === -1 || level === 0){
|
2014-12-15 00:15:50 +03:00
|
|
|
expected = new OpenSeadragon.Rect(0, 0, 1, 1);
|
|
|
|
} else {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
return expected;
|
2014-11-13 19:55:15 +03:00
|
|
|
}
|
2014-12-15 00:15:50 +03:00
|
|
|
});
|
2014-11-13 19:55:15 +03:00
|
|
|
});
|
|
|
|
|
2016-05-05 05:26:33 +03:00
|
|
|
asyncTest('getHomeBoundsNoRotate with rotation', function() {
|
2015-12-06 03:18:56 +03:00
|
|
|
function openHandler() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.setRotation(-675);
|
|
|
|
Util.assertRectangleEquals(
|
2016-05-05 05:26:33 +03:00
|
|
|
viewport.getHomeBoundsNoRotate(),
|
2015-12-06 03:18:56 +03:00
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
(1 - Math.sqrt(2)) / 2,
|
|
|
|
(1 - Math.sqrt(2)) / 2,
|
|
|
|
Math.sqrt(2),
|
|
|
|
Math.sqrt(2)),
|
|
|
|
0.00000001,
|
2016-05-05 05:26:33 +03:00
|
|
|
"Test getHomeBoundsNoRotate with degrees = -675");
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeBounds with rotation', function() {
|
|
|
|
function openHandler() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.setRotation(-675);
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
viewport.getHomeBounds(),
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
0.5,
|
|
|
|
-0.5,
|
|
|
|
Math.sqrt(2),
|
|
|
|
Math.sqrt(2),
|
|
|
|
45),
|
|
|
|
0.00000001,
|
2015-12-06 03:18:56 +03:00
|
|
|
"Test getHomeBounds with degrees = -675");
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2016-04-10 01:13:37 +03:00
|
|
|
asyncTest('getHomeBoundsWithMultiImages', function() {
|
|
|
|
function openHandler() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
new OpenSeadragon.Rect(0, 0, 4, 4),
|
|
|
|
viewport.getHomeBounds(),
|
|
|
|
0.00000001,
|
|
|
|
"Test getHomeBoundsWithMultiImages");
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open([{
|
|
|
|
tileSource: DZI_PATH,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 2
|
|
|
|
}, {
|
|
|
|
tileSource: DZI_PATH,
|
|
|
|
x: 3,
|
|
|
|
y: 3,
|
|
|
|
width: 1
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('getHomeBoundsWithMultiImagesAndClipping', function() {
|
|
|
|
function openHandler() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
new OpenSeadragon.Rect(1, 1, 4, 4),
|
|
|
|
viewport.getHomeBounds(),
|
|
|
|
0.00000001,
|
|
|
|
"Test getHomeBoundsWithMultiImagesAndClipping");
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open([{
|
|
|
|
tileSource: DZI_PATH,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 2,
|
|
|
|
clip: new OpenSeadragon.Rect(500, 500, 500, 500)
|
|
|
|
}, {
|
|
|
|
tileSource: DZI_PATH,
|
|
|
|
x: 4,
|
|
|
|
y: 4,
|
|
|
|
width: 1
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
2014-11-13 19:55:15 +03:00
|
|
|
asyncTest('getHomeZoom', function() {
|
2014-12-15 00:15:50 +03:00
|
|
|
reopenViewerHelper({
|
|
|
|
property: 'defaultZoomLevel',
|
|
|
|
method: 'getHomeZoom',
|
|
|
|
processExpected: function(level, expected){
|
|
|
|
// If the default zoom level is set to 0, then we expect the home zoom to be 1.
|
|
|
|
if(expected === 0){
|
|
|
|
expected = 1;
|
|
|
|
}
|
|
|
|
return expected;
|
2014-11-13 19:55:15 +03:00
|
|
|
}
|
2014-12-15 00:15:50 +03:00
|
|
|
});
|
2014-11-13 19:55:15 +03:00
|
|
|
});
|
|
|
|
|
2014-12-15 00:15:50 +03:00
|
|
|
// I don't use the helper for this one because it sets a couple more
|
2014-12-15 20:41:32 +03:00
|
|
|
// properties that would need special casing.
|
2014-11-13 19:55:15 +03:00
|
|
|
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-20 03:53:30 +03:00
|
|
|
// Special cases for oddball levels
|
|
|
|
if (level === -1) {
|
|
|
|
expected = 0.25;
|
|
|
|
} else 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
|
|
|
|
});
|
|
|
|
|
2015-01-20 02:51:55 +03:00
|
|
|
asyncTest('resetContentSize', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for(var i = 0; i < testRects.length; i++){
|
|
|
|
var rect = testRects[i].times(viewport.getContainerSize());
|
2015-02-09 21:36:07 +03:00
|
|
|
viewport.resetContentSize(rect.getSize());
|
2015-01-20 02:51:55 +03:00
|
|
|
propEqual(
|
2016-02-16 01:09:31 +03:00
|
|
|
viewport._contentSize,
|
2015-02-09 21:36:07 +03:00
|
|
|
rect.getSize(),
|
2015-01-20 02:51:55 +03:00
|
|
|
"Reset content size correctly."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('goHome', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
// zoom/pan somewhere
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR, true);
|
|
|
|
|
|
|
|
viewport.goHome(true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getBounds(),
|
|
|
|
viewport.getHomeBounds(),
|
|
|
|
"Went home."
|
|
|
|
);
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2016-05-11 01:49:55 +03:00
|
|
|
asyncTest('ensureVisible', function() {
|
2015-01-20 02:51:55 +03:00
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
// zoom/pan so that the image is out of view
|
|
|
|
viewport.zoomTo(ZOOM_FACTOR * -50, true);
|
|
|
|
viewport.panBy(new OpenSeadragon.Point(5000, 5000), null, true);
|
|
|
|
|
|
|
|
viewport.ensureVisible(true);
|
|
|
|
var bounds = viewport.getBounds();
|
|
|
|
ok(bounds.getSize().x > 1 && bounds.getSize().y > 1, "Moved viewport so that image is visible.");
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2016-05-11 01:49:55 +03:00
|
|
|
asyncTest('applyConstraints', function() {
|
|
|
|
var openHandler = function() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true);
|
|
|
|
viewport.visibilityRatio = 0.3;
|
|
|
|
viewport.applyConstraints(true);
|
|
|
|
var bounds = viewport.getBounds();
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
bounds,
|
|
|
|
new OpenSeadragon.Rect(0.7, 0.7, 1, 1),
|
|
|
|
EPSILON,
|
|
|
|
"Viewport.applyConstraints should move viewport.");
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('applyConstraints with rotation', function() {
|
|
|
|
var openHandler = function() {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.setRotation(45);
|
|
|
|
viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true);
|
|
|
|
viewport.applyConstraints(true);
|
|
|
|
var bounds = viewport.getBounds();
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
bounds,
|
|
|
|
new OpenSeadragon.Rect(1, 0, Math.sqrt(2), Math.sqrt(2), 45),
|
|
|
|
EPSILON,
|
|
|
|
"Viewport.applyConstraints with rotation should move viewport.");
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2016-04-23 15:29:32 +03:00
|
|
|
// Fit bounds tests
|
|
|
|
var testRectsFitBounds = [
|
|
|
|
new OpenSeadragon.Rect(0, -0.75, 0.5, 1),
|
|
|
|
new OpenSeadragon.Rect(0.5, 0, 0.5, 0.8),
|
|
|
|
new OpenSeadragon.Rect(0.75, 0.75, 0.5, 0.5),
|
2016-05-11 04:19:33 +03:00
|
|
|
new OpenSeadragon.Rect(-0.3, -0.3, 0.5, 0.5),
|
|
|
|
new OpenSeadragon.Rect(0.5, 0.25, Math.sqrt(0.125), Math.sqrt(0.125), 45)
|
2016-04-23 15:29:32 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
var expectedRectsFitBounds = [
|
|
|
|
new OpenSeadragon.Rect(-0.25, -0.75, 1, 1),
|
|
|
|
new OpenSeadragon.Rect(0.35, 0, 0.8, 0.8),
|
|
|
|
new OpenSeadragon.Rect(0.75, 0.75, 0.5, 0.5),
|
2016-05-11 04:19:33 +03:00
|
|
|
new OpenSeadragon.Rect(-0.3, -0.3, 0.5, 0.5),
|
|
|
|
new OpenSeadragon.Rect(0.25, 0.25, 0.5, 0.5)
|
2016-04-23 15:29:32 +03:00
|
|
|
];
|
|
|
|
|
2016-05-05 05:26:33 +03:00
|
|
|
var expectedRectsFitBoundsWithRotation = [
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
0.25,
|
|
|
|
-1,
|
|
|
|
Math.sqrt(0.125) + Math.sqrt(0.5),
|
|
|
|
Math.sqrt(0.125) + Math.sqrt(0.5),
|
|
|
|
45),
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
0.75,
|
|
|
|
-0.25,
|
|
|
|
Math.sqrt(0.125) + Math.sqrt(8 / 25),
|
|
|
|
Math.sqrt(0.125) + Math.sqrt(8 / 25),
|
|
|
|
45),
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
1,
|
|
|
|
0.5,
|
|
|
|
Math.sqrt(0.125) * 2,
|
|
|
|
Math.sqrt(0.125) * 2,
|
|
|
|
45),
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
-0.05,
|
|
|
|
-0.55,
|
|
|
|
Math.sqrt(0.125) * 2,
|
|
|
|
Math.sqrt(0.125) * 2,
|
2016-05-11 04:19:33 +03:00
|
|
|
45),
|
|
|
|
new OpenSeadragon.Rect(
|
|
|
|
0.5,
|
|
|
|
0.25,
|
|
|
|
Math.sqrt(0.125),
|
|
|
|
Math.sqrt(0.125),
|
2016-05-05 05:26:33 +03:00
|
|
|
45)
|
|
|
|
];
|
|
|
|
|
2016-04-23 15:29:32 +03:00
|
|
|
var expectedRectsFitBoundsWithConstraints = [
|
|
|
|
new OpenSeadragon.Rect(-0.25, -0.5, 1, 1),
|
|
|
|
new OpenSeadragon.Rect(0.35, 0, 0.8, 0.8),
|
|
|
|
new OpenSeadragon.Rect(0.75, 0.75, 0.5, 0.5),
|
2016-05-11 04:19:33 +03:00
|
|
|
new OpenSeadragon.Rect(-0.25, -0.25, 0.5, 0.5),
|
|
|
|
new OpenSeadragon.Rect(0.25, 0.25, 0.5, 0.5)
|
2016-04-23 15:29:32 +03:00
|
|
|
];
|
|
|
|
|
2015-01-20 02:51:55 +03:00
|
|
|
asyncTest('fitBounds', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
2016-04-23 15:29:32 +03:00
|
|
|
for(var i = 0; i < testRectsFitBounds.length; i++){
|
|
|
|
var rect = testRectsFitBounds[i];
|
2015-01-20 02:51:55 +03:00
|
|
|
viewport.fitBounds(rect, true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getBounds(),
|
2016-04-23 15:29:32 +03:00
|
|
|
expectedRectsFitBounds[i],
|
2015-01-20 02:51:55 +03:00
|
|
|
"Fit bounds correctly."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2016-05-05 05:26:33 +03:00
|
|
|
asyncTest('fitBounds with viewport rotation', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.setRotation(45);
|
|
|
|
|
|
|
|
for(var i = 0; i < testRectsFitBounds.length; i++){
|
|
|
|
var rect = testRectsFitBounds[i];
|
|
|
|
viewport.fitBounds(rect, true);
|
|
|
|
Util.assertRectangleEquals(
|
|
|
|
viewport.getBounds(),
|
|
|
|
expectedRectsFitBoundsWithRotation[i],
|
|
|
|
EPSILON,
|
|
|
|
"Fit bounds correctly."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2015-01-20 02:51:55 +03:00
|
|
|
asyncTest('fitBoundsWithConstraints', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
2015-02-02 10:29:30 +03:00
|
|
|
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
2015-02-09 09:46:55 +03:00
|
|
|
for(var i = 0; i < testRectsFitBounds.length; i++){
|
|
|
|
var rect = testRectsFitBounds[i];
|
2015-01-20 02:51:55 +03:00
|
|
|
|
|
|
|
viewport.fitBoundsWithConstraints(rect, true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getBounds(),
|
2016-04-23 15:29:32 +03:00
|
|
|
expectedRectsFitBoundsWithConstraints[i],
|
2015-01-20 02:51:55 +03:00
|
|
|
"Fit bounds correctly."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2015-01-17 03:14:18 +03:00
|
|
|
asyncTest('fitHorizontally', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.fitHorizontally(true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getBounds(),
|
2015-02-09 21:36:07 +03:00
|
|
|
new OpenSeadragon.Rect(0, 1.5, 1, 1),
|
2015-01-17 03:14:18 +03:00
|
|
|
"Viewport fit a tall image horizontally."
|
|
|
|
);
|
2015-01-17 03:30:54 +03:00
|
|
|
start();
|
2015-01-17 03:14:18 +03:00
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(TALL_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('fitVertically', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
viewport.fitVertically(true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getBounds(),
|
2015-02-09 21:36:07 +03:00
|
|
|
new OpenSeadragon.Rect(0.375, 0, 0.25, 0.25),
|
2015-01-17 03:14:18 +03:00
|
|
|
"Viewport fit a wide image vertically."
|
|
|
|
);
|
2015-01-17 03:30:54 +03:00
|
|
|
start();
|
2015-01-17 03:14:18 +03:00
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(WIDE_PATH);
|
|
|
|
});
|
2016-04-23 15:29:32 +03:00
|
|
|
// End fitBounds tests.
|
2015-01-17 03:14:18 +03:00
|
|
|
|
2015-01-17 03:00:57 +03:00
|
|
|
asyncTest('panBy', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
var expected = viewport.getCenter().plus(testPoints[i]);
|
|
|
|
viewport.panBy(testPoints[i], true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getCenter(),
|
|
|
|
expected,
|
|
|
|
"Panned by the correct amount."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('panTo', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for (var i = 0; i < testPoints.length; i++){
|
|
|
|
viewport.panTo(testPoints[i], true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getCenter(),
|
|
|
|
testPoints[i],
|
|
|
|
"Panned to the correct location."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2015-01-15 23:36:01 +03:00
|
|
|
asyncTest('zoomBy', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for (var i = 0; i < testZoomLevels.length; i++){
|
|
|
|
viewport.zoomBy(testZoomLevels[i], null, true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getZoom(),
|
|
|
|
testZoomLevels[i],
|
|
|
|
"Zoomed by the correct amount."
|
|
|
|
);
|
2015-01-17 02:45:04 +03:00
|
|
|
|
|
|
|
// now use a ref point
|
2015-02-09 20:24:43 +03:00
|
|
|
// TODO: check the ending position due to ref point
|
2015-01-17 02:45:04 +03:00
|
|
|
viewport.zoomBy(testZoomLevels[i], testPoints[i], true);
|
|
|
|
propEqual(
|
|
|
|
viewport.getZoom(),
|
|
|
|
testZoomLevels[i],
|
|
|
|
"Zoomed by the correct amount."
|
|
|
|
);
|
2015-01-15 23:36:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('zoomTo', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for (var i = 0; i < testZoomLevels.length; i++){
|
|
|
|
viewport.zoomTo(testZoomLevels[i], null, true);
|
|
|
|
propEqual(
|
2015-01-17 02:45:04 +03:00
|
|
|
viewport.getZoom(),
|
|
|
|
testZoomLevels[i],
|
|
|
|
"Zoomed to the correct level."
|
|
|
|
);
|
|
|
|
|
|
|
|
// now use a ref point
|
2015-02-09 20:24:43 +03:00
|
|
|
// TODO: check the ending position due to ref point
|
2015-01-17 02:45:04 +03:00
|
|
|
viewport.zoomTo(testZoomLevels[i], testPoints[i], true);
|
|
|
|
propEqual(
|
2015-01-15 23:36:01 +03:00
|
|
|
viewport.getZoom(),
|
|
|
|
testZoomLevels[i],
|
|
|
|
"Zoomed to the correct level."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('rotation', function(){
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees");
|
|
|
|
viewport.setRotation(90);
|
|
|
|
propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees");
|
|
|
|
viewport.setRotation(-75);
|
|
|
|
propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees");
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('resize', function() {
|
|
|
|
var openHandler = function(event) {
|
|
|
|
viewer.removeHandler('open', openHandler);
|
|
|
|
var viewport = viewer.viewport;
|
|
|
|
|
|
|
|
for(var i = 0; i < testPoints.length; i++){
|
|
|
|
var new_size = testPoints[i].times(viewer.source.dimensions.x);
|
|
|
|
viewport.resize(new_size);
|
|
|
|
propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully.");
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
viewer.addHandler('open', openHandler);
|
|
|
|
viewer.open(DZI_PATH);
|
|
|
|
});
|
|
|
|
|
2014-11-13 19:55:15 +03:00
|
|
|
asyncTest('deltaPixelsFromPoints', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport){
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport){
|
|
|
|
return orig.times(viewport.getContainerSize().x * ZOOM_FACTOR);
|
|
|
|
},
|
|
|
|
method: 'deltaPixelsFromPoints'
|
|
|
|
});
|
2014-11-07 05:30:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('deltaPointsFromPixels', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.divide(viewport.getContainerSize().x * ZOOM_FACTOR);
|
|
|
|
},
|
|
|
|
method: 'deltaPointsFromPixels'
|
|
|
|
});
|
2014-11-07 05:30:24 +03:00
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
|
2014-12-15 20:41:32 +03:00
|
|
|
asyncTest('pixelFromPoint', function() {
|
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.plus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).minus(viewport.getContainerSize());
|
|
|
|
},
|
|
|
|
method: 'pixelFromPoint'
|
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('pointFromPixel', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.divide(viewer.source.dimensions.x).plus(VIEWER_PADDING);
|
|
|
|
},
|
|
|
|
method: 'pointFromPixel'
|
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
});
|
|
|
|
|
2014-12-15 20:41:32 +03:00
|
|
|
asyncTest('viewportToImageCoordinates', function() {
|
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.divide(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
method: 'imageToViewportCoordinates'
|
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('imageToViewportCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.divide(ZOOM_FACTOR * viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
method: 'imageToViewportCoordinates'
|
|
|
|
});
|
2014-10-30 07:10:15 +03:00
|
|
|
});
|
2014-10-24 03:13:02 +04:00
|
|
|
asyncTest('imageToViewportRectangle', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testRects,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return 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
|
|
|
);
|
2014-12-15 20:41:32 +03:00
|
|
|
},
|
|
|
|
method: 'imageToViewportRectangle'
|
|
|
|
});
|
2014-10-24 03:13:02 +04:00
|
|
|
});
|
|
|
|
|
2014-10-21 22:19:41 +04:00
|
|
|
asyncTest('viewportToImageRectangle', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testRects,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return 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
|
|
|
);
|
2014-12-15 20:41:32 +03:00
|
|
|
},
|
|
|
|
method: 'viewportToImageRectangle'
|
|
|
|
});
|
2014-10-21 22:19:41 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewerElementToImageCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewport.getContainerSize().x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.plus(viewport.getContainerSize().divide(2));
|
|
|
|
},
|
|
|
|
method: 'viewerElementToImageCoordinates'
|
|
|
|
});
|
2014-10-16 04:00:11 +04:00
|
|
|
});
|
|
|
|
|
2014-10-16 03:54:09 +04:00
|
|
|
asyncTest('imageToViewerElementCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig.minus(viewport.getContainerSize().divide(2));
|
|
|
|
},
|
|
|
|
method: 'imageToViewerElementCoordinates'
|
|
|
|
});
|
2014-10-16 03:54:09 +04:00
|
|
|
});
|
|
|
|
|
2014-10-15 23:22:52 +04:00
|
|
|
asyncTest('windowToImageCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
|
|
|
return el.times(window_boundary);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
2015-01-03 01:24:05 +03:00
|
|
|
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
|
2014-12-15 20:41:32 +03:00
|
|
|
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
|
|
|
},
|
|
|
|
method: 'windowToViewportCoordinates'
|
|
|
|
});
|
2014-10-15 23:22:52 +04:00
|
|
|
});
|
2014-10-15 22:45:19 +04:00
|
|
|
|
|
|
|
asyncTest('imageToWindowCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
2015-01-03 01:24:05 +03:00
|
|
|
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
|
2014-12-15 20:41:32 +03:00
|
|
|
return orig.plus(pos_point).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
|
|
|
|
},
|
|
|
|
method: 'imageToWindowCoordinates'
|
|
|
|
});
|
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-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
|
|
|
return el.times(window_boundary);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
2015-01-03 01:24:05 +03:00
|
|
|
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
|
2014-12-15 20:41:32 +03:00
|
|
|
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
|
|
|
},
|
|
|
|
method: 'windowToViewportCoordinates'
|
|
|
|
});
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToWindowCoordinates', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el.times(viewer.source.dimensions.x);
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
2015-01-03 01:24:05 +03:00
|
|
|
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
|
2014-12-15 20:41:32 +03:00
|
|
|
return orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(pos_point);
|
|
|
|
},
|
|
|
|
method: 'viewportToWindowCoordinates'
|
|
|
|
});
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('viewportToImageZoom', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el;
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig / ZOOM_FACTOR;
|
|
|
|
},
|
|
|
|
method: 'viewportToImageZoom'
|
|
|
|
});
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest('imageToViewportZoom', function() {
|
2014-12-15 20:41:32 +03:00
|
|
|
loopingTestHelper({
|
|
|
|
testArray: testPoints,
|
|
|
|
getOrig: function(el, viewport) {
|
|
|
|
return el;
|
|
|
|
},
|
|
|
|
getExpected: function(orig, viewport) {
|
|
|
|
return orig * ZOOM_FACTOR;
|
|
|
|
},
|
|
|
|
method: 'imageToViewportZoom'
|
|
|
|
});
|
2014-10-03 00:20:28 +04:00
|
|
|
});
|
|
|
|
|
2014-10-29 19:42:19 +03:00
|
|
|
})();
|