2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-30 03:16:51 +04:00
|
|
|
$.Rect = function( x, y, width, height ) {
|
|
|
|
this.x = typeof ( x ) == "number" ? x : 0;
|
|
|
|
this.y = typeof ( y ) == "number" ? y : 0;
|
|
|
|
this.width = typeof ( width ) == "number" ? width : 0;
|
|
|
|
this.height = typeof ( height ) == "number" ? height : 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Rect.prototype = {
|
|
|
|
getAspectRatio: function() {
|
|
|
|
return this.width / this.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTopLeft: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point( this.x, this.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getBottomRight: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point(
|
|
|
|
this.x + this.width,
|
|
|
|
this.y + this.height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getCenter: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point(
|
|
|
|
this.x + this.width / 2.0,
|
|
|
|
this.y + this.height / 2.0
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getSize: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point( this.width, this.height );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
equals: function(other) {
|
2011-12-30 03:16:51 +04:00
|
|
|
return
|
|
|
|
( other instanceof $.Rect ) &&
|
|
|
|
( this.x === other.x ) &&
|
|
|
|
( this.y === other.y ) &&
|
|
|
|
( this.width === other.width ) &&
|
|
|
|
( this.height === other.height );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
toString: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return "[" +
|
|
|
|
this.x + "," +
|
|
|
|
this.y + "," +
|
|
|
|
this.width + "x" +
|
|
|
|
this.height +
|
|
|
|
"]";
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|