/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ /**************************************************************************** History $Log: not supported by cvs2svn $ ****************************************************************************/ #ifndef __VCGLIB_MATH_BASE #define __VCGLIB_MATH_BASE #include #include #ifdef __BORLANDC__ float sqrtf (float v) {return sqrt(v);} float fabsf (float v) {return fabs(v);} #endif namespace vcg { template class Math { public: static T inline Sqrt(const T v); static T inline Abs(const T v); static const T MaxVal; static T ToDeg(const T &a); static T ToRad(const T &a); // Unspecialized members T Clamp( const T & val, const T& minval, const T& maxval); class MagnitudoComparer { public: inline bool operator() ( const T a, const T b ) { return fabs(a)>fabs(b); } }; }; float Math::Sqrt(const float v) { return sqrtf(v); } float Math::Abs(const float v) { return fabsf(v); } double Math::Sqrt(const double v) { return sqrt(v); } double Math::Abs(const double v) { return fabs(v); } const unsigned char Math::MaxVal = 255; const char Math::MaxVal = 127; const unsigned short Math::MaxVal = 0xFFFFu; const short Math::MaxVal = 0x7FFF; const float Math::MaxVal = 3.4E38F; const int Math::MaxVal = 2147483647; const long double Math::MaxVal = 1.2E308; const double Math::MaxVal = 1.7E308; const __int64 Math<__int64 >::MaxVal = 9223372036854775807; /* Some files do not define M_PI... */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif template inline SCALAR Math::Clamp( const SCALAR & val, const SCALAR& minval, const SCALAR& maxval) { if(val < minval) return minval; if(val > maxval) return maxval; return val; } inline float Math::ToDeg(const float &a){return a*180.0f/float(M_PI);} inline float Math::ToRad(const float &a){return float(M_PI)*a/180.0f;} inline double Math::ToDeg(const double &a){return a*180.0/M_PI;} inline double Math::ToRad(const double &a){return M_PI*a/180.0;} } // End namespace #endif