function Bounds(x, y, width, height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}
Bounds.prototype.load = function(other) {
    this.x = other.x;
    this.y = other.y;
    this.width = other.width;
    this.height = other.height;
}
Bounds.prototype.loadDiag = function(x1, y1, x2, y2) {
    if (x2 < x1) {
        var t = x1; x1 = x2; x2 = t;
    }
    if (y2 < y1) {
        var t = y1; y1 = y2; y2 = t;
    }
    this.x = x1;
    this.y = y1;
    this.width = x2 - x1;
    this.height = y2 - y1;
}
Bounds.prototype.loadRect = function(rect) {
    this.loadDiag(rect.tr.x, rect.tr.y,
                  rect.bl.x, rect.bl.y);
}
Bounds.prototype.minX = function() { return this.x; }
Bounds.prototype.minY = function() { return this.y; }
Bounds.prototype.maxX = function() { return this.x + this.width; }
Bounds.prototype.maxY = function() { return this.y + this.height; }
Bounds.prototype.add = function(other) {
    if (!other.exist()) return;
    if (this.exist()) {
        this.loadDiag(Math.min(this.minX(), other.minX()),
                      Math.min(this.minY(), other.minY()),
                      Math.max(this.maxX(), other.maxX()),
                      Math.max(this.maxY(), other.maxY()));
    } else {
        this.load(other);
    }
}
Bounds.prototype.addRect = function(rect) {
    if (this.exist()) {
        this.loadDiag(Math.min(this.minX(), rect.tl.x),
                      Math.min(this.minY(), rect.tl.y),
                      Math.max(this.maxX(), rect.br.x),
                      Math.max(this.maxY(), rect.br.y));
    } else {
        this.loadRect(rect);
    }
}
Bounds.prototype.addPoint = function(pt) {
    this.loadDiag(Math.min(this.minX(), pt.x),
                  Math.min(this.minY(), pt.y),
                  Math.max(this.maxX(), pt.x),
                  Math.max(this.maxY(), pt.y));
}
Bounds.prototype.toRect = function() {
    var points = this.toPoints();
    return {
        tl: points[0],
        tr: points[1],
        br: points[2],
        bl: points[3]
    };
}
Bounds.prototype.toPoints = function() {
    return [
        { x: this.x, y: this.y },
        { x: this.x + this.width, y: this.y },
        { x: this.x + this.width, y: this.y + this.height },
        { x: this.x, y: this.y + this.height }
    ];
}
Bounds.prototype.exist = function() {
    // if one of the values is NaN, then the whole bounds are invalid?
    return (this.x === NaN);
}
Bounds.prototype.clone = function() {
    return new Bounds(this.x, this.y,
                      this.width, this.height);
}
Bounds.fromRect = function(rect) {
    var bounds = new Bounds();
    bounds.loadRect(rect);
    return bounds;
}
Bounds.fromPoints = function(pts) {
    var bounds = new Bounds();
    bounds.loadDiag(pts[0].x, pts[0].y,
                    pts[2].x, pts[2].y);
    return bounds;
}
Bounds.NONE = new Bounds(NaN, NaN, NaN, NaN);

module.exports = Bounds;

@@ -538,136 +538,8 @@
 ;%0A%7D%0A
-Bounds.prototype.loadRect = function(rect) %7B%0A    this.loadDiag(rect.tr.x, rect.tr.y,%0A                  rect.bl.x, rect.bl.y);%0A%7D%0A
 Boun
@@ -584,24 +584,24 @@
 n this.x; %7D%0A
+
 Bounds.proto
@@ -1162,351 +1162,8 @@
 %7D%0A%7D%0A
-Bounds.prototype.addRect = function(rect) %7B%0A    if (this.exist()) %7B%0A        this.loadDiag(Math.min(this.minX(), rect.tl.x),%0A                      Math.min(this.minY(), rect.tl.y),%0A                      Math.max(this.maxX(), rect.br.x),%0A                      Math.max(this.maxY(), rect.br.y));%0A    %7D else %7B%0A        this.loadRect(rect);%0A    %7D%0A%7D%0A
 Boun
@@ -1396,194 +1396,8 @@
 ;%0A%7D%0A
-Bounds.prototype.toRect = function() %7B%0A    var points = this.toPoints();%0A    return %7B%0A        tl: points%5B0%5D,%0A        tr: points%5B1%5D,%0A        br: points%5B2%5D,%0A        bl: points%5B3%5D%0A    %7D;%0A%7D%0A
 Boun
@@ -1856,24 +1856,24 @@
 .x, this.y,%0A
+
             
@@ -1914,291 +1914,8 @@
 ;%0A%7D%0A
-Bounds.fromRect = function(rect) %7B%0A    var bounds = new Bounds();%0A    bounds.loadRect(rect);%0A    return bounds;%0A%7D%0ABounds.fromPoints = function(pts) %7B%0A    var bounds = new Bounds();%0A    bounds.loadDiag(pts%5B0%5D.x, pts%5B0%5D.y,%0A                    pts%5B2%5D.x, pts%5B2%5D.y);%0A    return bounds;%0A%7D%0A
 Boun

remove rect from bounds