#include "box2d/math_functions.h"
#include "core.h"
#include <float.h>
bool b2IsValid( float a )
{
if ( isnan( a ) )
{
return false;
}
if ( isinf( a ) )
{
return false;
}
return true;
}
bool b2Vec2_IsValid( b2Vec2 v )
{
if ( isnan( v.x ) || isnan( v.y ) )
{
return false;
}
if ( isinf( v.x ) || isinf( v.y ) )
{
return false;
}
return true;
}
bool b2Rot_IsValid( b2Rot q )
{
if ( isnan( q.s ) || isnan( q.c ) )
{
return false;
}
if ( isinf( q.s ) || isinf( q.c ) )
{
return false;
}
return b2IsNormalized( q );
}
static inline float b2Atan( float x )
{
float a1 = 0.99997726f;
float a3 = -0.33262347f;
float a5 = 0.19354346f;
float a7 = -0.11643287f;
float a9 = 0.05265332f;
float a11 = -0.01172120f;
float x2 = x * x;
return x * ( a1 + x2 * ( a3 + x2 * ( a5 + x2 * ( a7 + x2 * ( a9 + x2 * a11 ) ) ) ) );
}
float b2Atan2( float y, float x )
{
float pi = b2_pi;
float halfPi = 0.5f * b2_pi;
bool swap = b2AbsFloat( x ) < b2AbsFloat( y );
float atanInput = ( swap ? x : y ) / ( swap ? y : x );
float res = b2Atan( atanInput );
res = swap ? ( atanInput >= 0.0f ? halfPi : -halfPi ) - res : res;
if ( x >= 0.0f && y >= 0.0f )
{
} else if ( x < 0.0f && y >= 0.0f )
{
res = pi + res;
} else if ( x < 0.0f && y < 0.0f )
{
res = -pi + res;
} else if ( x >= 0.0f && y < 0.0f )
{
}
return res;
}
b2CosSin b2ComputeCosSin( float angle )
{
float x = b2UnwindLargeAngle( angle );
float pi2 = b2_pi * b2_pi;
b2Rot q;
if (x < -0.5f * b2_pi)
{
float y = x + b2_pi;
float y2 = y * y;
q.c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 );
}
else if (x > 0.5f * b2_pi)
{
float y = x - b2_pi;
float y2 = y * y;
q.c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 );
}
else
{
float y2 = x * x;
q.c = ( pi2 - 4.0f * y2 ) / ( pi2 + y2 );
}
if (x < 0.0f)
{
float y = x + b2_pi;
q.s = -16.0f * y * ( b2_pi - y ) / ( 5.0f * pi2 - 4.0f * y * ( b2_pi - y ) );
}
else
{
q.s = 16.0f * x * ( b2_pi - x ) / ( 5.0f * pi2 - 4.0f * x * ( b2_pi - x ) );
}
q = b2NormalizeRot( q );
return ( b2CosSin ){ q.c, q.s };
}