2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* A Point is really used as a 2-dimensional vector, equally useful for
|
|
|
|
* representing a point on a plane, or the height and width of a plane
|
|
|
|
* not requiring any other frame of reference.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} [x] The vector component 'x'. Defaults to the origin at 0.
|
|
|
|
* @param {Number} [y] The vector component 'y'. Defaults to the origin at 0.
|
|
|
|
* @property {Number} [x] The vector component 'x'.
|
|
|
|
* @property {Number} [y] The vector component 'y'.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.Point = function( x, y ) {
|
|
|
|
this.x = typeof ( x ) == "number" ? x : 0;
|
|
|
|
this.y = typeof ( y ) == "number" ? y : 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Point.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
plus: function( point ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x + point.x,
|
|
|
|
this.y + point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
minus: function( point ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x - point.x,
|
|
|
|
this.y - point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
times: function( factor ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x * factor,
|
|
|
|
this.y * factor
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
divide: function( factor ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x / factor,
|
|
|
|
this.y / factor
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
negate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
return new $.Point( -this.x, -this.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
distanceTo: function( point ) {
|
|
|
|
return Math.sqrt(
|
|
|
|
Math.pow( this.x - point.x, 2 ) +
|
|
|
|
Math.pow( this.y - point.y, 2 )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
apply: function( func ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( func( this.x ), func( this.y ) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
equals: function( point ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
return (
|
|
|
|
point instanceof $.Point
|
|
|
|
) && (
|
|
|
|
this.x === point.x
|
|
|
|
) && (
|
|
|
|
this.y === point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
toString: function() {
|
|
|
|
return "(" + this.x + "," + this.y + ")";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|