Mercurial > hg > digilib-old
changeset 426:7207a5549301
some new rectangle methods
author | hertzhaft |
---|---|
date | Thu, 22 Dec 2005 11:20:32 +0100 |
parents | 6aef40295ac1 |
children | 84aee0e6d64e |
files | client/digitallibrary/greyskin/baselib.js |
diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/client/digitallibrary/greyskin/baselib.js Thu Dec 22 11:19:40 2005 +0100 +++ b/client/digitallibrary/greyskin/baselib.js Thu Dec 22 11:20:32 2005 +0100 @@ -97,7 +97,10 @@ Size.prototype.toString = function() { return this.width + "x" + this.height; } - +Size.prototype.equals = function(other) { + return (this.width == other.width + && this.height == other.height) + } /* * Position class @@ -110,7 +113,10 @@ Position.prototype.toString = function() { return this.x + "," + this.y; } - +Position.prototype.equals = function(other) { + return (this.x == other.x + && this.y == other.y) + } /* * Rectangle class */ @@ -136,6 +142,12 @@ // returns the size of this Rectangle return new Size(this.width, this.height); } +Rectangle.prototype.equals = function(other) { + // equal props + return (this.getPosition().equals(other.getPosition()) + && this.getSize().equals(other.getSize()) + ); +} Rectangle.prototype.getArea = function() { // returns the area of this Rectangle return (this.width * this.height); @@ -158,6 +170,7 @@ } Rectangle.prototype.stayInside = function(rect) { // changes this rectangle's x/y values so it stays inside of rectangle rect + // but not its proportions if (this.x < rect.x) this.x = rect.x; if (this.y < rect.y) this.y = rect.y; if (this.x + this.width > rect.x + rect.width) @@ -190,7 +203,7 @@ // returns a Rectangle that fits into this one (by moving first) var sec = rect.copy(); sec.x = Math.max(sec.x, this.x); - sec.x = Math.max(sec.x, this.x); + sec.y = Math.max(sec.y, this.x); if (sec.x + sec.width > this.x + this.width) { sec.x = this.x + this.width - sec.width; }