compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (4)

View Page History
{zone-data}

{zone-data:skeletons}{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_BoundingBox extends Zend_Math_BoundingVolume
{
/**
* Checks if this bounding volume contains the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume contains the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function contains( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}
The code for this proposal can be found at [http://code.google.com/p/zend-math/source/browse/]

/**
* Checks if this bounding volume intersects with the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume intersects with the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function intersects( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_BoundingFrustum extends Zend_Math_BoundingVolume
{
/**
* Checks if this bounding volume contains the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume contains the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function contains( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}

/**
* Checks if this bounding volume intersects with the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume intersects with the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function intersects( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_BoundingSphere extends Zend_Math_BoundingVolume
{
/**
* Checks if this bounding volume contains the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume contains the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function contains( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}

/**
* Checks if this bounding volume intersects with the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume intersects with the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function intersects( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Vector_Vector3 )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided.' );
}
return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Math_BoundingVolume
{
/**
* Checks if this bounding volume contains the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume contains the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public abstract function contains( $value );

/**
* Checks if this bounding volume intersects with the given value.
*
* @param mixed $value The value to check for.
* @return bool Returns true when this bounding volume intersects with the given value; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public abstract function intersects( $value );
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Exception_DivideByZero extends Zend_Math_Exception
{
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Exception extends Zend_Exception
{
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Math_Interface
{
/**
* Adds the given value to this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function add( $value );

/**
* Subtracts the given value from this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function sub( $value );

/**
* Multiplies this value with the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function mul( $value );

/**
* Divides this value by the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function div( $value );

/**
* Converts this value to a readable string.
*
* @return string
*/
public function __toString();
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Matrix_Matrix44 extends Zend_Math_Matrix
{
/**
* Initializes a new instance of this class.
*/
public function __construct()
{
parent::__construct( 4, 4 );
}

/**
* Creates a scale matrix.
*
* @param mixed $X The X-position to set. This can be a number or a vector.
* @param mixed $Y The Y-position to set. This should be a number or empty when $X is a vector.
* @param mixed $Z The Z-position to set. This should be a number or empty when $X is a vector.
* @return Zend_Math_Matrix Returns a new instance of this class.
* @throws InvalidArgumentException When the given argument is not valid.
*/
public static function createScale( $X = 0.0, $Y = 0.0, $Z = 0.0 )
{
$result = new self();
if ( is_float( $X ) || is_int( $X ) )
{
$result->set( 0, 0, $X );
$result->set( 1, 1, $Y );
$result->set( 2, 2, $Z );
}
else if ( $X instanceof Zend_Math_Vector_Vector3 || $X instanceof Zend_Math_Vector_Vector4 )
{
$result->set( 0, 0, $X->getX() );
$result->set( 1, 1, $X->getY() );
$result->set( 2, 2, $X->getZ() );
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $result;
}

/**
* Creates a translation matrix.
*
* @param mixed $X The X-position to set. This can be a number or a vector.
* @param mixed $Y The Y-position to set. This should be a number or empty when $X is a vector.
* @param mixed $Z The Z-position to set. This should be a number or empty when $X is a vector.
* @return Zend_Math_Matrix Returns a new instance of this class.
* @throws InvalidArgumentException When the given argument is not valid.
*/
public static function createTranslation( $X = 0.0, $Y = 0.0, $Z = 0.0 )
{
$result = new self();
if ( is_float( $X ) || is_int( $X ) )
{
$result->set( 0, 3, $X );
$result->set( 1, 3, $Y );
$result->set( 2, 3, $Z );
}
else if ( $X instanceof Zend_Math_Vector_Vector3 || $X instanceof Zend_Math_Vector_Vector4 )
{
$result->set( 0, 3, $X->getX() );
$result->set( 1, 3, $X->getY() );
$result->set( 2, 3, $X->getZ() );
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $result;
}

/**
* Creates a rotation matrix around the X-axis.
*
* @param float $radians The radians to set.
* @return Zend_Math_Matrix Returns a new instance of this class.
*/
public static function createRotationX( $radians = 0.0 )
{
$result = new self();

// @todo

return $result;
}

/**
* Creates a rotation matrix around the Y-axis.
*
* @param float $radians The radians to set.
* @return Zend_Math_Matrix Returns a new instance of this class.
*/
public static function createRotationY( $radians = 0.0 )
{
$result = new self();

// @todo

return $result;
}

/**
* Creates a rotation matrix around the Z-axis.
* @param float $radians The radians to set.
* @return Zend_Math_Matrix Returns a new instance of this class.
*/
public static function createRotationZ( $radians = 0.0 )
{
$result = new self();

// @todo

return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Matrix implements Zend_Math_Interface, Iterator
{
/**
* The position of the iterator.
*
* @var int
*/
private $_position = 0;

/**
* The amount of components that this matrix has.
*
* @var array
*/
protected $_components = array();

/**
* The amount of rows that this matrix has.
*
* @var int
*/
protected $_rows = 0;

/**
* The amount of columns that this matrix has.
*
* @var int
*/
protected $_columns = 0;

/**
* Initializes a new instance of this class.
*
* @param int $rows The amount of rows that this matrix has.
* @param int $columns The amount of columns that this matrix has.
*/
public function __construct( $rows, $columns )
{
$this->_rows = $rows;
$this->_columns = $columns;
$this->makeIdentity();
}

/**
* Gets the amount of rows that this matrix has.
*
* @return int
*/
public function getRows()
{
return $this->_rows;
}

/**
* Gets the amount of columns that this matrix has.
*
* @return int
*/
public function getColumns()
{
return $this->_columns;
}

/**
* Gets the given component.
*
* @return float
* @throws OutOfBoundsException When the row or column is not valid.
*/
public function get( $row, $column )
{
if ( $row >= $this->_rows )
{
throw new OutOfBoundsException( 'Trying to get row ' . ( $row + 1 ) . ' while this matrix only has ' . $this->_rows . ' rows.' );
}
if ( $column >= $this->_columns )
{
throw new OutOfBoundsException( 'Trying to get column ' . ( $column + 1 ) . ' while this matrix only has ' . $this->column . ' columns.' );
}
return $this->_components[ $row * $this->_rows + $column ];
}

/**
* Sets the value to the given component.
*
* @param int $row The row to set.
* @param int $column The column to set.
* @param float $value The value to set.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws OutOfBoundsException When the row or column is not valid.
*/
public function set( $row, $column, $value )
{
if ( $row >= $this->_rows )
{
throw new OutOfBoundsException( 'Trying to set row ' . ( $row + 1 ) . ' while this matrix only has ' . $this->_rows . ' rows.' );
}
if ( $column >= $this->_columns )
{
throw new OutOfBoundsException( 'Trying to set column ' . ( $column + 1 ) . ' while this matrix only has ' . $this->_columns . ' columns.' );
}
$this->_components[ $row * $this->_rows + $column ] = $value;
return $this;
}

/**
* Adds the given value to this value.
*
* @param $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws OutOfBoundsException When the argument is a matrix but not of the same dimension.
* @throws InvalidArgumentException When the given argument is not a valid value.
*/
public function add( $value )
{
if ( $value instanceof Zend_Math_Matrix )
{
if ( $value->getRows() >= $this->_rows || $value->getColumns() >= $this->_columns )
{
throw new OutOfBoundsException( 'Matrices only support the addition of other matrices with the same rows and columns.' );
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] += $value;
}
}
else
{
throw new InvalidArgumentException( 'Matrices only supports the addition of matrices, floats and integers.' );
}
return $this;
}

/**
* Subtracts the given value from this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws OutOfBoundsException When the argument is a matrix but not of the same dimension.
* @throws InvalidArgumentException When the given argument is not a valid value.
*/
public function sub( $value )
{
if ( $value instanceof Zend_Math_Matrix )
{
if ( $value->getRows() >= $this->_rows || $value->getColumns() >= $this->_columns )
{
throw new OutOfBoundsException( 'Matrices only support the subtraction of other matrices with the same rows and columns.' );
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] -= $value;
}
}
else
{
throw new InvalidArgumentException( 'Matrices only supports the subtraction of matrices, floats and integers.' );
}
return $this;
}

/**
* Multiplies this value with the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not a valid value.
*/
public function mul( $value )
{
if ( $value instanceof Zend_Math_Matrix )
{
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] *= $value;
}
}
else
{
throw new InvalidArgumentException( 'Matrices only supports the multiplication of matrices, floats and integers.' );
}
return $this;
}

/**
* Divides this value by the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not a valid value.
*/
public function div( $value )
{
if ( $value instanceof Zend_Math_Matrix )
{
}
else if ( is_int( $value ) || is_float( $value ) )
{
if ( !$value )
{
throw new Zend_Math_Exception_DivideByZero( 'A value cannot be divided by zero.' );
}

foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] /= $value;
}
}
else
{
throw new InvalidArgumentException( 'Matrices only supports the division of matrices, floats and integers.' );
}
return $this;
}

/**
* Makes an identity matrix of this matrix.
*
* @return Zend_Math_Matrix Returns the instance of this class.
*/
public function makeIdentity()
{
$this->_components = array_fill( 0, $this->_rows * $this->_columns, 0.0 );
for ( $r = 0; $r < $this->_rows; ++$r )
{
$index = $r * $this->_rows + $r;
$this->_components[ $index ] = 1;
}
return $this;
}

/**
* Calculates the determinant of this matrix.
*
* @return float Returns the determinant of this matrix.
* @throws RuntimeException When this is not a square matrix.
*/
public function determinant()
{
if ( $this->_rows != $this->_columns )
{
throw new RuntimeException( 'The determinant of a matrix can only be calculated when the matrix is a square matrix.' );
}

$result = 0.0;
if ( $this->_rows == 1 )
{
$result = $this->_components[ 0 ];
}
else
{
for ( $i = 0; $i < $this->_columns; $i++ )
{
$minor = $this->calculateMinor( $this, 0, $i );
if ( $minor )
{
$result += ( pow( -1, $i ) * $this->_components[ $i ] * $minor->determinant() );
}
}
}
return $result;
}

/**
* Calculate the 'minor' of the given matrix at given position. The minor is the matrix formed by deleting the specified row and column from the matrix.
*
* @param Zend_Math_Matrix $matrix The matrix to work with.
* @param int $row The row to remove.
* @param int $column The column to remove.
* @return Zend_Math_Matrix Returns the matrix with the given row and column removed or null when no minor could be calculated.
*/
public function calculateMinor( Zend_Math_Matrix $matrix, $row, $column )
{
$result = null;

if ( $matrix->getRows() > 0 && $row < $matrix->getRows() && $column < $matrix->getColumns() )
{
$result = new Zend_Math_Matrix( $matrix->getRows() - 1, $matrix->getColumns() - 1 );

$a = $b = 0;

for ( $i = 0; $i < $matrix->getRows(); $i++ )
{
if( $i != $row )
{
$b = 0;
for ( $j = 0; $j < $matrix->getColumns(); $j++ )
{
if( $j != $column )
{
$result->set( $a, $b, $matrix->get( $i, $j ) );
$b++; // Increase column-count of minor
}
}
$a++; // Increase row-count of minor
}
}
}

return $result;
}

/**
* Transposes the rows and columns of this matrix and returns a new matrix.
*
* @return Zend_Math_Matrix Returns a new instance of this class containing the transposed matrix.
*/
public function transpose()
{
$result = clone $this;

for ( $r = 0; $r < $this->_rows; ++$r )
{
for ( $c = 0; $c < $this->_columns; ++$c )
{
$result->set( $c, $r, $this->get( $r, $c ) );
}
}

return $result;
}

/**
* Gets the current value from the iterator.
*
* @return mixed Returns the current value of the iterator.
*/
public function current()
{
return $this->_components[ $this->_position ];
}

/**
* Gets the current key from the iterator.
*
* @return int Returns the current key of the iterator.
*/
public function key()
{
return $this->_position;
}

/**
* Increases the iterator's position.
*
* @return void
*/
public function next()
{
++$this->_position;
}

/**
* Rewinds the iterator's position.
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
}

/**
* Checks if the iterator is still valid.
*
* @return boolean Returns true when the iterator is valid; false otherwise.
*/
public function valid()
{
return $this->_position < $this->getDimension();
}

/**
* Converts this value to a readable string.
*
* @return string
*/
public function __toString()
{
return implode( ',', $this->_components );
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Plane
{
/**
* The distance of the plane.
*
* @var float
*/
private $_distance;

/**
* The normal vector of the plane.
*
* @var Zend_Math_Vector_Vector3
*/
private $_normal;

/**
* Initializes a new instance of this class.
*
* @param float $distance The distance of this plane.
* @param Zend_Math_Vector_Vector3 $normal The normal of this plane.
*/
public function __construct( $distance, Zend_Math_Vector_Vector3 $normal )
{
$this->_distance = (float)$distance;
$this->_normal = $normal;
}

/**
* Gets the distance of this plane related to the math origin.
*
* @return float Returns the distance of this plane from the math origin.
*/
public function getDistance()
{
return $this->_distance;
}

/**
* Gets the normal of this plane.
*
* @return Zend_Math_Vector_Vector3 Returns a Zend_Math_Vector_Vector3 which represents the normal of this plane.
*/
public function getNormal()
{
return $this->_normal;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Point
{
/**
* The X-position of the point.
*
* @var float
*/
private $_x;

/**
* The Y-position of the point.
*
* @var float
*/
private $_y;

/**
* Initializes a new instance of this class.
*
* @param $x The X-position of this point.
* @param $y The Y-position of this point.
*/
public function __construct( $x, $y )
{
$this->_x = $x;
$this->_y = $y;
}

/**
* Gets the X-position of this point.
*
* @return float Returns a float representing the X-position of this point.
*/
public function getX()
{
return $this->_x;
}

/**
* Gets the Y-position of this point.
*
* @return float Returns a float representing the Y-position of this point.
*/
public function getY()
{
return $this->_y;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Quaternion implements Zend_Math_Interface
{
/**
* The X-component of this quaternion.
*
* @var float
*/
private $X;

/**
* The Y-component of this quaternion.
*
* @var float
*/
private $Y;

/**
* The Z-component of this quaternion.
*
* @var float
*/
private $Z;

/**
* The W-component of this quaternion.
*
* @var float
*/
private $W;

/**
* Initializes a new instance of this class.
*
* @param float $X The X-component to set.
* @param float $Y The Y-component to set.
* @param float $Z The Z-component to set.
* @param float $W The W-component to set.
*/
public function __construct( $X, $Y, $Z, $W )
{
$this->X = $X;
$this->Y = $Y;
$this->Z = $Z;
$this->W = $W;
}

/**
* Gets the X-component of this quaternion.
*
* @return float
*/
public function getX()
{
return $this->X;
}

/**
* Gets the Y-component of this quaternion.
*
* @return float
*/
public function getY()
{
return $this->Y;
}

/**
* Gets the Z-component of this quaternion.
*
* @return float
*/
public function getZ()
{
return $this->Z;
}

/**
* Gets the W-component of this quaternion.
*
* @return float
*/
public function getW()
{
return $this->W;
}

/**
* Calculates the dot product of this quaternion and the given quaternion.
*
* @param Zend_Math_Quaternion $value The quaternion to calculate with.
* @return float Returns the dot product between the two quaternions.
*/
public function dot( Zend_Math_Quaternion $value )
{
$result = 0.0;
return $result;
}

/**
* Calculates the conjugate of this quaternion.
*
* @return Zend_Math_Quaternion Returns the instance of this class.
*/
public function conjugate()
{
$this->X = -$this->X;
$this->Y = -$this->Y;
$this->Z = -$this->Z;
$this->W = -$this->W;
return $this;
}

/**
* Calculates the length of this quaternion.
*
* @return float Returns the length of this quaternion.
*/
public function length()
{
$result = 1.0;
return $result;
}

/**
* Normalizes this quaternion.
*
* @return Zend_Math_Quaternion Returns the instance of this quaternion.
*/
public function normalize()
{
$cloned = clone $this;
$cloned->div( $this->length() );

$this->X = $cloned->getX();
$this->Y = $cloned->getY();
$this->Z = $cloned->getZ();
$this->W = $cloned->getW();

return $this;
}

/**
* Creates a quaternion with no rotation.
*
* @return Zend_Math_Quaternion Returns the identity quaternion.
*/
public static function createIdentity()
{
return new Zend_Math_Quaternion( 0.0, 0.0, 0.0, 1.0 );
}

/**
* Creates a quaternion from the given yaw, pitch and roll value.
*
* @param float $yaw The angle in radians around the Y-axis.
* @param float $pitch The angle in radians around the X-axis.
* @param float $roll The angle in radians around the Z-axis.
* @return Zend_Math_Quaternion Returns the created quaternion.
*/
public static function createFromYawPitchRoll( $yaw, $pitch, $roll )
{
return new Zend_Math_Quaternion( 0.0, 0.0, 0.0, 1.0 );
}

/**
* Adds the given value to this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function add( $value )
{
return $this;
}

/**
* Subtracts the given value from this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function sub( $value )
{
return $this;
}

/**
* Multiplies this value with the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function mul( $value )
{
return $this;
}

/**
* Divides this value by the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function div( $value )
{
return $this;
}

/**
* Converts this value to a readable string.
*
* @return string
*/
public function __toString()
{
return implode( ',', array(
$this->X, $this->Y, $this->Z, $this->W,
) );
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Ray
{
/**
* The direction of this ray.
*
* @var Zend_Math_Vector_Vector3
*/
private $_direction;

/**
* The position of this ray.
*
* @var Zend_Math_Vector_Vector3
*/
private $_position;

/**
* Initializes a new instance of this class.
*
* @param Zend_Math_Vector_Vector3 $position The position of the ray.
* @param Zend_Math_Vector_Vector3 $direction The direction of the ray.
*/
public function __construct( Zend_Math_Vector_Vector3 $position, Zend_Math_Vector_Vector3 $direction )
{
$this->_position = $position;
$this->_direction = $direction;
}

/**
* Gets the direction of this ray.
*
* @return Zend_Math_Vector_Vector3 Returns a Zend_Math_Vector_Vector3 which represents the direction.
*/
public function getDirection()
{
return $this->_direction;
}

/**
* Gets the position of this ray.
*
* @return Zend_Math_Vector_Vector3 Returns a Zend_Math_Vector_Vector3 which represents the position.
*/
public function getPosition()
{
return $this->_position;
}

/**
* Checks if this ray intersects with the given value.
*
* @param mixed $value The value to calculate with.
* @return bool Returns true when there is an intersection; false otherwise.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function intersects( $value )
{
$result = false;
if ( $value instanceof Zend_Math_BoundingBox )
{
}
else if ( $value instanceof Zend_Math_BoundingFrustum )
{
}
else if ( $value instanceof Zend_Math_BoundingSphere )
{
}
else if ( $value instanceof Zend_Math_Plane )
{
}
else
{
throw new InvalidArgumentException( 'Invalid argument provided for intersects method.' );
}
return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Rectangle
{
/**
* The X-position of the rectangle.
*
* @var float
*/
private $_x;

/**
* The Y-position of the rectangle.
*
* @var float
*/
private $_y;

/**
* The width of the rectangle.
*
* @var float
*/
private $_width;

/**
* The height of the rectangle.
*
* @var float
*/
private $_height;

/**
* Initializes a new instance of this class.
*
* @param float $x The X-position of this rectangle.
* @param float $y The Y-position of this rectangle.
* @param float $width The width of this rectangle.
* @param float $height The height of this rectangle.
*/
public function __construct( $x, $y, $width, $height )
{
$this->_x = $x;
$this->_y = $y;
$this->_width = $width;
$this->_height = $height;
}

/**
* Gets the X-position of this rectangle.
*
* @return float Returns a float representing the X-position of this rectangle.
*/
public function getX()
{
return $this->_x;
}

/**
* Gets the Y-position of this rectangle.
*
* @return float Returns a float representing the Y-position of this rectangle.
*/
public function getY()
{
return $this->_y;
}

/**
* Gets the width of this rectangle.
*
* @return float Returns the width of this rectangle.
*/
public function getWidth()
{
return $this->_width;
}

/**
* Gets the height of this rectangle.
*
* @return float Returns the height of this rectangle.
*/
public function getHeight()
{
return $this->_height;
}

/**
* Gets the X-position of the left of this rectangle.
*
* @return float Returns a float representing the X-position of the left of this rectangle.
*/
public function getLeft()
{
return $this->_x;
}

/**
* Gets the Y-position of the top of this rectangle.
*
* @return float Returns a float representing the Y-position of the top of this rectangle.
*/
public function getTop()
{
return $this->_y;
}

/**
* Gets the X-position of the right of this rectangle.
*
* @return float Returns a float representing the X-position of the right of this rectangle.
*/
public function getRight()
{
return $this->_x + $this->_width;
}

/**
* Gets the Y-position of the bottom of this rectangle.
*
* @return float Returns a float representing the Y-position of the bottom of this rectangle.
*/
public function getBottom()
{
return $this->_y + $this->_height;
}

/**
* Gets the location of this rectangle.
*
* @return Point Returns a Point object which represents the location of this rectangle.
*/
public function getLocation()
{
return new Point( $this->_x, $this->_y );
}

/**
* Gets the size of this rectangle.
*
* @return Size Returns a Size object which represents the size of this rectangle.
*/
public function getSize()
{
return new Size( $this->_width, $this->_height );
}

/**
* Checks if the given value is inside the rectangle.
*
* @param mixed $x The X-position, point or rectangle value to check for.
* @param mixed $y The Y-position to check for.
* @return bool Returns true when the given value is inside this rectangle; false otherwise.
* @throws InvalidArgumentException When the given argument is not valid.
*/
public function contains( $x = 0.0, $y = 0.0 )
{
$result = false;
if ( $x instanceof Zend_Math_Point )
{
$x = $x->getX();
$y = $x->getY();

$result = ( ( $x >= $this->_x && $x <= $this->_x + $this->_width ) &&
( $y >= $this->_y && $y <= $this->_y + $this->_height ) );
}
else if ( $x instanceof Zend_Math_Rectangle )
{
// The complete rectangle must be present in this rectangle for this
// check to complete.

$posBegX = $x->getX();
$posBegY = $x->getY();
$posEndX = $x->getX() + $x->getWidth();
$posEndY = $x->getY() + $x->getHeight();

$result = ( ( $x >= $this->_x && $x <= $this->_x + $this->_width ) &&
( $y >= $this->_y && $y <= $this->_y + $this->_height ) );
}
else if ( is_float( $x ) || is_int( $x ) )
{
$result = ( ( $x >= $this->_x && $x <= $this->_x + $this->_width ) &&
( $y >= $this->_y && $y <= $this->_y + $this->_height ) );
}
else
{
throw new InvalidArgumentException( 'Can only offset a rectangle by supplying numbers or a Zend_Math_Point.' );
}
return $result;
}

/**
* Pushes the edges of this rectangle out by the given amount.
*
* @param mixed $horizontalAmount The value to push the sides out.
* @param mixed $verticalAmount The value to push the top and bottom out.
* @return Zend_Math_Rectangle Returns the updated instance of this class.
*/
public function inflate( $horizontalAmount, $verticalAmount )
{
$hSpace = $horizontalAmount / 2;
$vSpace = $verticalAmount / 2;

$this->_x -= $hSpace;
$this->_y -= $vSpace;

$this->_width += $hSpace;
$this->_height += $vSpace;

return false;
}

/**
* Checks if the given rectangle intersects with this rectangle.
*
* @param Zend_Math_Rectangle $value The value to check for.
* @return bool Returns true if the rectangle intersect; false otherwise.
*/
public function intersects( Zend_Math_Rectangle $value )
{
return (( $value->getLeft() > $this->getRight() ) ||
( $value->getRight() < $this->getLeft() ) ||
( $value->getTop() > $this->getBottom() ) ||
( $value->getBottom() < $this->getTop() ));
}

/**
* Changes the location of this rectangle.
*
* @param mixed $X The change in the X-position.
* @param mixed $y The change in the Y-position.
* @return Zend_Math_Rectangle Returns the updated instance of this class.
* @throws InvalidArgumentException When the given argument is not valid.
*/
public function offset( $x = 0.0, $y = 0.0 )
{
if ( $x instanceof Zend_Math_Point )
{
$this->_x += $x->getX();
$this->_y += $x->getY();
}
else if ( is_float( $x ) || is_int( $x ) )
{
$this->_x += $x;
$this->_y += $y;
}
else
{
throw new InvalidArgumentException( 'Can only offset a rectangle by supplying numbers or a Zend_Math_Point.' );
}
return $this;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Size
{
/**
* The width of the size.
*
* @var float
*/
private $_width;

/**
* The height of the size.
*
* @var float
*/
private $_height;

/**
* Initializes a new instance of this class.
*
* @param float $width The width of this size.
* @param float $height The height of this size.
*/
public function __construct( $width, $height )
{
$this->_width = $width;
$this->_height = $height;
}

/**
* Gets the width of this size.
*
* @return float Returns the width of this size.
*/
public function getWidth()
{
return $this->_width;
}

/**
* Gets the height of this size.
*
* @return float Returns the height of this size.
*/
public function getHeight()
{
return $this->_height;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Vector_Vector2 extends Zend_Math_Vector
{
/**
* Initializes a new instance of this class.
*
* @param float $X The X-value of this vector.
* @param float $Y The Y-value of this vector.
*/
public function __construct( $X = 0.0, $Y = 0.0 )
{
parent::__construct( 2 );
$this->set( 0, $X );
$this->set( 1, $Y );
}

/**
* Gets the X-value of this vector.
*
* @return float Returns the X-value as a float value.
*/
public function getX()
{
return $this->get( 0 );
}

/**
* Sets the X-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setX( $value )
{
$this->set( 0, $value );
return $this;
}

/**
* Gets the Y-value of this vector.
*
* @return float Returns the Y-value as a float value.
*/
public function getY()
{
return $this->get( 1 );
}

/**
* Sets the Y-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setY( $value )
{
$this->set( 1, $value );
return $this;
}

/**
* Gets the zero vector.
*
* @return Zend_Math_Vector2 Returns the zero vector.
*/
public final static function getZero()
{
return new Zend_Math_Vector2( 0.0, 0.0, 0.0, 0.0 );
}

/**
* Gets the X-unit vector.
*
* @return Zend_Math_Vector3 Returns the X-unit vector.
*/
public final static function getUnitX()
{
return new Zend_Math_Vector2( 1.0, 0.0 );
}

/**
* Gets the Y-unit vector.
*
* @return Zend_Math_Vector3 Returns the Y-unit vector.
*/
public final static function getUnitY()
{
return new Zend_Math_Vector2( 0.0, 1.0 );
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Vector_Vector3 extends Zend_Math_Vector
{
/**
* Initializes a new instance of this class.
*
* @param float $X The X-value of this vector.
* @param float $Y The Y-value of this vector.
* @param float $Z The Z-value of this vector.
*/
public function __construct( $X = 0.0, $Y = 0.0, $Z = 0.0 )
{
parent::__construct( 3 );
$this->set( 0, $X );
$this->set( 1, $Y );
$this->set( 2, $Z );
}

/**
* Gets the X-value of this vector.
*
* @return float Returns the X-value as a float value.
*/
public function getX()
{
return $this->get( 0 );
}

/**
* Sets the X-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setX( $value )
{
$this->set( 0, $value );
return $this;
}

/**
* Gets the Y-value of this vector.
*
* @return float Returns the Y-value as a float value.
*/
public function getY()
{
return $this->get( 1 );
}

/**
* Sets the Y-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setY( $value )
{
$this->set( 1, $value );
return $this;
}

/**
* Gets the Z-value of this vector.
*
* @return float Returns the Z-value as a float value.
*/
public function getZ()
{
return $this->get( 2 );
}

/**
* Sets the Z-value of this vector
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setZ( $value )
{
$this->set( 2, $value );
return $this;
}

/**
* Gets the zero vector.
*
* @return Zend_Math_Vector_Vector3 Returns the zero vector.
*/
public final static function getZero()
{
return new Zend_Math_Vector_Vector3( 0.0, 0.0, 0.0, 0.0 );
}

/**
* Gets the X-unit vector.
*
* @return Zend_Math_Vector_Vector3 Returns the X-unit vector.
*/
public final static function getUnitX()
{
return new Zend_Math_Vector_Vector3( 1.0, 0.0, 0.0 );
}

/**
* Gets the Y-unit vector.
*
* @return Zend_Math_Vector_Vector3 Returns the Y-unit vector.
*/
public final static function getUnitY()
{
return new Zend_Math_Vector_Vector3( 0.0, 1.0, 0.0 );
}

/**
* Gets the Z-unit vector.
*
* @return Zend_Math_Vector_Vector3 Returns the Z-unit vector.
*/
public final static function getUnitZ()
{
return new Zend_Math_Vector_Vector3( 0.0, 0.0, 1.0 );
}

/**
* Calculates the cross product of this vector and the given vector.
*
* @param Zend_Math_Vector_Vector3 $value The vector to calculate with.
* @return Zend_Math_Vector_Vector3 Returns the cross product between the two vectors.
* @throws InvalidArgumentException When the given vector is not of the same dimension as this vector.
*/
public function cross( Zend_Math_Vector_Vector3 $value )
{
if ( $this->getDimension() != $value->getDimension() )
{
throw new InvalidArgumentException( 'We can only calculate the cross product between two vectors with the same dimension.' );
}

$result = clone $value;

$result->set( 0, $this->_components[ 1 ] * $value->get( 2 ) - $this->_components[ 2 ] * $value->get( 1 ) );
$result->set( 1, $this->_components[ 2 ] * $value->get( 0 ) - $this->_components[ 0 ] * $value->get( 2 ) );
$result->set( 2, $this->_components[ 0 ] * $value->get( 1 ) - $this->_components[ 1 ] * $value->get( 0 ) );

return $result;
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Vector_Vector4 extends Zend_Math_Vector
{
/**
* Initializes a new instance of this class.
*
* @param float $X The X-value of this vector.
* @param float $Y The Y-value of this vector.
* @param float $Z The Z-value of this vector.
* @param float $W The W-value of this vector.
*/
public function __construct( $X = 0.0, $Y = 0.0, $Z = 0.0, $W = 0.0 )
{
parent::__construct( 4 );
$this->set( 0, $X );
$this->set( 1, $Y );
$this->set( 2, $Z );
$this->set( 3, $Z );
}

/**
* Gets the X-value of this vector.
*
* @return float Returns the X-value as a float value.
*/
public function getX()
{
return $this->get( 0 );
}

/**
* Sets the X-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setX( $value )
{
$this->set( 0, $value );
return $this;
}

/**
* Gets the Y-value of this vector.
*
* @return float Returns the Y-value as a float value.
*/
public function getY()
{
return $this->get( 1 );
}

/**
* Sets the Y-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setY( $value )
{
$this->set( 1, $value );
return $this;
}

/**
* Gets the Z-value of this vector.
*
* @return float Returns the Z-value as a float value.
*/
public function getZ()
{
return $this->get( 2 );
}

/**
* Sets the Z-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setZ( $value )
{
$this->set( 2, $value );
return $this;
}

/**
* Gets the W-value of this vector.
*
* @return float Returns the W-value as a float value.
*/
public function getW()
{
return $this->get( 3 );
}

/**
* Sets the W-value of this vector.
*
* @param float @value The value to set.
* @return Zend_Math_Vector_Interface Returns the instance of this class.
*/
public function setW( $value )
{
$this->set( 3, $value );
return $this;
}

/**
* Gets the zero vector.
*
* @return Zend_Math_Vector4 Returns the zero vector.
*/
public final static function getZero()
{
return new Zend_Math_Vector4( 0.0, 0.0, 0.0, 0.0 );
}

/**
* Gets the X-unit vector.
*
* @return Zend_Math_Vector4 Returns the X-unit vector.
*/
public final static function getUnitX()
{
return new Zend_Math_Vector4( 1.0, 0.0, 0.0, 0.0 );
}

/**
* Gets the Y-unit vector.
*
* @return Zend_Math_Vector4 Returns the Y-unit vector.
*/
public final static function getUnitY()
{
return new Zend_Math_Vector4( 0.0, 1.0, 0.0, 0.0 );
}

/**
* Gets the Z-unit vector.
*
* @return Zend_Math_Vector4 Returns the Z-unit vector.
*/
public final static function getUnitZ()
{
return new Zend_Math_Vector4( 0.0, 0.0, 1.0, 0.0 );
}

/**
* Gets the W-unit vector.
*
* @return Zend_Math_Vector4 Returns the W-unit vector.
*/
public final static function getUnitW()
{
return new Zend_Math_Vector4( 0.0, 0.0, 0.0, 1.0 );
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math_Vector implements Zend_Math_Interface, Iterator
{
/**
* The position of the iterator.
*
* @var int
*/
private $_position = 0;

/**
* The amount of components that this vector has.
*
* @var array
*/
protected $_components = array();

/**
* Initializes a new instance of this class.
*
* @param int $components The amount of components that this vector has.
*/
public function __construct( $components )
{
$this->_components = array_fill( 0, $components, 0.0 );
}

/**
* Gets the dimension of this vector.
*
* @return int Returns an integer which represents the dimension of this vector.
*/
public function getDimension()
{
return count( $this->_components );
}

/**
* Gets the given component.
*
* @return float
*/
public function get( $component )
{
return $this->_components[ $component ];
}

/**
* Sets the value to the given component.
*
* @param int $component The component to set.
* @param float $value The value to set.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws OutOfBoundsException When the given component is not valid.
*/
public function set( $component, $value )
{
if ( $component < $this->getDimension() )
{
$this->_components[ $component ] = $value;
}
else
{
throw new OutOfBoundsException( 'Trying to set component index ' . $component . ' while this vector only has ' . $this->getDimension() . ' components.' );
}
return $this;
}

/**
* Adds the given value to this value.
*
* @param $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function add( $value )
{
if ( $value instanceof Zend_Math_Vector )
{
foreach ( $value as $component => $componentValue )
{
$this->_components[ $component ] += $componentValue;
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] += $value;
}
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $this;
}

/**
* Subtracts the given value from this value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function sub( $value )
{
if ( $value instanceof Zend_Math_Vector )
{
foreach ( $value as $component => $componentValue )
{
$this->_components[ $component ] -= $componentValue;
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] -= $value;
}
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $this;
}

/**
* Multiplies this value with the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function mul( $value )
{
if ( $value instanceof Zend_Math_Vector )
{
foreach ( $value as $component => $componentValue )
{
$this->_components[ $component ] *= $componentValue;
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] *= $value;
}
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $this;
}

/**
* Divides this value by the given value.
*
* @param mixed $value The value to calculate with.
* @return Zend_Math_Interface Returns the instance of this object.
* @throws InvalidArgumentException When the given argument is not of the valid type.
*/
public function div( $value )
{
if ( $value instanceof Zend_Math_Vector )
{
foreach ( $value as $component => $componentValue )
{
if ( !$componentValue )
{
throw new Zend_Math_Exception_DivideByZero( 'A value cannot be divided by zero.' );
}
$this->_components[ $component ] /= $componentValue;
}
}
else if ( is_int( $value ) || is_float( $value ) )
{
if ( !$value )
{
throw new Zend_Math_Exception_DivideByZero( 'A value cannot be divided by zero.' );
}

foreach ( $this->_components as $component => $componentValue )
{
$this->_components[ $component ] /= $value;
}
}
else
{
throw new InvalidArgumentException( 'No valid argument provided.' );
}
return $this;
}

/**
* Calculates the dot product of this vector and the given vector.
*
* @param Zend_Math_Vector $value The vector to calculate with.
* @return float Returns the dot product between the two vectors.
* @throws InvalidArgumentException When the given argument does not have the correct dimension.
*/
public function dot( Zend_Math_Vector $value )
{
if ( $this->getDimension() != $value->getDimension() )
{
throw new InvalidArgumentException( 'We can only calculate the dot product between two vectors with the same dimension.' );
}

$result = 0.0;
foreach ( $value as $component => $componentValue )
{
$result += ( $this->_components[ $component ] * $componentValue );
}
return $result;
}

/**
* Calculates the length of this vector.
*
* @return float Returns the length of this vector.
*/
public function length()
{
$result = 0.0;
foreach ( $this->_components as $component => $value )
{
$result += ( $value * $value );
}
return sqrt( $result );
}

/**
* Negates this vector.
*
* @return Zend_Math_Vector Returns the instance of this vector.
*/
public function negate()
{
foreach ( $this->_components as $component => $value )
{
$this->_components[ $component ] = -$value;
}

return $this;
}

/**
* Normalizes this vector.
*
* @return Zend_Math_Vector Returns the instance of this vector.
*/
public function normalize()
{
$cloned = clone $this;
$cloned->div( $this->length() );

foreach ( $this->_components as $component => $value )
{
$this->_components[ $component ] = $cloned->get( $component );
}

return $this;
}

/**
* Gets the current value from the iterator.
*
* @return mixed Returns the current value of the iterator.
*/
public function current()
{
return $this->_components[ $this->_position ];
}

/**
* Gets the current key from the iterator.
*
* @return int Returns the current key of the iterator.
*/
public function key()
{
return $this->_position;
}

/**
* Increases the iterator's position.
*
* @return void
*/
public function next()
{
++$this->_position;
}

/**
* Rewinds the iterator's position.
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
}

/**
* Checks if the iterator is still valid.
*
* @return boolean Returns true when the iterator is valid; false otherwise.
*/
public function valid()
{
return $this->_position < $this->getDimension();
}

/**
* Converts this value to a readable string.
*
* @return string
*/
public function __toString()
{
return implode( ',', $this->_components );
}
}{code}

{code}<?php

/**
* @category Zend
* @package Zend_Math
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Math
{
/**
* The value PI.
* @const
*/
const PI = 3.1415926535897932384626433832795028841971693993751;

/**
* Two times the value of PI.
* @const
*/
const PI2 = 6.283185307179586476925286766559;

/**
* The half of PI.
* @const
*/
const HALF_PI = 1.5707963267948966192313216916398;

/**
* The reciprocal value of PI.
* @const
*/
const RECIPROCAL_PI = 0.31830988618379067153776752674503;

/**
* The factor to convert degrees to radians.
* @const
*/
const DEG_TO_RAD = 0.0174532925;

/**
* The factor to convert radians to degrees.
* @const
*/
const RAD_TO_DEG = 57.2957795;

/**
* Converts the given radians to degrees.
* @param float $value The value to convert.
* @return float Returns the converted value.
*/
public static function degToRad( $value )
{
return $value * self::DEG_TO_RAD;
}

/**
* Converts the given degrees to radians.
* @param float $value The value to convert.
* @return float Returns the converted value.
*/
public static function radToDeg( $value )
{
return $value * self::RAD_TO_DEG;
}

/**
* Clamps the given value between the given minimum and maximum.
* @param mixed $value The value that should be clamped.
* @param mixed $min The minimum value.
* @param mixed $max The maximum value.
* @return mixed Returns the clamped value.
*/
public static function clamp( $value, $min, $max )
{
return max( $min, min( $value, $max ) );
}

/**
* Lineair interpolates the two values.
* @param mixed $from The value to start from.
* @param mixed $to The value to interpolate to.
* @param mixed $amount The amount of interpolation to apply.
* @return mixed Returns the interpolated value.
*/
public static function lerp( $from, $to, $amount )
{
$result = null;
if ( $from instanceof Zend_Math_Vector && $to instanceof Zend_Math_Vector )
{
if ( $from->getDimension() != $to->getDimension() )
{
throw new InvalidArgumentException( 'Vectors must be of the same dimension.' );
}

$result = clone $from;

for ( $i = 0; $i < $result->getDimension(); ++$i )
{
$val1 = $from->get( $i );
$val2 = $to->get( $i );
$result->set( $i, $val1 + ( $val2 - $val1 ) * $amount );
}
}
else if ( ( is_float( $from ) || is_int( $from ) ) &&
( ( is_float( $to ) || is_int( $to ) ) ) )
{
$result = $from + ( $to - $from ) * $amount;
}
else
{
throw new InvalidArgumentException( 'Invalid arguments provided for Zend_Math::lerp' );
}
return $result;
}
}{code}


{zone-data}