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 #define TOOLS_VEC2F_MORE_PREC
0059 #ifdef TOOLS_VEC2F_MORE_PREC
0060 float length() const {
0061 return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]));
0062 }
0063 float normalize() {
0064 float norme = length();
0065 if(!norme) return 0;
0066 divide(norme);
0067 return norme;
0068 }
0069 #else
0070 float length() const {return parent::length(::sqrtf);}
0071 float normalize() {return parent::normalize(::sqrtf);}
0072 #endif
0073 public: //iv2sg
0074 bool equals(const vec2f& a_v,const float a_epsil) const {
0075 //if(a_epsil<0.0f))
0076 float d0 = m_data[0]-a_v.m_data[0];
0077 float d1 = m_data[1]-a_v.m_data[1];
0078 return ((d0*d0+d1*d1)<=a_epsil);
0079 }
0080 void negate() {
0081 m_data[0] = -m_data[0];
0082 m_data[1] = -m_data[1];
0083 }
0084
0085 private:static void check_instantiation() {vec2f v(0,0);v.set_value(1,1);}
0086 };
0087
0088 inline vec2f operator*(float a_f,const vec2f& a_v) {
0089 vec2f res(a_v);
0090 res *= a_f;
0091 return res;
0092 }
0093
0094 }
0095
0096 #include <vector>
0097
0098 namespace tools {
0099
0100 #ifndef SWIG
0101 //for sf, mf :
0102 inline bool set_from_vec(vec2f& a_v,const std::vector<float>& a_sv) {
0103 if(a_sv.size()!=2) return false;
0104 a_v[0] = a_sv[0];
0105 a_v[1] = a_sv[1];
0106 return true;
0107 }
0108 #endif
0109
0110 }
0111
0112 #endif