Vector3D.h 5.34 KB
Newer Older
1
// -*- C++ -*-
Lynn Garren's avatar
Lynn Garren committed
2
// $Id: Vector3D.h,v 1.3 2003/10/23 21:29:50 garren Exp $
3
4
5
6
7
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
8
// 09.09.96 E.Chernyaev - initial version
9
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
10
11
//                        the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
12
//
13

14
15
16
#ifndef HEP_VECTOR3D_H
#define HEP_VECTOR3D_H

17
#include <iosfwd>
Lynn Garren's avatar
Lynn Garren committed
18
#include "CLHEP/Geometry/defs.h"
19
#include "CLHEP/Vector/ThreeVector.h"
20
21
#include "CLHEP/Geometry/BasicVector3D.h"

22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace HepGeom {

  class Transform3D;

  /**
   * Geometrical 3D Vector.
   * This is just a declaration of the class needed to define
   * specializations Vector3D<float> and Vector3D<double>.
   *
   * @ingroup geometry
   * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
   */
  template<class T>
  class Vector3D : public BasicVector3D<T> {};
36
37

  /**
38
39
40
41
   * Geometrical 3D Vector with components of float type.
   *
   * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
   * @ingroup geometry
42
   */
43
44
45
46
47
  template<>
  class Vector3D<float> : public BasicVector3D<float> {
  public:
    /**
     * Default constructor. */
48
    Vector3D() = default;
49
50
51

    /**
     * Constructor from three numbers. */
52
    Vector3D(float x1, float y1, float z1) : BasicVector3D<float>(x1,y1,z1) {}
53
54
55
56
57
58
59
60

    /**
     * Constructor from array of floats. */
    explicit Vector3D(const float * a)
      : BasicVector3D<float>(a[0],a[1],a[2]) {}

    /**
     * Copy constructor. */
61
62
63
64
65
    Vector3D(const Vector3D<float> &) = default;

    /**
     * Move constructor. */
    Vector3D(Vector3D<float> &&) = default;
66

67
68
69
    /**
     * Constructor from BasicVector3D<float>. */
    Vector3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
70

71
72
    /**
     * Destructor. */
73
    ~Vector3D() = default;
74

75
76
    /**
     * Assignment. */
77
    Vector3D<float> & operator=(const Vector3D<float> &) = default;
78
79
80
81

    /**
     * Assignment from BasicVector3D<float>. */
    Vector3D<float> & operator=(const BasicVector3D<float> & v) {
82
83
      this->BasicVector3D<float>::operator=(v);
      return *this;
84
85
    }

86
87
88
89
    /**
     * Move assignment. */
    Vector3D<float> & operator=(Vector3D<float> &&) = default;

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    /**
     * Transformation by Transform3D. */
    Vector3D<float> & transform(const Transform3D & m);
  };

  /**
   * Transformation of Vector<float> by Transform3D.
   * @relates Vector3D
   */
  Vector3D<float>
  operator*(const Transform3D & m, const Vector3D<float> & v);

  /**
   * Geometrical 3D Vector with components of double type.
   *
   * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
   * @ingroup geometry
   */
  template<>
  class Vector3D<double> : public BasicVector3D<double> {
  public:
    /**
     * Default constructor. */
113
    Vector3D() = default;
114

115
116
    /**
     * Constructor from three numbers. */
117
    Vector3D(double x1, double y1, double z1) : BasicVector3D<double>(x1,y1,z1) {}
118
119
120
121
122
123
124
125
126
127
128
129
130

    /**
     * Constructor from array of floats. */
    explicit Vector3D(const float * a)
      : BasicVector3D<double>(a[0],a[1],a[2]) {}

    /**
     * Constructor from array of doubles. */
    explicit Vector3D(const double * a)
      : BasicVector3D<double>(a[0],a[1],a[2]) {}

    /**
     * Copy constructor. */
131
132
133
134
135
    Vector3D(const Vector3D<double> &) = default;

    /**
     * Move constructor. */
    Vector3D(Vector3D<double> &&) = default;
136
137
138
139
140
141
142
143
144
145
146

    /**
     * Constructor from BasicVector3D<float>. */
    Vector3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}

    /**
     * Constructor from BasicVector3D<double>. */
    Vector3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}

    /**
     * Destructor. */
147
    ~Vector3D() = default;
148
149
150
151
152
153
154
155
156
157
158
159
160

    /**
     * Constructor from CLHEP::Hep3Vector.
     * This constructor is needed only for backward compatibility and
     * in principle should be absent.
     */
    Vector3D(const CLHEP::Hep3Vector & v)
      : BasicVector3D<double>(v.x(),v.y(),v.z()) {}

    /**
     * Conversion (cast) to CLHEP::Hep3Vector.
     * This operator is needed only for backward compatibility and
     * in principle should not exit.
161
     */
162
163
164
165
    operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }

    /**
     * Assignment. */
166
    Vector3D<double> & operator=(const Vector3D<double> &) = default;
167
168
169
170

    /**
     * Assignment from BasicVector3D<float>. */
    Vector3D<double> & operator=(const BasicVector3D<float> & v) {
171
172
      this->BasicVector3D<double>::operator=(v);
      return *this;
173
174
175
176
177
    }

    /**
     * Assignment from BasicVector3D<double>. */
    Vector3D<double> & operator=(const BasicVector3D<double> & v) {
178
179
      this->BasicVector3D<double>::operator=(v);
      return *this;
180
181
    }

182
183
184
185
    /**
     * Move assignment. */
    Vector3D<double> & operator=(Vector3D<double> &&) = default;

186
187
188
189
190
191
192
193
194
195
196
    /**
     * Transformation by Transform3D. */
    Vector3D<double> & transform(const Transform3D & m);
  };

  /**
   * Transformation of Vector<double> by Transform3D.
   * @relates Vector3D
   */
  Vector3D<double>
  operator*(const Transform3D & m, const Vector3D<double> & v);
197

198
} /* namespace HepGeom */
199

Lynn Garren's avatar
Lynn Garren committed
200
201
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
//  backwards compatibility will be enabled ONLY in CLHEP 1.9
202
typedef HepGeom::Vector3D<double> HepVector3D;
Lynn Garren's avatar
Lynn Garren committed
203
#endif
204
205

#endif /* HEP_VECTOR3D_H */