GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
Vectors.h
1 #ifndef GEAR_Vectors_H
2 #define GEAR_Vectors_H 1
3 
4 #include <stdexcept>
5 #include "Vector3D.h"
6 
7 namespace gear {
8 
9 
19  template <int N, typename Float_T=double>
20  class VectorND_T {
21 
22  public:
23 
24  VectorND_T() { for(int i = 0; i < N; ++i) _c[i] = 0.; } ;
25 
27  inline Float_T& operator[](unsigned i) {
28 
29  if( i > N-1 ) throw std::out_of_range( "VectorND_T::operator[]" ) ;
30 
31  return _c[i] ;
32  }
33  inline Float_T operator[](unsigned i) const {
34 
35  if( i > N-1 ) throw std::out_of_range( "VectorND_T::operator[]" ) ;
36 
37  return _c[i] ;
38  }
39 
40  protected:
41 
42  Float_T _c[N] ;
43 
44  }; // class
45 
46 
48  template <typename Float_T=double>
49  struct Vector2D_T : public VectorND_T<2,Float_T> {
50  typedef VectorND_T<2,Float_T> Base ;
51  Vector2D_T() {
52  Base::_c[0] = 0. ;
53  Base::_c[1] = 0. ;
54  }
55  Vector2D_T( Float_T c0, Float_T c1 ) {
56  Base::_c[0] = c0 ;
57  Base::_c[1] = c1 ;
58  }
59  } ;
60 
62  template <typename Float_T=double>
63  struct Vector3D_T : public VectorND_T<3,Float_T> {
64  typedef VectorND_T<3,Float_T> Base ;
65  Vector3D_T() {
66  Base::_c[0] = 0. ;
67  Base::_c[1] = 0. ;
68  Base::_c[2] = 0. ;
69  }
70  Vector3D_T( Float_T c0, Float_T c1, Float_T c2 ) {
71  Base::_c[0] = c0 ;
72  Base::_c[1] = c1 ;
73  Base::_c[2] = c2 ;
74  }
75  } ;
76 
77 
78 
80 
81 // typedef Vector3D_T<double> Vector3D ;
82 
83 
84 
85 // /** Defined for backward compatibility */
86 // struct Point2D : public Vector2D{
87 
88 // Point2D() : Vector2D( 0., 0. ) {}
89 // Point2D(double d0, double d1 ) : Vector2D( d0, d1 ) {}
90 
91 // } ;
92 
93 // /** Defined for backward compatibility */
94 // struct Point3D : public Vector3D{
95 
96 // Point3D() : Vector3D( 0., 0., 0.) {}
97 // Point3D(double d0, double d1, double d2 ) : Vector3D( d0, d1,d2 ) {}
98 
99 // } ;
100 
101 
102 } // namespace gear
103 
104 #endif /* ifndef GEAR_Vectors_H */
105 
Specialization for 2D.
Definition: Vectors.h:49
Float_T & operator[](unsigned i)
The i-th coordinate.
Definition: Vectors.h:27
Specialization for 3D.
Definition: Vectors.h:63
Trivial N-dimensional vector.
Definition: Vectors.h:20