mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-19 17:21:50 +03:00
Fix imageToViewerElementCoordinates method and corresponding unit tests.
This commit is contained in:
parent
e26727488f
commit
ed5eae9a73
@ -920,12 +920,12 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
||||
/**
|
||||
* Convert pixel coordinates relative to the image to
|
||||
* viewer element coordinates.
|
||||
* @param {OpenSeadragon.Point} point
|
||||
* @param {OpenSeadragon.Point} pixel
|
||||
* @returns {OpenSeadragon.Point}
|
||||
*/
|
||||
imageToViewerElementCoordinates: function( point ) {
|
||||
var pixel = this.pixelFromPoint( point, true );
|
||||
return this.imageToViewportCoordinates( pixel );
|
||||
imageToViewerElementCoordinates: function( pixel ) {
|
||||
var point = this.imageToViewportCoordinates( pixel );
|
||||
return this.pixelFromPoint( point, true );
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -26,12 +26,34 @@
|
||||
|
||||
|
||||
function pointEqual(a, b, message) {
|
||||
ok(a.x === b.x && a.y === b.y, message);
|
||||
Util.assessNumericValue(a.x, b.x, 0.00000001, message);
|
||||
Util.assessNumericValue(a.y, b.y, 0.00000001, message);
|
||||
}
|
||||
|
||||
// ----------
|
||||
asyncTest('Coordinates conversions', function() {
|
||||
|
||||
function checkPoint(context) {
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
var point = new OpenSeadragon.Point(15, 12);
|
||||
var result = viewport.viewerElementToImageCoordinates(
|
||||
viewport.imageToViewerElementCoordinates(point));
|
||||
pointEqual(result, point, 'viewerElement and image ' + context);
|
||||
|
||||
var result = viewport.windowToImageCoordinates(
|
||||
viewport.imageToWindowCoordinates(point));
|
||||
pointEqual(result, point, 'window and image ' + context);
|
||||
|
||||
var result = viewport.viewerElementToViewportCoordinates(
|
||||
viewport.viewportToViewerElementCoordinates(point));
|
||||
pointEqual(result, point, 'viewerElement and viewport ' + context);
|
||||
|
||||
var result = viewport.windowToViewportCoordinates(
|
||||
viewport.viewportToWindowCoordinates(point));
|
||||
pointEqual(result, point, 'window and viewport ' + context);
|
||||
}
|
||||
|
||||
viewer.addHandler("open", function () {
|
||||
var viewport = viewer.viewport;
|
||||
|
||||
@ -52,25 +74,14 @@
|
||||
var pixel = viewport.viewerElementToImageCoordinates(viewerTopRight);
|
||||
pointEqual(pixel, imageTopRight, 'Viewer top right has viewport coordinates imageWidth,0.');
|
||||
|
||||
var point = new OpenSeadragon.Point(15, 12);
|
||||
var result = viewport.viewerElementToImageCoordinates(
|
||||
viewport.imageToViewerElementCoordinates(point));
|
||||
pointEqual(result, point, 'viewerElement and image');
|
||||
|
||||
var result = viewport.windowToImageCoordinates(
|
||||
viewport.imageToWindowCoordinates(point));
|
||||
pointEqual(result, point, 'window and image');
|
||||
|
||||
var result = viewport.viewerElementToViewportCoordinates(
|
||||
viewport.viewportToViewerElementCoordinates(point));
|
||||
pointEqual(result, point, 'viewerElement and viewport');
|
||||
|
||||
var result = viewport.windowToViewportCoordinates(
|
||||
viewport.viewportToWindowCoordinates(point));
|
||||
pointEqual(result, point, 'window and viewport');
|
||||
|
||||
checkPoint('after opening');
|
||||
viewer.addHandler('animation-finish', function animationHandler() {
|
||||
viewer.removeHandler('animation-finish', animationHandler);
|
||||
checkPoint('after zoom and pan');
|
||||
start();
|
||||
});
|
||||
viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2));
|
||||
});
|
||||
viewer.open('/test/data/testpattern.dzi');
|
||||
});
|
||||
|
||||
@ -104,14 +115,13 @@
|
||||
checkZoom();
|
||||
|
||||
var zoomHandler = function() {
|
||||
viewer.removeHandler('animationfinish', zoomHandler);
|
||||
viewer.removeHandler('animation-finish', zoomHandler);
|
||||
checkZoom();
|
||||
start();
|
||||
};
|
||||
|
||||
viewer.addHandler('animationfinish', zoomHandler);
|
||||
viewer.addHandler('animation-finish', zoomHandler);
|
||||
viewport.zoomTo(2);
|
||||
start();
|
||||
});
|
||||
|
||||
viewer.open('/test/data/testpattern.dzi');
|
||||
|
Loading…
x
Reference in New Issue
Block a user