From 63af5a69ac1ffdf31566760a6f79183b4a21c5bf Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Wed, 4 Sep 2013 14:13:25 -0400 Subject: [PATCH] Add comments and fix indentation --- src/viewport.js | 67 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index e2638111..74c9f8aa 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -722,33 +722,54 @@ $.Viewport.prototype = { }, /** - * Translates from Seajax viewer coordinate - * system to image coordinate system + * Translates from Seajax viewer coordinate system to image coordinate system. + * This method can be called either by passing X,Y coordinates or an + * OpenSeadragon.Point + * @function + * @param {OpenSeadragon.Point} viewerX the point in viewport coordinate system. + * @param {Number} viewerX X coordinate in viewport coordinate system. + * @param {Number} viewerY Y coordinate in viewport coordinate system. + * @return {OpenSeadragon.Point} a point representing the coordinates in the image. */ - viewportToImageCoordinates: function(viewerX, viewerY) { + viewportToImageCoordinates: function( viewerX, viewerY ) { if ( arguments.length == 1 ) { //they passed a point instead of individual components - return this.viewportToImageCoordinates(viewerX.x, viewerX.y); + return this.viewportToImageCoordinates( viewerX.x, viewerX.y ); } - return new $.Point(viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX); + return new $.Point( viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX ); }, /** - * Translates from image coordinate system to - * Seajax viewer coordinate system + * Translates from image coordinate system to Seajax viewer coordinate system + * This method can be called either by passing X,Y coordinates or an + * OpenSeadragon.Point + * @function + * @param {OpenSeadragon.Point} imageX the point in image coordinate system. + * @param {Number} imageX X coordinate in image coordinate system. + * @param {Number} imageY Y coordinate in image coordinate system. + * @return {OpenSeadragon.Point} a point representing the coordinates in the viewport. */ imageToViewportCoordinates: function( imageX, imageY ) { if ( arguments.length == 1 ) { //they passed a point instead of individual components - return this.imageToViewportCoordinates(imageX.x, imageX.y); + return this.imageToViewportCoordinates( imageX.x, imageX.y ); } - return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX); + return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX ); }, /** - * Translates from a rectangle which describes a portion of - * the image in pixel coordinates to OpenSeadragon viewport - * rectangle coordinates. + * Translates from a rectangle which describes a portion of the image in + * pixel coordinates to OpenSeadragon viewport rectangle coordinates. + * This method can be called either by passing X,Y,width,height or an + * OpenSeadragon.Rect + * @function + * @param {OpenSeadragon.Rect} imageX the rectangle in image coordinate system. + * @param {Number} imageX the X coordinate of the top left corner of the rectangle + * in image coordinate system. + * @param {Number} imageY the Y coordinate of the top left corner of the rectangle + * in image coordinate system. + * @param {Number} pixelWidth the width in pixel of the rectangle. + * @param {Number} pixelHeight the height in pixel of the rectangle. */ imageToViewportRectangle: function( imageX, imageY, pixelWidth, pixelHeight ) { var coordA, @@ -757,7 +778,9 @@ $.Viewport.prototype = { if( arguments.length == 1 ) { //they passed a rectangle instead of individual components rect = imageX; - return this.imageToViewportRectangle(rect.x, rect.y, rect.width, rect.height); + return this.imageToViewportRectangle( + rect.x, rect.y, rect.width, rect.height + ); } coordA = this.imageToViewportCoordinates( imageX, imageY @@ -776,6 +799,16 @@ $.Viewport.prototype = { /** * Translates from a rectangle which describes a portion of * the viewport in point coordinates to image rectangle coordinates. + * This method can be called either by passing X,Y,width,height or an + * OpenSeadragon.Rect + * @function + * @param {OpenSeadragon.Rect} viewerX the rectangle in viewport coordinate system. + * @param {Number} viewerX the X coordinate of the top left corner of the rectangle + * in viewport coordinate system. + * @param {Number} imageY the Y coordinate of the top left corner of the rectangle + * in viewport coordinate system. + * @param {Number} pointWidth the width of the rectangle in viewport coordinate system. + * @param {Number} pointHeight the height of the rectangle in viewport coordinate system. */ viewportToImageRectangle: function( viewerX, viewerY, pointWidth, pointHeight ) { var coordA, @@ -784,10 +817,12 @@ $.Viewport.prototype = { if ( arguments.length == 1 ) { //they passed a rectangle instead of individual components rect = viewerX; - return this.viewportToImageRectangle(rect.x, rect.y, rect.width, rect.height); + return this.viewportToImageRectangle( + rect.x, rect.y, rect.width, rect.height + ); } - coordA = this.viewportToImageCoordinates(viewerX, viewerY); - coordB = this.viewportToImageCoordinates(pointWidth, pointHeight); + coordA = this.viewportToImageCoordinates( viewerX, viewerY ); + coordB = this.viewportToImageCoordinates( pointWidth, pointHeight ); return new $.Rect( coordA.x, coordA.y,