2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-28 03:23:07 +04:00
|
|
|
$.Point = function(x, y) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.x = typeof (x) == "number" ? x : 0;
|
|
|
|
this.y = typeof (y) == "number" ? y : 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Point.prototype = {
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
apply: function( func ) {
|
|
|
|
return new $.Point( func(this.x), func(this.y) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
equals: function( point ) {
|
|
|
|
return ( point instanceof $.Point ) &&
|
|
|
|
( this.x === point.x ) &&
|
|
|
|
( this.y === point.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
toString: function() {
|
|
|
|
return "(" + this.x + "," + this.y + ")";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|