home *** CD-ROM | disk | FTP | other *** search
- class smashing.Point
- {
- var x;
- var y;
- function Point(x, y)
- {
- this.x = Number(x);
- this.y = Number(y);
- }
- function get length()
- {
- var _loc1_ = this;
- return Math.sqrt(_loc1_.x * _loc1_.x + _loc1_.y * _loc1_.y);
- }
- function set length(newLength)
- {
- var _loc1_ = this;
- if(_loc1_.length != 0)
- {
- var _loc2_ = newLength / _loc1_.length;
- _loc1_.x *= _loc2_;
- _loc1_.y *= _loc2_;
- }
- }
- function get lengthSqu()
- {
- var _loc1_ = this;
- return _loc1_.x * _loc1_.x + _loc1_.y * _loc1_.y;
- }
- function copy()
- {
- return new smashing.Point(this.x,this.y);
- }
- function addPoint(p)
- {
- return new smashing.Point(p.x + this.x,p.y + this.y);
- }
- function subtractPoint(p)
- {
- return new smashing.Point(this.x - p.x,this.y - p.y);
- }
- function addScalar(n)
- {
- return new smashing.Point(this.x + n,this.y + n);
- }
- function subtractScalar(n)
- {
- return new smashing.Point(this.x - n,this.y - n);
- }
- function addPointMe(p)
- {
- this.x += p.x;
- this.y += p.y;
- }
- function subtractPointMe(p)
- {
- this.x -= p.x;
- this.y -= p.y;
- }
- function addScalarMe(n)
- {
- this.x += n;
- this.y += n;
- }
- function subtractScalarMe(n)
- {
- this.x -= n;
- this.y -= n;
- }
- function multiply(nFactor)
- {
- var _loc1_ = this.copy();
- _loc1_.x *= nFactor;
- _loc1_.y *= nFactor;
- return _loc1_;
- }
- function divide(n)
- {
- var _loc2_ = n;
- var _loc1_ = this.copy();
- if(_loc2_ == 0)
- {
- _loc1_.x = 0;
- _loc1_.y = 0;
- }
- _loc1_.x /= _loc2_;
- _loc1_.y /= _loc2_;
- return _loc1_;
- }
- function multiplyMe(n)
- {
- this.x *= n;
- this.y *= n;
- }
- function divideMe(n)
- {
- this.x /= n;
- this.y /= n;
- }
- function dot(p)
- {
- return this.x * p.x + this.y * p.y;
- }
- function cross()
- {
- return new smashing.Point(this.y,- this.x);
- }
- function normalize()
- {
- var _loc1_ = this;
- if(!_loc1_.x && !_loc1_.y)
- {
- }
- var _loc2_ = _loc1_.length;
- return new smashing.Point(_loc1_.x / _loc2_,_loc1_.y / _loc2_);
- }
- function normalizeMe()
- {
- var _loc1_ = this;
- if(!(!_loc1_.x && !_loc1_.y))
- {
- var _loc2_ = _loc1_.length;
- _loc1_.x /= _loc2_;
- _loc1_.y /= _loc2_;
- }
- }
- function reverse()
- {
- var _loc1_ = new smashing.Point(this.x * -1,this.y * -1);
- return _loc1_;
- }
- function reverseMe()
- {
- this.x *= -1;
- this.y *= -1;
- }
- function rotateMe(nRad)
- {
- var _loc2_ = this;
- var _loc3_ = Math.sin(nRad);
- var _loc1_ = Math.cos(nRad);
- if(_loc3_ > 1 || _loc3_ < -1)
- {
- }
- if(_loc1_ > 1 || _loc1_ < -1)
- {
- }
- _loc2_.x = _loc2_.x * _loc1_ + _loc2_.y * (- _loc3_);
- _loc2_.y = _loc2_.x * _loc3_ + _loc2_.y * _loc1_;
- }
- function rotate(nRad)
- {
- var _loc3_ = this;
- var _loc2_ = Math.sin(nRad);
- var _loc1_ = Math.cos(nRad);
- if(_loc2_ > 1 || _loc2_ < -1)
- {
- }
- if(_loc1_ > 1 || _loc1_ < -1)
- {
- }
- return new smashing.Point(_loc3_.x * _loc1_ + _loc3_.y * (- _loc2_),_loc3_.x * _loc2_ + _loc3_.y * _loc1_);
- }
- function rotateSinCos(nSin, nCos)
- {
- var _loc1_ = this;
- _loc1_.x = _loc1_.x * nCos + _loc1_.y * (- nSin);
- _loc1_.y = _loc1_.x * nSin + _loc1_.y * nCos;
- }
- function findCosine(vOther)
- {
- var _loc2_ = this.dot(vOther);
- var _loc1_ = this.length * vOther.length;
- var _loc3_ = _loc2_ / _loc1_;
- return _loc3_;
- }
- function equals(p)
- {
- if(this.x == p.x && this.y == p.y)
- {
- return true;
- }
- return false;
- }
- function zero()
- {
- this.x = 0;
- this.y = 0;
- }
- function distSqu(p)
- {
- var _loc2_ = p.x - this.x;
- var _loc1_ = p.y - this.y;
- return _loc2_ * _loc2_ + _loc1_ * _loc1_;
- }
- function toString()
- {
- return "Point (" + this.x + "," + this.y + ")";
- }
- }
-