g4tools  5.4.0
vec4f
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_vec4f
5 #define tools_vec4f
6 
7 #include "vec4"
8 #include "../S_STRING"
9 #include <cmath>
10 
11 namespace tools {
12 
13 class vec4f : public vec4<float> {
14  typedef vec4<float> parent;
15 public:
16  TOOLS_SCLASS(tools::vec4f) //for stype()
17 public:
18  vec4f():parent() {}
19  vec4f(const float a_vec[4]):parent(a_vec) {}
20 #ifdef TOOLS_MEM
21  vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true):parent(a0,a1,a2,a3,a_inc){}
22 #else
23  vec4f(const float& a0,const float& a1,const float& a2,const float& a3):parent(a0,a1,a2,a3){}
24 #endif
25  virtual ~vec4f() {}
26 public:
27  vec4f(const vec4f& a_from):parent(a_from){}
28  vec4f& operator=(const vec4f& a_from){
29  parent::operator=(a_from);
30  return *this;
31  }
32 public: //operators
33  vec4f operator*(float a_v) const {
34  return vec4f(m_data[0]*a_v,
35  m_data[1]*a_v,
36  m_data[2]*a_v,
37  m_data[3]*a_v);
38  }
39  vec4f operator+(const vec4f& a_v) const {
40  return vec4f(m_data[0]+a_v.m_data[0],
41  m_data[1]+a_v.m_data[1],
42  m_data[2]+a_v.m_data[2],
43  m_data[3]+a_v.m_data[3]);
44  }
45  vec4f operator-(const vec4f& a_v) const {
46  return vec4f(m_data[0]-a_v.m_data[0],
47  m_data[1]-a_v.m_data[1],
48  m_data[2]-a_v.m_data[2],
49  m_data[3]-a_v.m_data[3]);
50  }
51  vec4f& operator+=(const vec4f& a_v) {
52  m_data[0] += a_v.m_data[0];
53  m_data[1] += a_v.m_data[1];
54  m_data[2] += a_v.m_data[2];
55  m_data[3] += a_v.m_data[3];
56  return *this;
57  }
58  vec4f& operator*=(float a_v) {
59  m_data[0] *= a_v;
60  m_data[1] *= a_v;
61  m_data[2] *= a_v;
62  m_data[3] *= a_v;
63  return *this;
64  }
65  vec4f operator-() const {
66  return vec4f(-m_data[0],-m_data[1],-m_data[2],-m_data[3]);
67  }
68 public:
69 #define TOOLS_VEC4F_MORE_PREC
70 #ifdef TOOLS_VEC4F_MORE_PREC
71  float length() const {
72  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]));
73  }
74  float normalize() {
75  float norme = length();
76  if(!norme) return 0;
77  divide(norme);
78  return norme;
79  }
80 #else
81  float length() const {return parent::length(::sqrtf);}
82  float normalize() {return parent::normalize(::sqrtf);}
83 #endif
84 };
85 
86 }
87 
88 #include <vector>
89 
90 namespace tools {
91 
92 #ifndef SWIG
93 //for sf, mf :
94 inline bool set_from_vec(vec4f& a_v,const std::vector<float>& a_sv) {
95  if(a_sv.size()!=4) return false;
96  a_v[0] = a_sv[0];
97  a_v[1] = a_sv[1];
98  a_v[2] = a_sv[2];
99  a_v[3] = a_sv[3];
100  return true;
101 }
102 #endif
103 
104 }
105 
106 #endif
tools::vec4< float >::divide
bool divide(const float &a_T)
Definition: vec4:186
tools::vec4f::operator-
vec4f operator-() const
Definition: vec4f:65
tools::vec4f::operator+
vec4f operator+(const vec4f &a_v) const
Definition: vec4f:39
tools::vec4< float >::m_data
float m_data[4]
Definition: vec4:262
tools::vec4f::vec4f
vec4f(const vec4f &a_from)
Definition: vec4f:27
tools::vec4< float >::operator=
vec4 & operator=(const vec4 &a_from)
Definition: vec4:77
tools::vec4f::normalize
float normalize()
Definition: vec4f:74
tools::vec4f::length
float length() const
Definition: vec4f:71
tools::vec4f::operator-
vec4f operator-(const vec4f &a_v) const
Definition: vec4f:45
tools::vec4f::operator*=
vec4f & operator*=(float a_v)
Definition: vec4f:58
tools::vec4< float >::length
float length(float(*a_sqrt)(float)) const
Definition: vec4:125
tools::vec4f::TOOLS_SCLASS
TOOLS_SCLASS(tools::vec4f) public
Definition: vec4f:16
tools::vec4f::~vec4f
virtual ~vec4f()
Definition: vec4f:25
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::vec4f::vec4f
vec4f(const float a_vec[4])
Definition: vec4f:19
tools::vec4f::operator*
vec4f operator*(float a_v) const
Definition: vec4f:33
tools::vec4< float >::normalize
float normalize(float(*a_sqrt)(float))
Definition: vec4:129
tools::vec4f::operator=
vec4f & operator=(const vec4f &a_from)
Definition: vec4f:28
tools::vec4f::operator+=
vec4f & operator+=(const vec4f &a_v)
Definition: vec4f:51
tools::vec4f::vec4f
vec4f(const float &a0, const float &a1, const float &a2, const float &a3)
Definition: vec4f:23
vec4
tools::set_from_vec
bool set_from_vec(vec2f &a_v, const std::vector< float > &a_sv)
Definition: vec2f:102
tools::vec4
Definition: vec4:16
tools::vec4f
Definition: vec4f:13