#include "munga.h" #pragma hdrstop #include "angle.h" #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile Radian *) { return false; } #endif Scalar Radian::Normalize(Scalar Value) { Scalar temp; temp = fmod(Value,TWO_PI); if (temp > PI) { temp -= TWO_PI; } else if (temp < -PI) { temp += TWO_PI; } return temp; } // //############################################################################# //############################################################################# // Radian& Radian::Normalize() { Check(this); angle = fmod(angle,TWO_PI); if (angle > PI) { angle -= TWO_PI; } else if (angle < -PI) { angle += TWO_PI; } return *this; } // //############################################################################# //############################################################################# // Radian& Radian::Lerp(const Radian &a,const Radian &b,Scalar t) { Scalar a1,a2; Check_Pointer(this); Check(&a); Check(&b); a1 = Radian::Normalize(a.angle); a2 = Radian::Normalize(b.angle); if (a2-a1 > PI) { a2 -= TWO_PI; } else if (a2-a1 < -PI) { a2 += TWO_PI; } angle = ::Lerp(a1, a2, t); return *this; } // //############################################################################# //############################################################################# // std::ostream& operator<<(std::ostream& stream, const Radian& radian) { return stream << radian.angle << " rad"; } // //############################################################################# //############################################################################# // Logical Radian::TestInstance() const { return angle >= -100.0f && angle <= 100.0f; } #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile Degree *) { return false; } #endif // //############################################################################# //############################################################################# // std::ostream& operator<<(std::ostream& stream, const Degree& degree) { return stream << degree.angle << " deg"; } // //############################################################################# //############################################################################# // Logical Degree::TestInstance() const { return True; } #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile SinCosPair *) { return False; } #endif // //############################################################################# //############################################################################# // SinCosPair& SinCosPair::operator=(const Radian &radian) { Check_Pointer(this); Check(&radian); cosine = cos(radian); sine = sin(radian); #if defined(__BCPLUSPLUS__) cosine = cos(radian); // STUPID FUCKING BORLAND LIBRARY HACK!!!!! #endif Check(this); return *this; } // //############################################################################# //############################################################################# // std::ostream& operator<<(std::ostream& stream, const SinCosPair& pair) { return stream << '{' << pair.cosine << ',' << pair.sine << '}'; } // //############################################################################# //############################################################################# // Logical SinCosPair::TestInstance() const { Scalar t = sine*sine + cosine*cosine; if (!Close_Enough(t,1.0f,0.001f)) { Dump(*this); Dump(t); return False; } return True; } #if defined(TEST_CLASS) # include "angle.tcp" #endif