src/tool/math_tools.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Outils mathématiques.
00020  *****************************************************************************/
00021 
00022 #include "../tool/math_tools.h"
00023 #include <math.h>
00024 
00025 // Limit under which, real numbers are considered as NULL
00026 const double EPS_ZERO = 0.05;
00027 
00028 // Conversion degré en radian
00029 double Deg2Rad (int degre){
00030   return ((double)degre)*M_PI/180;
00031 }
00032 
00033 int Rad2Deg(double rad) {
00034   return int(rad*180/M_PI);
00035 }
00036 
00037 // Modèle pour borner une valeur entre min et max
00038 template <class T>
00039 T BorneTpl (const T &valeur, const T &min, const T &max){
00040   if (valeur < min)
00041     return min;
00042   else if (max < valeur)
00043     return max;
00044   else
00045     return valeur;
00046 }
00047 
00048 long BorneLong (const long &valeur, const long &min, const long &max){
00049         return BorneTpl (valeur, min, max);
00050 }
00051 
00052 double BorneDouble (const double &valeur, const double &min, const double &max){
00053         return BorneTpl (valeur, min, max);
00054 }
00055 
00056 // Inverse un angle par rapport à l'axe vertical
00057 double InverseAngle (const double &angle){
00058   if (angle < 0)
00059     return -M_PI - angle;
00060   else
00061     return M_PI - angle;
00062 }
00063 
00064 // Inverse un angle par rapport à l'axe vertical
00065 double InverseAngleRad (const double &angle){
00066   if (angle < 0)
00067     return -M_PI - angle;
00068   else
00069     return M_PI - angle;
00070 }
00071 
00072 // Inverse un angle par rapport à l'axe vertical
00073 double InverseAngleDeg (const double &angle){
00074   if (angle < 0)
00075     return -180 - angle;
00076   else
00077     return 180 - angle;
00078 }
00079 
00080 double AbsReel (const double x){
00081         return fabs(x);
00082 }
00083 
00084 bool EgalZero (const double x){
00085         return AbsReel(x) <= EPS_ZERO;
00086 }
00087 

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7