include/vamos/geometry/Conversions.h

Go to the documentation of this file.
00001 //      Vamos - a driving simulator
00002 //  Copyright (C) 2001 Sam Varner
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 #ifndef _CONVERSIONS_H_
00019 #define _CONVERSIONS_H_
00020 
00021 #include <vamos/geometry/Constants.h>
00022 
00023 #include <algorithm>
00024 
00025 // Windows' normal build config defines these as macros.
00026 // Undefine these to get real std::min() and std::max() usuable.
00027 #ifdef WIN32
00028 # undef min
00029 # undef max
00030 #endif
00031 
00032 namespace Vamos_Geometry
00033 {
00034   inline double rad_to_deg (double rad) { return rad * 180.0 / pi; }
00035   inline double deg_to_rad (double deg) { return deg * pi / 180.0; }
00036 
00037   inline double rad_s_to_rpm (double rad_s) { return rad_s * 30.0 / pi; }
00038   inline double rpm_to_rad_s (double rpm) { return rpm * pi / 30.0; }
00039 
00040   inline double m_s_to_km_h (double m_s) { return m_s * 3.6; } 
00041   inline double km_h_to_m_s (double km_h) { return km_h / 3.6; } 
00042 
00043   template <typename T> T clip (T value, T low, T high)
00044   { return std::max (std::min (value, high), low); }
00045   
00046   template <typename T> T  sign (T value)
00047   { return value == 0 ? 0 : (value > 0 ? 1 : -1); }
00048 }
00049 
00050 #endif

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6