• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/core/math/math_constants.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_CORE_MATH_MATH_CONSTANTS_H
00002 #define OPENTISSUE_CORE_MATH_MATH_CONSTANTS_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 #include <boost/numeric/conversion/bounds.hpp>
00013 #include <boost/cast.hpp>
00014 #include <cmath>
00015 
00016 
00017 namespace OpenTissue
00018 {
00019     
00020   namespace math
00021   {
00022 
00023     // constant: 0 (zero)
00024     namespace detail
00025     {
00026 
00027       template <typename T>
00028       inline T zero();
00029 
00030       template <>
00031       inline float zero<float>() { return 0.0f; }
00032 
00033       template <>
00034       inline double zero<double>() { return 0.0; }
00035 
00036       template <>
00037       inline int zero<int>() { return 0; }
00038 
00039       template <>
00040       inline long unsigned int zero<long unsigned int>() { return 0; }
00041 
00042       template <>
00043       inline unsigned int zero<unsigned int>() { return 0u; }
00044 
00045     }  // namespace detail
00046 
00047 
00048     // constant: 1 (one)
00049     namespace detail
00050     {
00051 
00052       template <typename T>
00053       inline T one();
00054 
00055       template <>
00056       inline float one<float>() { return 1.0f; }
00057 
00058       template <>
00059       inline double one<double>() { return 1.0; }
00060 
00061       template <>
00062       inline int one<int>() { return 1; }
00063 
00064       template <>
00065       inline unsigned int one<unsigned int>() { return 1u; }
00066 
00067     }  // namespace detail
00068 
00069 
00070     // constant: 2 (two)
00071     namespace detail
00072     {
00073 
00074       template <typename T>
00075       inline T two();
00076 
00077       template <>
00078       inline float two<float>() { return 2.0f; }
00079 
00080       template <>
00081       inline double two<double>() { return 2.0; }
00082 
00083       template <>
00084       inline int two<int>() { return 2; }
00085 
00086       template <>
00087       inline unsigned int two<unsigned int>() { return 2u; }
00088 
00089     }  // namespace detail
00090 
00091 
00092     // constant: 3 (three)
00093     namespace detail
00094     {
00095 
00096       template <typename T>
00097       inline T three();
00098 
00099       template <>
00100       inline float three<float>() { return 3.0f; }
00101 
00102       template <>
00103       inline double three<double>() { return 3.0; }
00104 
00105       template <>
00106       inline int three<int>() { return 3; }
00107 
00108       template <>
00109       inline unsigned int three<unsigned int>() { return 3u; }
00110 
00111     }  // namespace detail
00112 
00113 
00114     // constant: 4 (four)
00115     namespace detail
00116     {
00117 
00118       template <typename T>
00119       inline T four();
00120 
00121       template <>
00122       inline float four<float>() { return 4.0f; }
00123 
00124       template <>
00125       inline double four<double>() { return 4.0; }
00126 
00127       template <>
00128       inline int four<int>() { return 4; }
00129 
00130       template <>
00131       inline unsigned int four<unsigned int>() { return 4u; }
00132 
00133     }  // namespace detail
00134 
00135 
00136     // constant: 8 (eight)
00137     namespace detail
00138     {
00139 
00140       template <typename T>
00141       inline T eight();
00142 
00143       template <>
00144       inline float eight<float>() { return 8.0f; }
00145 
00146       template <>
00147       inline double eight<double>() { return 8.0; }
00148 
00149       template <>
00150       inline int eight<int>() { return 8; }
00151 
00152       template <>
00153       inline unsigned int eight<unsigned int>() { return 8u; }
00154 
00155     }  // namespace detail
00156 
00157 
00158     // constant: ½ (half)
00159     namespace detail
00160     {
00161 
00162       template <typename T>
00163       inline T half();
00164 
00165       template <>
00166       inline float half<float>() { return 0.5f; }
00167 
00168       template <>
00169       inline double half<double>() { return 0.5; }
00170 
00171     }  // namespace detail
00172 
00173 
00174     // constant: pi and fractions of pi
00175     namespace detail
00176     {
00177 
00178       template<typename T>
00179       inline T pi() { return boost::numeric_cast<T>(M_PI); }
00180 
00181       template<typename T>
00182       inline T pi_half() {  return boost::numeric_cast<T>(M_PI_2); }
00183 
00184       template<typename T>
00185       inline T pi_quarter() {  return boost::numeric_cast<T>(M_PI_4); }
00186 
00187     }  // namespace detail
00188 
00189 
00190     // constant: specials
00191     namespace detail
00192     {
00193 
00194       template <typename T>
00195       inline T highest() { return boost::numeric::bounds<T>::highest(); }
00196 
00197       template <typename T>
00198       inline T lowest() { return boost::numeric::bounds<T>::lowest(); }
00199 
00200       template <typename T>
00201       inline T infinity(){ return highest<T>(); }
00202 
00203       // one degree in radians
00204       template<typename T>
00205       inline T degree() {  return boost::numeric_cast<T>(0.017453292519943295769236907684886); }
00206 
00207       // one radian in degrees
00208       template<typename T>
00209       inline T radian() {  return boost::numeric_cast<T>(57.295779513082320876798154814105); }
00210 
00211     }
00212 
00213   }  // namespace math
00214   
00215 }  // namespace OpenTissue
00216 
00217 // #define OPENTISSUE_CORE_MATH_MATH_CONSTANTS_H
00218 #endif

Generated on Thu Dec 1 2011 12:52:05 for HUMIM Tracker by  doxygen 1.7.1