var Rectangle = Class.create({
  initialize:function() {//{{{
    this.x = 0;
    this.y = 0;
    this.w = 0;
    this.h = 0;
  },//}}}
  set:function(x,y,w,h) {//{{{
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
  },//}}}
  getXMid:function() {//{{{
    return this.x + (this.w /2);
  },//}}}
  getXFar:function() {//{{{
    return this.x + this.w;
  },//}}}
  getYMid:function() {//{{{
    return this.y + (this.h /2);
  },//}}}
  getYFar:function() {//{{{
    return this.y + this.h;
  },//}}}
  setLeft:function(x) {//{{{
    var dw = x - this.x;
    if(this.w - dw < 0) {
      this.x = this.x+this.w;
      this.w = 0;
    }
    else {
      this.x = x;
      this.w = this.w - dw;
    }
  },//}}}
  setTop:function(y) {//{{{
    var dh = y-this.y;
    if(this.h - dh < 0) {
      this.y = this.y+this.h;
      this.h = 0;
    }
    else {
      this.y = y;
      this.h = this.h - dh;
    }
  },//}}}
  setRight:function(x) {//{{{
    if(x-this.x < 0 )
      this.w = 0;
    else
      this.w = x-this.x;
  },//}}}
  setBottom:function(y) {//{{{
    if(y-this.y < 0)
      this.h = 0;
    else
      this.h = y-this.y;
  },//}}}
  realDimensions:function() {//{{{
    if(this.w <0) this.w = 0;
    if(this.h <0) this.h = 0;
  },//}}}
  inBounds:function(bounds) {//{{{
    if(this.x < bounds.x)
      this.setLeft(bounds.x);
    if(this.y < bounds.y)
      this.setTop(bounds.y);
    if(this.x+this.w > bounds.x+bounds.w)
      this.setRight(bounds.x+bounds.w);
    if(this.y+this.h > bounds.y+bounds.h)
      this.setBottom(bounds.y+bounds.h);
  },//}}}
  multiply:function(multiplier) {//{{{
    this.x = multiplier*this.x;
    this.y = multiplier*this.y;
    this.w = multiplier*this.w;
    this.h = multiplier*this.h;
  },//}}}
  round:function() {//{{{
    this.x = Math.round(this.x);
    this.y = Math.round(this.y);
    this.w = Math.round(this.w);
    this.h = Math.round(this.h);
  }//}}}
});

