Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __VECTORUTILS_HXX__
00021 #define __VECTORUTILS_HXX__
00022
00023 #include <sstream>
00024 #include <numeric>
00025 #include <string>
00026 #include <cmath>
00027 #include <map>
00028
00029 namespace INTERP_KERNEL
00030 {
00032 const double VOL_PREC = 1.0e-6;
00033
00035 const double DEFAULT_REL_TOL = 1.0e-6;
00036
00038 const double DEFAULT_ABS_TOL = 5.0e-12;
00039
00044 template<int SPACEDIM>
00045 inline double getDistanceBtw2Pts(const double *a, const double *b)
00046 {
00047 double ret2=0.;
00048 for(int i=0;i<SPACEDIM;i++)
00049 ret2+=(a[i]-b[i])*(a[i]-b[i]);
00050 return sqrt(ret2);
00051 }
00052
00053
00054
00055
00056
00064 inline void copyVector3(const double* src, double* dest)
00065 {
00066 for(int i = 0 ; i < 3 ; ++i)
00067 dest[i] = src[i];
00068 }
00069
00076 inline const std::string vToStr(const double* pt)
00077 {
00078 std::stringstream ss(std::ios::out);
00079 ss << "[" << pt[0] << ", " << pt[1] << ", " << pt[2] << "]";
00080 return ss.str();
00081 }
00082
00090 inline void cross(const double* v1, const double* v2,double* res)
00091 {
00092 res[0] = v1[1]*v2[2] - v1[2]*v2[1];
00093 res[1] = v1[2]*v2[0] - v1[0]*v2[2];
00094 res[2] = v1[0]*v2[1] - v1[1]*v2[0];
00095 }
00096
00104 inline double dot(const double* v1, const double* v2)
00105 {
00106 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
00107 }
00108
00115 inline double norm(const double* v)
00116 {
00117 return sqrt(dot(v,v));
00118 }
00119
00129 inline bool epsilonEqual(const double x, const double y, const double errTol = DEFAULT_ABS_TOL)
00130 {
00131 return y < x ? x - y < errTol : y - x < errTol;
00132
00133 }
00134
00146 inline bool epsilonEqualRelative(const double x, const double y, const double relTol = DEFAULT_REL_TOL, const double absTol = DEFAULT_ABS_TOL)
00147 {
00148
00149
00150 if(std::fabs(x - y) < absTol)
00151 {
00152 return true;
00153 }
00154
00155 const double relError = std::fabs((x - y) / std::max(std::fabs(x), std::fabs(y)));
00156
00157 return relError < relTol;
00158 }
00159
00160 }
00161
00162 #endif