Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/lina/vec4f is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_vec4f
0005 #define tools_vec4f
0006 
0007 #include "vec4"
0008 #include "../S_STRING"
0009 #include <cmath>
0010 
0011 namespace tools {
0012 
0013 class vec4f : public vec4<float> {
0014   typedef vec4<float> parent;
0015 public:
0016   TOOLS_SCLASS(tools::vec4f) //for stype()
0017 public:
0018   vec4f():parent() {}
0019   vec4f(const float a_vec[4]):parent(a_vec) {}
0020 #ifdef TOOLS_MEM
0021   vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true):parent(a0,a1,a2,a3,a_inc){}
0022 #else
0023   vec4f(const float& a0,const float& a1,const float& a2,const float& a3):parent(a0,a1,a2,a3){}
0024 #endif
0025   virtual ~vec4f() {}
0026 public:
0027   vec4f(const vec4f& a_from):parent(a_from){}
0028   vec4f& operator=(const vec4f& a_from){
0029     parent::operator=(a_from);
0030     return *this;
0031   }
0032 public: //operators
0033   vec4f operator*(float a_v) const {
0034     return vec4f(m_data[0]*a_v,
0035                  m_data[1]*a_v,
0036                  m_data[2]*a_v,
0037                  m_data[3]*a_v);
0038   }
0039   vec4f operator+(const vec4f& a_v) const {
0040     return vec4f(m_data[0]+a_v.m_data[0],
0041                  m_data[1]+a_v.m_data[1],
0042                  m_data[2]+a_v.m_data[2],
0043                  m_data[3]+a_v.m_data[3]);
0044   }
0045   vec4f operator-(const vec4f& a_v) const {
0046     return vec4f(m_data[0]-a_v.m_data[0],
0047                  m_data[1]-a_v.m_data[1],
0048                  m_data[2]-a_v.m_data[2],
0049                  m_data[3]-a_v.m_data[3]);
0050   }
0051   vec4f& operator+=(const vec4f& a_v) {
0052     m_data[0] += a_v.m_data[0];
0053     m_data[1] += a_v.m_data[1];
0054     m_data[2] += a_v.m_data[2];
0055     m_data[3] += a_v.m_data[3];
0056     return *this;
0057   }
0058   vec4f& operator*=(float a_v) {
0059     m_data[0] *= a_v;
0060     m_data[1] *= a_v;
0061     m_data[2] *= a_v;
0062     m_data[3] *= a_v;
0063     return *this;
0064   }
0065   vec4f operator-() const {
0066     return vec4f(-m_data[0],-m_data[1],-m_data[2],-m_data[3]);
0067   }
0068 public:
0069 #define TOOLS_VEC4F_MORE_PREC
0070 #ifdef TOOLS_VEC4F_MORE_PREC
0071   float length() const {
0072     return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]));
0073   }
0074   float normalize() {
0075     float norme = length();
0076     if(!norme) return 0;
0077     divide(norme);
0078     return norme;
0079   }
0080 #else
0081   float length() const {return parent::length(::sqrtf);}
0082   float normalize() {return parent::normalize(::sqrtf);}
0083 #endif
0084 };
0085 
0086 }
0087 
0088 #include <vector>
0089 
0090 namespace tools {
0091 
0092 #ifndef SWIG
0093 //for sf, mf :
0094 inline bool set_from_vec(vec4f& a_v,const std::vector<float>& a_sv) {
0095   if(a_sv.size()!=4) return false;
0096   a_v[0] = a_sv[0];
0097   a_v[1] = a_sv[1];
0098   a_v[2] = a_sv[2];
0099   a_v[3] = a_sv[3];
0100   return true;
0101 }
0102 #endif
0103 
0104 }
0105 
0106 #endif