+ More merging

This commit is contained in:
Aza Raskin 2010-06-19 18:53:21 -07:00
commit 697bec4faa

View File

@ -20,6 +20,7 @@
*
* Contributor(s):
* Ian Gilman <ian@iangilman.com>
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -130,7 +131,7 @@ window.Rect.prototype = {
// ----------
set right(value) {
this.width = value - this.left;
this.width = value - this.left;
},
// ----------
@ -140,9 +141,17 @@ window.Rect.prototype = {
// ----------
set bottom(value) {
this.height = value - this.top;
this.height = value - this.top;
},
get xRange() {
return new Range(this.left,this.right);
},
get yRange() {
return new Range(this.top,this.bottom);
},
// ----------
intersects: function(rect) {
return (rect.right > this.left
@ -249,6 +258,67 @@ window.Rect.prototype = {
}
};
// ##########
// Class: Range
// A physical interval, with a min and max.
//
// Constructor: Range
// Creates a Range with the given min and max
window.Range = function(min, max) {
if (isRange(min) && !max) { // if the one variable given is a range, copy it.
this.min = min.min;
this.max = min.max;
} else {
this.min = min || 0;
this.max = max || 0;
}
};
// ----------
window.isRange = function(r) {
return (r
&& Utils.isNumber(r.min)
&& Utils.isNumber(r.max));
};
window.Range.prototype = {
// Variable: extent
// Equivalent to max-min
get extent() {
return (this.max - this.min);
},
set extent(extent) {
this.max = extent - this.min;
},
// ----------
// Function: contains
// Whether the <Range> contains the given value or not
//
// Paramaters
// - a number or <Range>
contains: function(value) {
if (Utils.isNumber(value))
return ( value >= this.min && value <= this.max );
else if (isRange(value))
return ( value.min >= this.min && value.max <= this.max );
},
// ----------
// Function: containsWithin
// Whether the <Range>'s interior contains the given value or not
//
// Paramaters
// - a number or <Range>
containsWithin: function(value) {
if (Utils.isNumber(value))
return ( value > this.min && value < this.max );
else if (isRange(value))
return ( value.min > this.min && value.max < this.max );
},
};
// ##########
// Class: Subscribable
// A mix-in for allowing objects to collect subscribers for custom events.