# HG changeset patch # User hertzhaft # Date 1135246832 -3600 # Node ID 7207a554930102f64f64184d791be9dbba55dc8a # Parent 6aef40295ac1db3298e0d9e95e4f9e979d601587 some new rectangle methods diff -r 6aef40295ac1 -r 7207a5549301 client/digitallibrary/greyskin/baselib.js --- 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; }