1 | // %flair:license{ |
---|
2 | // This file is part of the Flair framework distributed under the |
---|
3 | // CECILL-C License, Version 1.0. |
---|
4 | // %flair:license} |
---|
5 | /*! |
---|
6 | * \file Vector2D.h |
---|
7 | * \brief Class defining a 2D vector |
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253 |
---|
9 | * \date 2013/05/02 |
---|
10 | * \version 4.0 |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef VECTOR2D_H |
---|
14 | #define VECTOR2D_H |
---|
15 | |
---|
16 | namespace flair { |
---|
17 | namespace core { |
---|
18 | |
---|
19 | /*! \class Vector2D |
---|
20 | * |
---|
21 | * \brief Class defining a 2D vector |
---|
22 | */ |
---|
23 | class Vector2D { |
---|
24 | public: |
---|
25 | /*! |
---|
26 | * \brief Constructor |
---|
27 | * |
---|
28 | * Construct a Vector2D using specified values. |
---|
29 | * |
---|
30 | * \param x |
---|
31 | * \param y |
---|
32 | */ |
---|
33 | Vector2D(float x = 0, float y = 0); |
---|
34 | |
---|
35 | /*! |
---|
36 | * \brief Destructor |
---|
37 | * |
---|
38 | */ |
---|
39 | ~Vector2D(); |
---|
40 | |
---|
41 | /*! |
---|
42 | * \brief Rotation |
---|
43 | * |
---|
44 | * \param value rotation value in radians |
---|
45 | */ |
---|
46 | void Rotate(float value); |
---|
47 | |
---|
48 | /*! |
---|
49 | * \brief Rotation |
---|
50 | * |
---|
51 | * \param value rotation value in degrees |
---|
52 | */ |
---|
53 | void RotateDeg(float value); |
---|
54 | |
---|
55 | /*! |
---|
56 | * \brief Norm |
---|
57 | * |
---|
58 | * \return value |
---|
59 | */ |
---|
60 | float GetNorm(void) const; |
---|
61 | |
---|
62 | /*! |
---|
63 | * \brief Normalize |
---|
64 | */ |
---|
65 | void Normalize(void); |
---|
66 | |
---|
67 | /*! |
---|
68 | * \brief Saturate |
---|
69 | * |
---|
70 | * Saturate between min and max |
---|
71 | * |
---|
72 | * \param min minimum Vector2D value |
---|
73 | * \param max maximum Vector2D value |
---|
74 | */ |
---|
75 | void Saturate(Vector2D min, Vector2D max); |
---|
76 | |
---|
77 | /*! |
---|
78 | * \brief Saturate |
---|
79 | * |
---|
80 | * Saturate between min and max |
---|
81 | * |
---|
82 | * \param min minimum Vector2D(min,min) value |
---|
83 | * \param max maximum Vector2D(max,max) value |
---|
84 | */ |
---|
85 | void Saturate(float min, float max); |
---|
86 | |
---|
87 | /*! |
---|
88 | * \brief Saturate |
---|
89 | * |
---|
90 | * Saturate between -abs(value) and abs(value) |
---|
91 | * |
---|
92 | * \param value saturation Vector2D value |
---|
93 | */ |
---|
94 | void Saturate(const Vector2D &value); |
---|
95 | |
---|
96 | /*! |
---|
97 | * \brief Saturate |
---|
98 | * |
---|
99 | * Saturate between -abs(Vector2D(value,value)) and abs(Vector2D(value,value)) |
---|
100 | * |
---|
101 | * \param value saturation Vector2D(value,value) |
---|
102 | */ |
---|
103 | void Saturate(float value); |
---|
104 | |
---|
105 | /*! |
---|
106 | * \brief x |
---|
107 | */ |
---|
108 | float x; |
---|
109 | |
---|
110 | /*! |
---|
111 | * \brief y |
---|
112 | */ |
---|
113 | float y; |
---|
114 | |
---|
115 | Vector2D &operator=(const Vector2D &vector); |
---|
116 | Vector2D &operator+=(const Vector2D &vector); |
---|
117 | Vector2D &operator-=(const Vector2D &vector); |
---|
118 | }; |
---|
119 | |
---|
120 | /*! Add |
---|
121 | * |
---|
122 | * \brief Add |
---|
123 | * |
---|
124 | * \param vectorA vector |
---|
125 | * \param vectorB vector |
---|
126 | */ |
---|
127 | Vector2D operator+(const Vector2D &vectorA, const Vector2D &vectorB); |
---|
128 | |
---|
129 | /*! Substract |
---|
130 | * |
---|
131 | * \brief Substract |
---|
132 | * |
---|
133 | * \param vectorA vector |
---|
134 | * \param vectorB vector |
---|
135 | */ |
---|
136 | Vector2D operator-(const Vector2D &vectorA, const Vector2D &vectorB); |
---|
137 | |
---|
138 | /*! Opposite |
---|
139 | * |
---|
140 | * \brief Opposite |
---|
141 | * |
---|
142 | * \param vectorA vector |
---|
143 | * |
---|
144 | * \return -vectorA |
---|
145 | */ |
---|
146 | Vector2D operator-(const Vector2D &vectorA); |
---|
147 | |
---|
148 | /*! Divid |
---|
149 | * |
---|
150 | * \brief Divid |
---|
151 | * |
---|
152 | * \param vector vector |
---|
153 | * \param coeff coefficent |
---|
154 | * \return vector/coefficient |
---|
155 | */ |
---|
156 | Vector2D operator/(const Vector2D &vector, float coeff); |
---|
157 | |
---|
158 | /*! Multiply |
---|
159 | * |
---|
160 | * \brief Multiplyf |
---|
161 | * |
---|
162 | * \param vector vector |
---|
163 | * \param coeff coefficent |
---|
164 | * \return coefficient*vector |
---|
165 | */ |
---|
166 | Vector2D operator*(const Vector2D &vector, float coeff); |
---|
167 | |
---|
168 | /*! Multiply |
---|
169 | * |
---|
170 | * \brief Multiply |
---|
171 | * |
---|
172 | * \param coeff coefficent |
---|
173 | * \param vector vector |
---|
174 | * \return coefficient*vector |
---|
175 | */ |
---|
176 | Vector2D operator*(float coeff, const Vector2D &vector); |
---|
177 | |
---|
178 | } // end namespace core |
---|
179 | } // end namespace flair |
---|
180 | |
---|
181 | #endif // VECTOR2D_H |
---|