/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/sgx/core/math/trigonometry.inl

*/

#ifndef SGX_CORE_MATH_TRIGONOMETRY_INLINE
#define SGX_CORE_MATH_TRIGONOMETRY_INLINE	1

/**
This is an INLINE module. So every method must use the SGX_INLINE
designation.
*/

/**
Returns the sine of @theta.

This result is intended to be good, but not exact, since it is
not required to use floating point operations to calculate the sine.
For floating-point accuracy, use @sgxSinf.
*/
SGX_INLINE tREAL32 sgxSin(tREAL32 theta)
{
	extern tREAL32			sgxSineTable[];
    const tREAL32 mul = 162.9746617261f;
    return sgxSineTable[((tUINT32)(theta * mul)) & 1023];
}

/**
Returns the cosine of @theta.

This result is intended to be good, but not exact, since it is
not required to use floating point operations to calculate the sine.
For floating-point accuracy, use @sgxCosf.
*/
SGX_INLINE tREAL32 sgxCos(tREAL32 theta)
{
	extern tREAL32			sgxSineTable[];
    const tREAL32 mul = 162.9746617261f;
    return sgxSineTable[(((tUINT32)(theta * mul))+256) & 1023];
}

/**
Returns both the sine and cosine of @theta..

This function exists so that platforms with more optimal
handling of sin/cos can save CPU cycles, without affecting the others.
*/
SGX_INLINE void sgxSinCos(tREAL32 &sine, tREAL32 &cosine, const tREAL32 theta)
{
	sine = sgxSin(theta);
	cosine = sgxCos(theta);
}

/**
Returns the arcsine of @theta.

The results when @theta is outside the [-1,1] range are undefined.
*/
SGX_INLINE tREAL32 sgxASin(tREAL32 theta)
{
	return asinf(theta);
}

/**
Returns the arccosine of @theta.

The results when @theta is outside the [-1,1] range are undefined.
*/
SGX_INLINE tREAL32 sgxACos(tREAL32 theta)
{
	return acosf(theta);
}

/**
Returns the arctangent of @theta.

This is intended to return the angle from the horizontal to
the point dx,dy in a safe manner.
*/
SGX_INLINE tREAL32 sgxAtan2(tREAL32 dx, tREAL32 dy)
{
	return std::atan2f(dx, dy);
}

/**
Return an exact, floating-point calculated, cosine.
*/
SGX_INLINE tREAL32 sgxCosf(tREAL32 theta)
{
	return cosf(theta);
}

/**
Return an exact, floating-point calculated, sine.
*/
SGX_INLINE tREAL32 sgxSinf(tREAL32 theta)
{
	return sinf(theta);
}

/**
Convert a number of @radians into degrees.
*/
SGX_INLINE tREAL32 sgxToDegrees(tREAL32 radians)
{
	return radians * 57.295779513082320876798154817014f;
}

/**
Convert a number of @degrees into radians.
*/
SGX_INLINE tREAL32 sgxToRadians(tREAL32 degrees)
{
	return degrees * 0.017453292519943295769236907684886f;
}


#endif /* SGX_CORE_MATH_TRIGONOMETRY_INLINE */
