home *** CD-ROM | disk | FTP | other *** search
- class Library.Utils.MoreMath
- {
- static var MATH_PI = 3.141592653589793;
- function MoreMath()
- {
- }
- static function getRandomRange(__nMin, __nMax)
- {
- return Math.floor(Math.random() * (__nMax + 1 - __nMin)) + __nMin;
- }
- static function getPolarity(__nNum)
- {
- var _loc1_ = 0;
- if(__nNum < 0)
- {
- _loc1_ = -1;
- }
- else if(__nNum > 0)
- {
- _loc1_ = 1;
- }
- return _loc1_;
- }
- static function getReachZero(__nNum, __nReducer)
- {
- return Library.Utils.MoreMath.getReachNum(__nNum,0,__nReducer);
- }
- static function getReachNum(__nNum, __nTargetNum, __nReducer)
- {
- var _loc1_ = __nNum;
- if(_loc1_ != __nTargetNum)
- {
- if(_loc1_ < __nTargetNum)
- {
- _loc1_ += __nReducer;
- if(_loc1_ > __nTargetNum)
- {
- _loc1_ = __nTargetNum;
- }
- }
- else
- {
- _loc1_ -= __nReducer;
- if(_loc1_ < __nTargetNum)
- {
- _loc1_ = __nTargetNum;
- }
- }
- }
- return _loc1_;
- }
- static function getDistance(__nX1, __nY1, __nX2, __nY2)
- {
- return Math.sqrt(Math.pow(Math.abs(__nX2 - __nX1),2) + Math.pow(Math.abs(__nY2 - __nY1),2));
- }
- static function getManhattanDistance(_x1, _y1, _x2, _y2)
- {
- return Math.abs(_x1 - _x2) + Math.abs(_y1 - _y2);
- }
- static function getHypotenuse(__nDX, __nDY)
- {
- return Math.sqrt(Math.pow(__nDX,2) + Math.pow(__nDY,2));
- }
- static function getAngle(__nX1, __nY1, __nX2, __nY2)
- {
- var _loc2_ = undefined;
- var _loc1_ = undefined;
- var _loc4_ = undefined;
- var _loc3_ = undefined;
- _loc2_ = __nX2 - __nX1;
- _loc1_ = __nY2 - __nY1;
- _loc4_ = Math.atan2(_loc1_,_loc2_);
- _loc3_ = Library.Utils.MoreMath.getDegreeFromRadius(_loc4_);
- return _loc3_;
- }
- static function getDegreeFromRadius(__nRadius)
- {
- var _loc1_ = __nRadius / Library.Utils.MoreMath.MATH_PI * 180;
- return _loc1_;
- }
- static function getRadianFromDegree(__nDegree)
- {
- var _loc1_ = __nDegree * (Library.Utils.MoreMath.MATH_PI / 180);
- return _loc1_;
- }
- static function getBoundsCenter(_oBox)
- {
- var _loc3_ = (_oBox.xMin + _oBox.xMax) / 2;
- var _loc2_ = (_oBox.yMin + _oBox.yMax) / 2;
- return {x:_loc3_,y:_loc2_};
- }
- }
-