utility.h
1/*
2 * Player - One Hell of a Robot Server
3 * Copyright (C) 2000-2003
4 * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22/********************************************************************
23 *
24 * This library is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU Lesser General Public
26 * License as published by the Free Software Foundation; either
27 * version 2.1 of the License, or (at your option) any later version.
28 *
29 * This library is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public
35 * License along with this library; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 *
38 ********************************************************************/
39
40/***************************************************************************
41 * Desc: Player v2.0 C++ client
42 * Authors: Brad Kratochvil, Toby Collett
43 *
44 * Date: 23 Sep 2005
45 # CVS: $Id$
46 **************************************************************************/
47
48
49#ifndef PLAYERCC_UTILITY_H
50#define PLAYERCC_UTILITY_H
51namespace PlayerCc
52{
61const int PLAYER_PORTNUM = 6665;
63const std::string PLAYER_HOSTNAME = "localhost";
64
65// Since they are inline, these functions are as efficient as DEFINES,
66// but now they have the benefit of type checking!
67
69inline double rtod(double r)
70{
71 return r * 180.0 / M_PI;
72}
73
75inline double dtor(double r)
76{
77 return r * M_PI / 180.0;
78}
79
81inline double normalize(double z)
82{
83 return atan2(sin(z), cos(z));
84}
85
87#if defined (min)
88 #undef min
89#endif
90template<typename T>
91inline T min(T a, T b)
92{
93 if (a < b)
94 return a;
95 else
96 return b;
97}
98
100#if defined (max)
101 #undef max
102#endif
103template<typename T>
104inline T max(T a, T b)
105{
106 if (a > b)
107 return a;
108 else
109 return b;
110}
111
113template<typename T>
114inline T limit(T a, T min, T max)
115{
116 if (a < min)
117 return min;
118 else if (a > max)
119 return max;
120 else
121 return a;
122}
123
126} // namespace
127
128#endif
129
T limit(T a, T min, T max)
Limit a value to the range of min, max.
Definition utility.h:114
T max(T a, T b)
Return the maximum of a, b.
Definition utility.h:104
const int PLAYER_PORTNUM
The default port number for PlayerClient.
Definition utility.h:61
double dtor(double r)
Convert degrees to radians.
Definition utility.h:75
const std::string PLAYER_HOSTNAME
The default hostname for PlayerClient.
Definition utility.h:63
double normalize(double z)
Normalize angle to domain -pi, pi.
Definition utility.h:81
double rtod(double r)
Convert radians to degrees.
Definition utility.h:69