home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / germ_roundup.swf / scripts / __Packages / smashing / Point.as < prev    next >
Encoding:
Text File  |  2007-03-20  |  4.3 KB  |  201 lines

  1. class smashing.Point
  2. {
  3.    var x;
  4.    var y;
  5.    function Point(x, y)
  6.    {
  7.       this.x = Number(x);
  8.       this.y = Number(y);
  9.    }
  10.    function get length()
  11.    {
  12.       var _loc1_ = this;
  13.       return Math.sqrt(_loc1_.x * _loc1_.x + _loc1_.y * _loc1_.y);
  14.    }
  15.    function set length(newLength)
  16.    {
  17.       var _loc1_ = this;
  18.       if(_loc1_.length != 0)
  19.       {
  20.          var _loc2_ = newLength / _loc1_.length;
  21.          _loc1_.x *= _loc2_;
  22.          _loc1_.y *= _loc2_;
  23.       }
  24.    }
  25.    function get lengthSqu()
  26.    {
  27.       var _loc1_ = this;
  28.       return _loc1_.x * _loc1_.x + _loc1_.y * _loc1_.y;
  29.    }
  30.    function copy()
  31.    {
  32.       return new smashing.Point(this.x,this.y);
  33.    }
  34.    function addPoint(p)
  35.    {
  36.       return new smashing.Point(p.x + this.x,p.y + this.y);
  37.    }
  38.    function subtractPoint(p)
  39.    {
  40.       return new smashing.Point(this.x - p.x,this.y - p.y);
  41.    }
  42.    function addScalar(n)
  43.    {
  44.       return new smashing.Point(this.x + n,this.y + n);
  45.    }
  46.    function subtractScalar(n)
  47.    {
  48.       return new smashing.Point(this.x - n,this.y - n);
  49.    }
  50.    function addPointMe(p)
  51.    {
  52.       this.x += p.x;
  53.       this.y += p.y;
  54.    }
  55.    function subtractPointMe(p)
  56.    {
  57.       this.x -= p.x;
  58.       this.y -= p.y;
  59.    }
  60.    function addScalarMe(n)
  61.    {
  62.       this.x += n;
  63.       this.y += n;
  64.    }
  65.    function subtractScalarMe(n)
  66.    {
  67.       this.x -= n;
  68.       this.y -= n;
  69.    }
  70.    function multiply(nFactor)
  71.    {
  72.       var _loc1_ = this.copy();
  73.       _loc1_.x *= nFactor;
  74.       _loc1_.y *= nFactor;
  75.       return _loc1_;
  76.    }
  77.    function divide(n)
  78.    {
  79.       var _loc2_ = n;
  80.       var _loc1_ = this.copy();
  81.       if(_loc2_ == 0)
  82.       {
  83.          _loc1_.x = 0;
  84.          _loc1_.y = 0;
  85.       }
  86.       _loc1_.x /= _loc2_;
  87.       _loc1_.y /= _loc2_;
  88.       return _loc1_;
  89.    }
  90.    function multiplyMe(n)
  91.    {
  92.       this.x *= n;
  93.       this.y *= n;
  94.    }
  95.    function divideMe(n)
  96.    {
  97.       this.x /= n;
  98.       this.y /= n;
  99.    }
  100.    function dot(p)
  101.    {
  102.       return this.x * p.x + this.y * p.y;
  103.    }
  104.    function cross()
  105.    {
  106.       return new smashing.Point(this.y,- this.x);
  107.    }
  108.    function normalize()
  109.    {
  110.       var _loc1_ = this;
  111.       if(!_loc1_.x && !_loc1_.y)
  112.       {
  113.       }
  114.       var _loc2_ = _loc1_.length;
  115.       return new smashing.Point(_loc1_.x / _loc2_,_loc1_.y / _loc2_);
  116.    }
  117.    function normalizeMe()
  118.    {
  119.       var _loc1_ = this;
  120.       if(!(!_loc1_.x && !_loc1_.y))
  121.       {
  122.          var _loc2_ = _loc1_.length;
  123.          _loc1_.x /= _loc2_;
  124.          _loc1_.y /= _loc2_;
  125.       }
  126.    }
  127.    function reverse()
  128.    {
  129.       var _loc1_ = new smashing.Point(this.x * -1,this.y * -1);
  130.       return _loc1_;
  131.    }
  132.    function reverseMe()
  133.    {
  134.       this.x *= -1;
  135.       this.y *= -1;
  136.    }
  137.    function rotateMe(nRad)
  138.    {
  139.       var _loc2_ = this;
  140.       var _loc3_ = Math.sin(nRad);
  141.       var _loc1_ = Math.cos(nRad);
  142.       if(_loc3_ > 1 || _loc3_ < -1)
  143.       {
  144.       }
  145.       if(_loc1_ > 1 || _loc1_ < -1)
  146.       {
  147.       }
  148.       _loc2_.x = _loc2_.x * _loc1_ + _loc2_.y * (- _loc3_);
  149.       _loc2_.y = _loc2_.x * _loc3_ + _loc2_.y * _loc1_;
  150.    }
  151.    function rotate(nRad)
  152.    {
  153.       var _loc3_ = this;
  154.       var _loc2_ = Math.sin(nRad);
  155.       var _loc1_ = Math.cos(nRad);
  156.       if(_loc2_ > 1 || _loc2_ < -1)
  157.       {
  158.       }
  159.       if(_loc1_ > 1 || _loc1_ < -1)
  160.       {
  161.       }
  162.       return new smashing.Point(_loc3_.x * _loc1_ + _loc3_.y * (- _loc2_),_loc3_.x * _loc2_ + _loc3_.y * _loc1_);
  163.    }
  164.    function rotateSinCos(nSin, nCos)
  165.    {
  166.       var _loc1_ = this;
  167.       _loc1_.x = _loc1_.x * nCos + _loc1_.y * (- nSin);
  168.       _loc1_.y = _loc1_.x * nSin + _loc1_.y * nCos;
  169.    }
  170.    function findCosine(vOther)
  171.    {
  172.       var _loc2_ = this.dot(vOther);
  173.       var _loc1_ = this.length * vOther.length;
  174.       var _loc3_ = _loc2_ / _loc1_;
  175.       return _loc3_;
  176.    }
  177.    function equals(p)
  178.    {
  179.       if(this.x == p.x && this.y == p.y)
  180.       {
  181.          return true;
  182.       }
  183.       return false;
  184.    }
  185.    function zero()
  186.    {
  187.       this.x = 0;
  188.       this.y = 0;
  189.    }
  190.    function distSqu(p)
  191.    {
  192.       var _loc2_ = p.x - this.x;
  193.       var _loc1_ = p.y - this.y;
  194.       return _loc2_ * _loc2_ + _loc1_ * _loc1_;
  195.    }
  196.    function toString()
  197.    {
  198.       return "Point (" + this.x + "," + this.y + ")";
  199.    }
  200. }
  201.