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
|
* Convert pixel coordinates relative to the image to
|
||||||
* viewer element coordinates.
|
* viewer element coordinates.
|
||||||
* @param {OpenSeadragon.Point} point
|
* @param {OpenSeadragon.Point} pixel
|
||||||
* @returns {OpenSeadragon.Point}
|
* @returns {OpenSeadragon.Point}
|
||||||
*/
|
*/
|
||||||
imageToViewerElementCoordinates: function( point ) {
|
imageToViewerElementCoordinates: function( pixel ) {
|
||||||
var pixel = this.pixelFromPoint( point, true );
|
var point = this.imageToViewportCoordinates( pixel );
|
||||||
return this.imageToViewportCoordinates( pixel );
|
return this.pixelFromPoint( point, true );
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,12 +26,34 @@
|
|||||||
|
|
||||||
|
|
||||||
function pointEqual(a, b, message) {
|
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() {
|
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 () {
|
viewer.addHandler("open", function () {
|
||||||
var viewport = viewer.viewport;
|
var viewport = viewer.viewport;
|
||||||
|
|
||||||
@ -52,25 +74,14 @@
|
|||||||
var pixel = viewport.viewerElementToImageCoordinates(viewerTopRight);
|
var pixel = viewport.viewerElementToImageCoordinates(viewerTopRight);
|
||||||
pointEqual(pixel, imageTopRight, 'Viewer top right has viewport coordinates imageWidth,0.');
|
pointEqual(pixel, imageTopRight, 'Viewer top right has viewport coordinates imageWidth,0.');
|
||||||
|
|
||||||
var point = new OpenSeadragon.Point(15, 12);
|
checkPoint('after opening');
|
||||||
var result = viewport.viewerElementToImageCoordinates(
|
viewer.addHandler('animation-finish', function animationHandler() {
|
||||||
viewport.imageToViewerElementCoordinates(point));
|
viewer.removeHandler('animation-finish', animationHandler);
|
||||||
pointEqual(result, point, 'viewerElement and image');
|
checkPoint('after zoom and pan');
|
||||||
|
|
||||||
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');
|
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2));
|
||||||
|
});
|
||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,14 +115,13 @@
|
|||||||
checkZoom();
|
checkZoom();
|
||||||
|
|
||||||
var zoomHandler = function() {
|
var zoomHandler = function() {
|
||||||
viewer.removeHandler('animationfinish', zoomHandler);
|
viewer.removeHandler('animation-finish', zoomHandler);
|
||||||
checkZoom();
|
checkZoom();
|
||||||
start();
|
start();
|
||||||
};
|
};
|
||||||
|
|
||||||
viewer.addHandler('animationfinish', zoomHandler);
|
viewer.addHandler('animation-finish', zoomHandler);
|
||||||
viewport.zoomTo(2);
|
viewport.zoomTo(2);
|
||||||
start();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user