OpenPolygon  1.0.0
OpenPolygon is a Rendering Engine
vector.h
1 /*
2  Copyright (C) 2014 - 2016 Mutzii
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 #ifndef VECTOR_H
19 #define VECTOR_H
20 
21 template< typename A>
22 class Vector2
23 {
24  public:
25  Vector2(void);
26  Vector2(A x , A y);
27  ~Vector2(void)=default;
28 
29  Vector2 & operator=( const Vector2 & );
30 
31  Vector2 & operator-( const Vector2 &l);
32 
33  Vector2 & operator+(const Vector2& );
34 
35  Vector2 & operator*(const Vector2& );
36  Vector2 & operator*(const A );
37 
38  bool operator ==( const Vector2 &);
39 
40  bool operator !=( const Vector2 &);
41 
42  void normalize(void);
43 
44  void setX(A x );
45  void setY(A y);
46 
47  A getX(void) const;
48  A getY(void) const;
49 
50  private:
51  A mX, mY;
52 };
53 
54 template < typename A>
55 class Vector3
56 {
57  public:
58  Vector3(void);
59  Vector3( A x , A y , A z);
60  ~Vector3(void) =default;
61 
62  Vector3 & operator=( const Vector3& );
63 
64  Vector3 & operator+=(const Vector3& );
65 
66  Vector3 & operator+(const Vector3& );
67 
68  Vector3 & operator-(const Vector3& );
69 
70  Vector3 & operator*(const Vector3& );
71 
72  bool operator<(const Vector3 & ) const;
73 
74  Vector3 & operator*(const A );
75 
76  bool operator ==( const Vector3 &) const;
77  bool operator !=( const Vector3 &) const;
78 
79  void normalize(void);
80  void inverse(void);
81 
82  void setX(A x);
83  void setY(A y);
84  void setZ(A z);
85 
86  A getX(void) const;
87  A getY(void) const;
88  A getZ(void) const;
89 
90  private:
91  A mX , mY , mZ;
92  };
93 
94  template < typename A>
95  class Vector4
96  {
97  public:
98  Vector4(void);
99  Vector4( A x , A y , A z , A a);
100  ~Vector4(void) = default;
101 
102  Vector4 & operator=( const Vector4& );
103 
104  Vector4 & operator+=(const Vector4& );
105 
106  Vector4 & operator+(const Vector4& );
107  Vector4 & operator+(const Vector3<A>& );
108  Vector4 & operator+(const Vector2<A>& );
109 
110  Vector4 & operator-(const Vector4& );
111  Vector4 & operator-(const Vector3<A>& );
112  Vector4 & operator-(const Vector2<A>& );
113 
114  Vector4 & operator*(const Vector4& );
115  Vector4 & operator*(const A );
116 
117  bool operator ==( const Vector4 &);
118  bool operator !=( const Vector4 &);
119 
120  void setX(A x);
121  void setY(A y);
122  void setZ(A z);
123  void setA(A a);
124 
125  A getX(void) const;
126  A getY(void) const;
127  A getZ(void) const;
128  A getA(void) const;
129 
130  private:
131  A mX , mY , mZ , mA;
132  };
133 
134  using Vector2f = Vector2<float>;
135  using Vector2d = Vector2<double>;
136  using Vector2i = Vector2<int>;
137 
138  using Vector3f = Vector3<float>;
139  using Vector3d = Vector3<double>;
140  using Vector3i = Vector3<int>;
141 
142  using Vector4f = Vector4<float>;
143  using Vector4d = Vector4<double>;
144  using Vector4i = Vector4<int>;
145 
146  /* ------------ no templates --------------*/
147 
148  /* vector source code / template */
149  #include "vector.template"
150 
151 #endif // VECTOR2_H
Definition: vector.h:22
Definition: vector.h:95
Definition: vector.h:55