Optimize VECTOR2::Rotation for 0, 90, 180 and -90 degrees by avoiding time consumming calculations.

This commit is contained in:
jean-pierre charras 2016-04-26 14:14:26 +02:00
parent c1f0ab91a2
commit 5da341d1fc
1 changed files with 13 additions and 0 deletions

View File

@ -358,6 +358,19 @@ VECTOR2<T>& VECTOR2<T>::operator-=( const T& aScalar )
template <class T>
VECTOR2<T> VECTOR2<T>::Rotate( double aAngle ) const
{
// fast calculation of some rotations, very frequently found
if( aAngle == 0.0 )
return VECTOR2<T> ( T( x ), T( y ) );
if( aAngle == 90.0 )
return VECTOR2<T> ( T( -y ), T( x ) );
if( aAngle == -90.0 )
return VECTOR2<T> ( T( y ), T( -x ) );
if( aAngle == 180.0 || aAngle == -180.0 )
return VECTOR2<T> ( T( -x ), T( -y ) );
double sa = sin( aAngle );
double ca = cos( aAngle );