home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / breakawish.swf / scripts / __Packages / Library / Utils / MoreMath.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  2.4 KB  |  93 lines

  1. class Library.Utils.MoreMath
  2. {
  3.    static var MATH_PI = 3.141592653589793;
  4.    function MoreMath()
  5.    {
  6.    }
  7.    static function getRandomRange(__nMin, __nMax)
  8.    {
  9.       return Math.floor(Math.random() * (__nMax + 1 - __nMin)) + __nMin;
  10.    }
  11.    static function getPolarity(__nNum)
  12.    {
  13.       var _loc1_ = 0;
  14.       if(__nNum < 0)
  15.       {
  16.          _loc1_ = -1;
  17.       }
  18.       else if(__nNum > 0)
  19.       {
  20.          _loc1_ = 1;
  21.       }
  22.       return _loc1_;
  23.    }
  24.    static function getReachZero(__nNum, __nReducer)
  25.    {
  26.       return Library.Utils.MoreMath.getReachNum(__nNum,0,__nReducer);
  27.    }
  28.    static function getReachNum(__nNum, __nTargetNum, __nReducer)
  29.    {
  30.       var _loc1_ = __nNum;
  31.       if(_loc1_ != __nTargetNum)
  32.       {
  33.          if(_loc1_ < __nTargetNum)
  34.          {
  35.             _loc1_ += __nReducer;
  36.             if(_loc1_ > __nTargetNum)
  37.             {
  38.                _loc1_ = __nTargetNum;
  39.             }
  40.          }
  41.          else
  42.          {
  43.             _loc1_ -= __nReducer;
  44.             if(_loc1_ < __nTargetNum)
  45.             {
  46.                _loc1_ = __nTargetNum;
  47.             }
  48.          }
  49.       }
  50.       return _loc1_;
  51.    }
  52.    static function getDistance(__nX1, __nY1, __nX2, __nY2)
  53.    {
  54.       return Math.sqrt(Math.pow(Math.abs(__nX2 - __nX1),2) + Math.pow(Math.abs(__nY2 - __nY1),2));
  55.    }
  56.    static function getManhattanDistance(_x1, _y1, _x2, _y2)
  57.    {
  58.       return Math.abs(_x1 - _x2) + Math.abs(_y1 - _y2);
  59.    }
  60.    static function getHypotenuse(__nDX, __nDY)
  61.    {
  62.       return Math.sqrt(Math.pow(__nDX,2) + Math.pow(__nDY,2));
  63.    }
  64.    static function getAngle(__nX1, __nY1, __nX2, __nY2)
  65.    {
  66.       var _loc2_ = undefined;
  67.       var _loc1_ = undefined;
  68.       var _loc4_ = undefined;
  69.       var _loc3_ = undefined;
  70.       _loc2_ = __nX2 - __nX1;
  71.       _loc1_ = __nY2 - __nY1;
  72.       _loc4_ = Math.atan2(_loc1_,_loc2_);
  73.       _loc3_ = Library.Utils.MoreMath.getDegreeFromRadius(_loc4_);
  74.       return _loc3_;
  75.    }
  76.    static function getDegreeFromRadius(__nRadius)
  77.    {
  78.       var _loc1_ = __nRadius / Library.Utils.MoreMath.MATH_PI * 180;
  79.       return _loc1_;
  80.    }
  81.    static function getRadianFromDegree(__nDegree)
  82.    {
  83.       var _loc1_ = __nDegree * (Library.Utils.MoreMath.MATH_PI / 180);
  84.       return _loc1_;
  85.    }
  86.    static function getBoundsCenter(_oBox)
  87.    {
  88.       var _loc3_ = (_oBox.xMin + _oBox.xMax) / 2;
  89.       var _loc2_ = (_oBox.yMin + _oBox.yMax) / 2;
  90.       return {x:_loc3_,y:_loc2_};
  91.    }
  92. }
  93.