common_functions.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; indent-tabs-mode: nil; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2006, Tim Robertson <kid50@users.sourceforge.net>
00006 //
00007 //This program is free software; you can redistribute it and/or modify
00008 //it under the terms of the GNU Lesser General Public License as published
00009 //by the Free Software Foundation; either version 2.1 of the License, or (at
00010 //your option) any later version.
00011 //
00012 //This program is distributed in the hope that it will be useful,  but
00013 //WITHOUT ANY WARRANTY; without even the implied warranty of'
00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //Lesser General Public License for more details.
00016 //
00017 //You should have received a copy of the GNU Lesser General Public License
00018 //along with this program; if not, write to the Free Software Foundation,
00019 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00023 
00024 #ifndef BTK_MATH_COMMON_FUNCTIONS_HPP
00025 #define BTK_MATH_COMMON_FUNCTIONS_HPP
00026 
00027 #include <cmath>
00028 
00029 #include <btk/core/math/constants.hpp>
00030 
00031 namespace BTK {
00032 namespace MATH {
00033 
00035 template <typename T>
00036 inline T square(T val) { return val * val; }
00037 
00039 template <typename T>
00040 inline T cube(T val) { return val * val * val; }
00041 
00042 template <typename T>
00043 inline bool equivalent(T x, T y, T precision)
00044 {
00045   return std::fabs(x - y) <= precision * std::fabs(x);  
00046 }
00047 
00048 template <typename T>
00049 bool equivalent(T x, T y);
00050 
00051 template <>
00052 inline bool equivalent(float x, float y)
00053 {
00054   return equivalent(x,y,FLOAT_EPSILON);
00055 }
00056 
00057 template <>
00058 inline bool equivalent(double x, double y)
00059 {
00060   return equivalent(x,y,DOUBLE_EPSILON);
00061 }
00062 
00063 inline double deg2rad(double angle_in_degrees) 
00064 {
00065   return RADIANS_PER_DEGREE*angle_in_degrees;
00066 }
00067 
00068 inline double rad2deg(double angle_in_radians)
00069 {
00070   return DEGREES_PER_RADIAN*angle_in_radians;
00071 }
00072 
00073 } // MATH
00074 } // BTK
00075 
00076 #endif // BTK_MATH_COMMON_FUNCTIONS_HPP

Generated on Sun Jul 15 20:46:25 2007 for BTK Core by  doxygen 1.5.1