utility.h
00001 /* 00002 * Player - One Hell of a Robot Server 00003 * Copyright (C) 2000-2003 00004 * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 /*************************************************************************** 00024 * Desc: Player v2.0 C++ client 00025 * Authors: Brad Kratochvil, Toby Collett 00026 * 00027 * Date: 23 Sep 2005 00028 # CVS: $Id: utility.h,v 1.1.2.2 2006/06/09 18:13:50 gerkey Exp $ 00029 **************************************************************************/ 00030 00031 00032 #ifndef PLAYERCC_UTILITY_H 00033 #define PLAYERCC_UTILITY_H 00034 namespace PlayerCc 00035 { 00043 00044 const int PLAYER_PORTNUM = 6665; 00046 const std::string PLAYER_HOSTNAME = "localhost"; 00047 00048 // Since they are inline, these functions are as efficient as DEFINES, 00049 // but now they have the benefit of type checking! 00050 00052 inline double rtod(double r) 00053 { 00054 return r * 180.0 / M_PI; 00055 } 00056 00058 inline double dtor(double r) 00059 { 00060 return r * M_PI / 180.0; 00061 } 00062 00064 inline double normalize(double z) 00065 { 00066 return atan2(sin(z), cos(z)); 00067 } 00068 00070 template<typename T> 00071 inline T min(T a, T b) 00072 { 00073 if (a < b) 00074 return a; 00075 else 00076 return b; 00077 } 00078 00080 template<typename T> 00081 inline T max(T a, T b) 00082 { 00083 if (a > b) 00084 return a; 00085 else 00086 return b; 00087 } 00088 00090 template<typename T> 00091 inline T limit(T a, T min, T max) 00092 { 00093 if (a < min) 00094 return min; 00095 else if (a > max) 00096 return max; 00097 else 00098 return a; 00099 } 00100 00103 } // namespace 00104 00105 #endif 00106