mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 22:56:11 +03:00
Refactor other looping tests that don't reopen the viewer in a similar manner.
This commit is contained in:
parent
aebfecb4e8
commit
00510c6cc2
512
test/viewport.js
512
test/viewport.js
@ -90,6 +90,33 @@
|
|||||||
viewer.open(DZI_PATH);
|
viewer.open(DZI_PATH);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
viewport.update(); // need to call this even with immediately=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);
|
||||||
|
};
|
||||||
|
|
||||||
// Tests start here.
|
// Tests start here.
|
||||||
asyncTest('getContainerSize', function() {
|
asyncTest('getContainerSize', function() {
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
@ -207,7 +234,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// I don't use the helper for this one because it sets a couple more
|
// I don't use the helper for this one because it sets a couple more
|
||||||
// properties that would need a lot of special casing.
|
// properties that would need special casing.
|
||||||
asyncTest('getHomeZoomWithHomeFillsViewer', function() {
|
asyncTest('getHomeZoomWithHomeFillsViewer', function() {
|
||||||
var expected, level, i = 0;
|
var expected, level, i = 0;
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
@ -250,365 +277,234 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('deltaPixelsFromPoints', function() {
|
asyncTest('deltaPixelsFromPoints', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport){
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport){
|
||||||
var orig, expected, actual;
|
return orig.times(viewport.getContainerSize().x * ZOOM_FACTOR);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
method: 'deltaPixelsFromPoints'
|
||||||
expected = orig.times(viewport.getContainerSize().x * ZOOM_FACTOR);
|
});
|
||||||
actual = viewport.deltaPixelsFromPoints(orig);
|
|
||||||
propEqual(actual, expected, "Correctly got delta pixels from points" + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('deltaPointsFromPixels', function() {
|
asyncTest('deltaPointsFromPixels', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewport.getContainerSize().x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.divide(viewport.getContainerSize().x * ZOOM_FACTOR);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewport.getContainerSize().x);
|
method: 'deltaPointsFromPixels'
|
||||||
|
});
|
||||||
expected = orig.divide(viewport.getContainerSize().x * ZOOM_FACTOR);
|
|
||||||
actual = viewport.deltaPointsFromPixels(orig);
|
|
||||||
propEqual(actual, expected, "Correctly got delta points from pixels " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('pixelFromPoint', function() {
|
asyncTest('pixelFromPoint', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.plus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).minus(viewport.getContainerSize());
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
method: 'pixelFromPoint'
|
||||||
expected = orig.plus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).minus(viewport.getContainerSize());
|
});
|
||||||
actual = viewport.pixelFromPoint(orig, false);
|
|
||||||
propEqual(
|
|
||||||
actual,
|
|
||||||
expected,
|
|
||||||
"Correctly converted coordinates " + orig
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('pointFromPixel', function() {
|
asyncTest('pointFromPixel', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewport.getContainerSize().x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.divide(viewer.source.dimensions.x).plus(VIEWER_PADDING);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewport.getContainerSize().x);
|
method: 'pointFromPixel'
|
||||||
expected = orig.divide(viewer.source.dimensions.x).plus(VIEWER_PADDING);
|
});
|
||||||
actual = viewport.pointFromPixel(orig, false);
|
|
||||||
propEqual(
|
|
||||||
actual,
|
|
||||||
expected,
|
|
||||||
"Correctly converted coordinates " + orig
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('viewportToImageCoordinates', function() {
|
asyncTest('viewportToImageCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewport.getContainerSize().x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.divide(viewer.source.dimensions.x);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewport.getContainerSize().x);
|
method: 'imageToViewportCoordinates'
|
||||||
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() {
|
asyncTest('imageToViewportCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.divide(ZOOM_FACTOR * viewport.getContainerSize().x);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
method: 'imageToViewportCoordinates'
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
asyncTest('imageToViewportRectangle', function() {
|
asyncTest('imageToViewportRectangle', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testRects,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return new OpenSeadragon.Rect(
|
||||||
for (var i = 0; i < testRects.length; i++){
|
|
||||||
orig = testRects[i].times(viewer.source.dimensions.x);
|
|
||||||
expected = new OpenSeadragon.Rect(
|
|
||||||
orig.x / viewer.source.dimensions.x,
|
orig.x / viewer.source.dimensions.x,
|
||||||
orig.y / viewer.source.dimensions.x,
|
orig.y / viewer.source.dimensions.x,
|
||||||
orig.width / viewer.source.dimensions.x,
|
orig.width / viewer.source.dimensions.x,
|
||||||
orig.height / viewer.source.dimensions.x
|
orig.height / viewer.source.dimensions.x
|
||||||
);
|
);
|
||||||
actual = viewport.imageToViewportRectangle(orig);
|
},
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
method: 'imageToViewportRectangle'
|
||||||
}
|
});
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('viewportToImageRectangle', function() {
|
asyncTest('viewportToImageRectangle', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testRects,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewport.getContainerSize().x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return new OpenSeadragon.Rect(
|
||||||
for (var i = 0; i < testRects.length; i++){
|
|
||||||
orig = testRects[i].times(viewport.getContainerSize().x);
|
|
||||||
expected = new OpenSeadragon.Rect(
|
|
||||||
orig.x * viewer.source.dimensions.x,
|
orig.x * viewer.source.dimensions.x,
|
||||||
orig.y * viewer.source.dimensions.x,
|
orig.y * viewer.source.dimensions.x,
|
||||||
orig.width * viewer.source.dimensions.x,
|
orig.width * viewer.source.dimensions.x,
|
||||||
orig.height * viewer.source.dimensions.x
|
orig.height * viewer.source.dimensions.x
|
||||||
);
|
);
|
||||||
actual = viewport.viewportToImageRectangle(orig);
|
},
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
method: 'viewportToImageRectangle'
|
||||||
}
|
});
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('viewerElementToImageCoordinates', function() {
|
asyncTest('viewerElementToImageCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewport.getContainerSize().x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.plus(viewport.getContainerSize().divide(2));
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewport.getContainerSize().x);
|
method: 'viewerElementToImageCoordinates'
|
||||||
expected = orig.plus(viewport.getContainerSize().divide(2));
|
});
|
||||||
actual = viewport.viewerElementToImageCoordinates(orig);
|
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('imageToViewerElementCoordinates', function() {
|
asyncTest('imageToViewerElementCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig.minus(viewport.getContainerSize().divide(2));
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
method: 'imageToViewerElementCoordinates'
|
||||||
expected = orig.minus(viewport.getContainerSize().divide(2));
|
});
|
||||||
actual = viewport.imageToViewerElementCoordinates(orig);
|
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('windowToImageCoordinates', function() {
|
asyncTest('windowToImageCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
return el.times(window_boundary);
|
||||||
|
},
|
||||||
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual, position, pos_point;
|
var position, pos_point;
|
||||||
position = viewer.element.getBoundingClientRect();
|
position = viewer.element.getBoundingClientRect();
|
||||||
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
||||||
orig = testPoints[i].times(window_boundary);
|
},
|
||||||
expected = orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
method: 'windowToViewportCoordinates'
|
||||||
actual = viewport.windowToViewportCoordinates(orig);
|
});
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('imageToWindowCoordinates', function() {
|
asyncTest('imageToWindowCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var position, orig, expected, actual, pos_point;
|
var position, pos_point;
|
||||||
position = viewer.element.getBoundingClientRect();
|
position = viewer.element.getBoundingClientRect();
|
||||||
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
return orig.plus(pos_point).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
},
|
||||||
expected = orig.plus(pos_point).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
|
method: 'imageToWindowCoordinates'
|
||||||
actual = viewport.imageToWindowCoordinates(orig);
|
});
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('windowToViewportCoordinates', function() {
|
asyncTest('windowToViewportCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
return el.times(window_boundary);
|
||||||
|
},
|
||||||
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual, position;
|
var position, pos_point;
|
||||||
position = viewer.element.getBoundingClientRect();
|
position = viewer.element.getBoundingClientRect();
|
||||||
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
||||||
orig = testPoints[i].times(window_boundary);
|
},
|
||||||
expected = orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
|
method: 'windowToViewportCoordinates'
|
||||||
actual = viewport.windowToViewportCoordinates(orig);
|
});
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('viewportToWindowCoordinates', function() {
|
asyncTest('viewportToWindowCoordinates', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el.times(viewer.source.dimensions.x);
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual, position;
|
var position, pos_point;
|
||||||
position = viewer.element.getBoundingClientRect();
|
position = viewer.element.getBoundingClientRect();
|
||||||
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
pos_point = new OpenSeadragon.Point(position.top, position.left);
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
return orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(pos_point);
|
||||||
orig = testPoints[i].times(viewer.source.dimensions.x);
|
},
|
||||||
expected = orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(pos_point);
|
method: 'viewportToWindowCoordinates'
|
||||||
actual = viewport.viewportToWindowCoordinates(orig);
|
});
|
||||||
propEqual(actual, expected, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('viewportToImageZoom', function() {
|
asyncTest('viewportToImageZoom', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el;
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig / ZOOM_FACTOR;
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testZoomLevels[i];
|
method: 'viewportToImageZoom'
|
||||||
expected = orig / ZOOM_FACTOR;
|
});
|
||||||
actual = viewport.viewportToImageZoom(orig);
|
|
||||||
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('imageToViewportZoom', function() {
|
asyncTest('imageToViewportZoom', function() {
|
||||||
var openHandler = function(event) {
|
loopingTestHelper({
|
||||||
viewer.removeHandler('open', openHandler);
|
testArray: testPoints,
|
||||||
var viewport = viewer.viewport;
|
getOrig: function(el, viewport) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
return el;
|
||||||
viewport.update(); // need to call this even with immediately=true
|
},
|
||||||
|
getExpected: function(orig, viewport) {
|
||||||
var orig, expected, actual;
|
return orig * ZOOM_FACTOR;
|
||||||
for (var i = 0; i < testPoints.length; i++){
|
},
|
||||||
orig = testZoomLevels[i];
|
method: 'imageToViewportZoom'
|
||||||
expected = orig * ZOOM_FACTOR;
|
});
|
||||||
actual = viewport.imageToViewportZoom(orig);
|
|
||||||
equal(expected, actual, "Coordinates converted correctly for " + orig);
|
|
||||||
}
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user