39 |
|
|
40 |
|
namespace oopse { |
41 |
|
|
42 |
+ |
const double epsilon = 0.000001; |
43 |
+ |
|
44 |
+ |
template<typename T> |
45 |
+ |
inline bool equal(T e1, T e2) { |
46 |
+ |
return e1 == e2; |
47 |
+ |
} |
48 |
+ |
|
49 |
+ |
template<> |
50 |
+ |
inline bool equal(float e1, float e2) { |
51 |
+ |
return fabs(e1 - e2) < epsilon; |
52 |
+ |
} |
53 |
+ |
|
54 |
+ |
template<> |
55 |
+ |
inline bool equal(double e1, double e2) { |
56 |
+ |
return fabs(e1 - e2) < epsilon; |
57 |
+ |
} |
58 |
+ |
|
59 |
|
/** |
60 |
|
* @class Vector Vector.hpp "math/Vector.hpp" |
61 |
|
* @brief Fix length vector class |
130 |
|
inline const double& operator()(unsigned int i) const { |
131 |
|
assert( i < Dim); |
132 |
|
return data_[i]; |
133 |
+ |
} |
134 |
+ |
|
135 |
+ |
/** |
136 |
+ |
* Tests if this vetor is equal to other vector |
137 |
+ |
* @return true if equal, otherwise return false |
138 |
+ |
* @param v vector to be compared |
139 |
+ |
*/ |
140 |
+ |
inline bool operator ==(const Vector<Real, Dim>& v) { |
141 |
+ |
|
142 |
+ |
for (unsigned int i = 0; i < Dim; i ++) { |
143 |
+ |
if (!equal(data_[i], v[i])) { |
144 |
+ |
return false; |
145 |
+ |
} |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
return true; |
149 |
|
} |
150 |
|
|
151 |
+ |
/** |
152 |
+ |
* Tests if this vetor is not equal to other vector |
153 |
+ |
* @return true if equal, otherwise return false |
154 |
+ |
* @param v vector to be compared |
155 |
+ |
*/ |
156 |
+ |
inline bool operator !=(const Vector<Real, Dim>& v) { |
157 |
+ |
return !(*this == v); |
158 |
+ |
} |
159 |
+ |
|
160 |
|
/** Negates the value of this vector in place. */ |
161 |
|
inline void negate() { |
162 |
|
data_[0] = -data_[0]; |