Source for file MathUtils.php
Documentation is available at MathUtils.php
* Description: Math utility procedures
* @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
* @link http://www.steema.com
/*static*/ public/*final double*/ $PISTEP = M_PI; // / 180;
function __get( $property ) {
$method = "get{$property}";
function __set ( $property,$value ) {
$method = "set{$property}";
return $this->$method($value);
* A constant holding the positive infinity of type
* <code>double</code>. It is equal to the value returned by
* <code>Double.longBitsToDouble(0x7ff0000000000000L)</code>.
// public static /*final*/ $POSITIVE_INFINITY = 1.0 / 0.0;
* A constant holding the negative infinity of type
* <code>double</code>. It is equal to the value returned by
* <code>Double.longBitsToDouble(0xfff0000000000000L)</code>.
// public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
* A constant holding a Not-a-Number (NaN) value of type
* <code>double</code>. It is equivalent to the value returned by
* <code>Double.longBitsToDouble(0x7ff8000000000000L)</code>.
// public static final double NaN = 0.0d / 0.0;
* A constant holding the largest positive finite value of type
* (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to
* the hexadecimal floating-point literal
* <code>0x1.fffffffffffffP+1023</code> and also equal to
* <code>Double.longBitsToDouble(0x7fefffffffffffffL)</code>.
// public static final double MAX_VALUE = 1.7976931348623157e+308; // 0x1.fffffffffffffP+1023
* A constant holding the smallest positive nonzero value of type
* <code>double</code>, 2<sup>-1074</sup>. It is equal to the
* hexadecimal floating-point literal
* <code>0x0.0000000000001P-1022</code> and also equal to
* <code>Double.longBitsToDouble(0x1L)</code>.
// public static final double MIN_VALUE = 4.9e-324; // 0x0.0000000000001P-1022
static public function /*final double*/ sqr(/*double*/ $x) {
* Note: This function has been added to MathUtils because J2ME Math
* class does not include it.
* Returns Math.log of value parameter.
public static function /*double*/ log(/*double*/ $value) {
static public function _log($x, $numBase) {
return log($x) / log($numBase);
// Note: This function is implemented here instead of using Math.round
// because J2ME Math class does not include it (as far as in CLDC 1.1)
* Returns the integer nearest to "value" parameter
public static function round($value) {
return /*(int)*/ floor($value + 0.5); // before 0.5d);
if ($aFrom. x != $aTo. x) {
$tmp = MathUtils::atan2(($aTo->getY() - $aFrom->getY()), ($aTo->getX() - $aFrom->getX()));
$res->x -= self::round($aDist * $tmpCos);
$res->y -= self::round($aDist * $tmpSin);
if ($aTo->getY() < $aFrom->getY()) {
$res->setY($res->getY() + $aDist);
$res->setY($res->getY() - $aDist);
static public function /*double*/ calcDistance(/*Point/* $p, /*int*/ $x0, /*int*/ $y0, /*int*/ $x1, /*int*/ $y1) {
if (($x1 == $x0) && ($y1 == $y0)) {
return sqrt($dx * $dx + $dy * $dy);
$tmpResult = (($p. x - $x0) * $dx + ($p. y - $y0) * $dy) /
} else if ($tmpResult > 1) {
$dx = $p. x - ($x0 + $tmpResult * $dx);
$dy = $p. y - ($y0 + $tmpResult * $dy);
return sqrt($dx * $dx + $dy * $dy);
static public function /*boolean*/ pointInLineTolerance(/*Point*/ $p, /*int*/ $x0, /*int*/ $y0, /*int*/ $x1,
/*int*/ $y1, /*int*/ $tolerance) {
if ((($p. x == $x0) && ($p. y == $y0)) || (($p. x == $x1) && ($p. y == $y1))) {
/** TODO REMOVE THIS FUNCTION BCOS BCCCOMP IS USED INSTEAD
* Compares Double d1 with d2. Returns 0 if both are equal.
* Returns -1 if d1 is lower than d2, and 1 if d1 is bigger than d2.
return - 1; // Neither val is NaN, thisVal is smaller
return 1; // Neither val is NaN, thisVal is larger
/*long*/ $thisBits = Double. doubleToLongBits($d1);
/*long*/ $anotherBits = Double. doubleToLongBits($d2);
return ($thisBits == $anotherBits ? 0 : // Values are equal
($thisBits < $anotherBits ? - 1 : // (-0.0, 0.0) or (!NaN, NaN)
1)); // (0.0, -0.0) or (NaN, !NaN)
* Note: This method has been implemented here in MathUtils class
* because J2ME Math class does not include it.
public static function atan2($y, $x) {
* Note: This method has been implemented here in MathUtils class
* because J2ME Math class does not include it.
public static function pow($a, $b) {
* Note: This method has been implemented here in MathUtils class
* because J2ME Math class does not include it.
public static function exp($a) {
|