/*
* Script: crect.js
* Class : CRect
* Author: UMG
* Descrpition: Rectangle class.
*/

function CRect(nLeft,nRight,nTop,nBottom) {
  this.left = 0; this.right = 0; this.top = 0; this.bottom = 0;
  this.expand          = _crectExpand;
  this.getHeight       = _crectGetHeight;
  this.getWidth        = _crectGetWidth;
  this.hasSize         = _crectHasSize;
  this.isEmpty         = _crectIsEmpty;
  this.makeNormalized  = _crectMakeNormalized;
  this.put             = _crectPut;
  this.putRect         = _crectPutRect;
  this.setEmpty        = _crectSetEmpty;
  this.setEmpty();this.put(nLeft,nRight,nTop,nBottom);
}

function _crectExpand() {
  var xOff = 0.0035, yOff = 0.0035, nPct = 1.15;
  var x = this.left,   w = xOff;
  var y = this.bottom, h = yOff;
  if (this.getHeight() > 0) {
    h = (this.getHeight() * nPct) / 2.0;
    y = (this.bottom + this.top)  / 2.0;
  }
  if (this.getWidth() > 0) {
    w = (this.getWidth() * nPct) / 2.0;
    x = (this.left + this.right) / 2.0;
  } 
  this.left   = x - w; this.right = x + w;
  this.bottom = y - h; this.top   = y + h;
}

function _crectGetHeight() {return Math.abs(this.top-this.bottom);}

function _crectGetWidth() {return Math.abs(this.left-this.right);}

function _crectHasSize() {return ((this.getWidth()>0)||(this.getHeight()>0))}

function _crectIsEmpty() {
  return ((this.left == -9999) && (this.right  == -9999) && 
          (this.top  == -9999) && (this.bottom == -9999));
}

function _crectMakeNormalized() {
  var r = new CRect(this.left,this.right,this.top,this.bottom);
  if (this.left>this.right) {r.left=this.right; r.right =this.left;}
  if (this.top >this.bottom){r.top =this.bottom;r.bottom=this.top;}
  return r;
}

function _crectPut(nLeft,nRight,nTop,nBottom) {
  if (nLeft!=null) {
    this.left=nLeft;this.right=nRight;this.top=nTop;this.bottom=nBottom;
  }
}

function _crectPutRect(oRect) {
  if ((oRect!=null)&&(oRect.left!=null)) {
    this.left=oRect.left;this.right=oRect.right;this.top=oRect.top;this.bottom=oRect.bottom;
  }
}

function _crectSetEmpty() {
  this.left=-9999;this.right=-9999;this.top=-9999;this.bottom=-9999;
}


