Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/lina/vec2f 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_vec2f
0005 #define tools_vec2f
0006 
0007 #include "vec2"
0008 #include "../S_STRING"
0009 #include <cmath>
0010 
0011 namespace tools {
0012 
0013 class vec2f : public vec2<float> {
0014   typedef vec2<float> parent;
0015 public:
0016   TOOLS_SCLASS(tools::vec2f) //for stype()
0017 public:
0018   vec2f():parent(){}
0019   vec2f(const float a_vec[2]):parent(a_vec){}
0020   vec2f(float a0,float a1):parent(a0,a1){}
0021   virtual ~vec2f() {}
0022 public:
0023   vec2f(const vec2f& a_from): parent(a_from){}
0024   vec2f& operator=(const vec2f& a_from){
0025     parent::operator=(a_from);
0026     return *this;
0027   }
0028 
0029   vec2f(const parent& a_from):parent(a_from){}
0030 
0031 public: //operators
0032   vec2f operator*(float a_v) const {
0033     return vec2f(m_data[0]*a_v,
0034                  m_data[1]*a_v);
0035   }
0036   vec2f operator+(const vec2f& a_v) const {
0037     return vec2f(m_data[0]+a_v.m_data[0],
0038                  m_data[1]+a_v.m_data[1]);
0039   }
0040   vec2f operator-(const vec2f& a_v) const {
0041     return vec2f(m_data[0]-a_v.m_data[0],
0042                  m_data[1]-a_v.m_data[1]);
0043   }
0044   vec2f& operator+=(const vec2f& a_v) {
0045     m_data[0] += a_v.m_data[0];
0046     m_data[1] += a_v.m_data[1];
0047     return *this;
0048   }
0049   vec2f& operator*=(float a_v) {
0050     m_data[0] *= a_v;
0051     m_data[1] *= a_v;
0052     return *this;
0053   }
0054   vec2f operator-() const {
0055     return vec2f(-m_data[0],-m_data[1]);
0056   }
0057 public:
0058   float length() const {
0059     return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]));
0060   }
0061   float normalize() {
0062     float norme = length();
0063     if(!norme) return 0;
0064     divide(norme);
0065     return norme;
0066   }
0067 public: //iv2sg
0068   bool equals(const vec2f& a_v,const float a_epsil) const {
0069     //if(a_epsil<0.0f))
0070     float d0 = m_data[0]-a_v.m_data[0];
0071     float d1 = m_data[1]-a_v.m_data[1];
0072     return ((d0*d0+d1*d1)<=a_epsil);
0073   }
0074   void negate() {
0075     m_data[0] = -m_data[0];
0076     m_data[1] = -m_data[1];
0077   }
0078 
0079 private:static void check_instantiation() {vec2f v(0,0);v.set_value(1,1);}
0080 };
0081 
0082 inline vec2f operator*(float a_f,const vec2f& a_v) {
0083   vec2f res(a_v);
0084   res *= a_f;
0085   return res;
0086 }
0087 
0088 }
0089 
0090 #include <vector>
0091 
0092 namespace tools {
0093 
0094 #ifndef SWIG
0095 //for sf, mf :
0096 inline bool set_from_vec(vec2f& a_v,const std::vector<float>& a_sv) {
0097   if(a_sv.size()!=2) return false;
0098   a_v[0] = a_sv[0];
0099   a_v[1] = a_sv[1];
0100   return true;
0101 }
0102 #endif
0103 
0104 }
0105 
0106 #endif