7 #ifndef __math_Vector_h__ 8 #define __math_Vector_h__ 18 template<
int N,
class T>
37 Vector(T x,T y,T z,T w,T v,T u);
38 Vector(T x,T y,T z,T w,T v);
46 const T& operator[](
unsigned int index)
const;
47 T& operator[](
unsigned int index);
50 const T *raw(
void)
const;
53 const T *temp(
void)
const;
95 return !FE_INVALID_SCALAR(a_value);
103 feX(e_corrupt,
"confirmValid(F32)",
"scalar invalid");
110 return !FE_INVALID_SCALAR(a_value);
118 feX(e_corrupt,
"confirmValid(F64)",
"scalar invalid");
122 template<
int N,
typename T>
130 template<
int N,
typename T>
141 const F32*
data=a_vector.raw();
142 if(N>0 && FE_INVALID_SCALAR(data[0]))
144 if(N>1 && FE_INVALID_SCALAR(data[1]))
146 if(N>2 && FE_INVALID_SCALAR(data[2]))
148 if(N>3 && FE_INVALID_SCALAR(data[3]))
150 if(N>4 && FE_INVALID_SCALAR(data[4]))
152 if(N>5 && FE_INVALID_SCALAR(data[5]))
162 const F32*
data=a_vector.raw();
163 if(N>0 && FE_INVALID_SCALAR(data[0]))
164 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 0 invalid");
165 if(N>1 && FE_INVALID_SCALAR(data[1]))
166 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 1 invalid");
167 if(N>2 && FE_INVALID_SCALAR(data[2]))
168 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 2 invalid");
169 if(N>3 && FE_INVALID_SCALAR(data[3]))
170 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 3 invalid");
171 if(N>4 && FE_INVALID_SCALAR(data[4]))
172 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 4 invalid");
173 if(N>5 && FE_INVALID_SCALAR(data[5]))
174 feX(e_corrupt,
"confirmValid(Vector<N,F32>)",
"vector element 5 invalid");
182 const F64*
data=a_vector.raw();
183 if(N>0 && FE_INVALID_SCALAR(data[0]))
185 if(N>1 && FE_INVALID_SCALAR(data[1]))
187 if(N>2 && FE_INVALID_SCALAR(data[2]))
189 if(N>3 && FE_INVALID_SCALAR(data[3]))
191 if(N>4 && FE_INVALID_SCALAR(data[4]))
193 if(N>5 && FE_INVALID_SCALAR(data[5]))
203 const F64*
data=a_vector.raw();
204 if(N>0 && FE_INVALID_SCALAR(data[0]))
205 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 0 invalid");
206 if(N>1 && FE_INVALID_SCALAR(data[1]))
207 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 1 invalid");
208 if(N>2 && FE_INVALID_SCALAR(data[2]))
209 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 2 invalid");
210 if(N>3 && FE_INVALID_SCALAR(data[3]))
211 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 3 invalid");
212 if(N>4 && FE_INVALID_SCALAR(data[4]))
213 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 4 invalid");
214 if(N>5 && FE_INVALID_SCALAR(data[5]))
215 feX(e_corrupt,
"confirmValid(Vector<N,F64>)",
"vector element 5 invalid");
223 #if FE_VEC_CHECK_VALID 228 template<
int N,
class T>
231 for(
unsigned int i = 0; i < N; i++)
238 template<
int N,
class T>
241 for(
unsigned int i = 0; i < N; i++)
243 m_data[i] = other[i];
248 template<
int N,
class T>
252 for(
unsigned int i = 0; i < N; i++)
254 m_data[i] = (T)other[i];
259 template<
int N,
class T>
263 for(
unsigned int i = 0; i < N; i++)
265 m_data[i] = other[i];
270 template<
int N,
class T>
274 for(
unsigned int i = 0; i < N; i++)
276 m_data[i] = other[i];
281 template<
int N,
class T>
285 for(
unsigned int i = 0; i < N-1; i++)
287 m_data[i] = other[i];
296 template<
int N,
class T>
300 for(
unsigned int i = 0; i < N-2; i++)
302 m_data[i] = other[i];
315 template<
int N,
class T>
322 template<
int N,
class T>
326 if(N >=2) m_data[1] = y;
327 if(N >=3) m_data[2] = z;
328 if(N >=4) m_data[3] = w;
329 if(N >=5) m_data[4] = v;
330 if(N >=6) m_data[5] = u;
335 template<
int N,
class T>
344 for(I32 n=6;n<N;n++) m_data[n]=T(0);
348 template<
int N,
class T>
356 for(I32 n=5;n<N;n++) m_data[n]=T(0);
360 template<
int N,
class T>
367 for(I32 n=4;n<N;n++) m_data[n]=T(0);
371 template<
int N,
class T>
377 for(I32 n=3;n<N;n++) m_data[n]=T(0);
381 template<
int N,
class T>
386 for(I32 n=2;n<N;n++) m_data[n]=T(0);
390 template<
int N,
class T>
394 for(I32 n=1;n<N;n++) m_data[n]=T(0);
401 template<
int N,
class T>
404 for(
unsigned int i = 0; i < N; i++)
411 template<
int N,
class T>
415 if(index >= N) { feX(e_invalidRange); }
417 return m_data[index];
420 template<
int N,
class T>
424 if(index >= N) { feX(e_invalidRange); }
426 return m_data[index];
429 template<
int N,
class T>
435 template<
int N,
class T>
441 template<
int N,
class T>
448 template<
int N,
class T>
453 if((
void*)
this != (
void*)&other)
455 for(
unsigned int i = 0; i < N; i++)
457 if(m_data[i] != other[i]) {
return false; }
463 template<
int N,
class T>
466 return !operator==(other);
469 template<
int N,
class T>
473 if((
void*)
this != (
void*)&other)
475 for(
unsigned int i = 0; i < N; i++)
477 m_data[i] = other[i];
484 template<
int N,
class T>
489 if((
void*)
this != (
void*)&other)
491 for(
unsigned int i = 0; i < N; i++)
493 m_data[i] = (T)other[i];
500 template<
int N,
class T>
504 for(
unsigned int i = 0; i < N; i++)
506 m_data[i] = other[i];
512 template<
int N,
class T>
517 for(
unsigned int i = 0; i < N; i++)
519 m_data[i] = (T)other[i];
525 template<
int N,
class T>
530 for(
unsigned int i = 0; i < N; i++)
532 m_data[i] = (T)other[i];
538 template<
int N,
class T>
543 for(
unsigned int i = 0; i < N-1; i++)
545 m_data[i] = (T)other[i];
555 template<
int N,
class T>
560 for(
unsigned int i = 0; i < N-2; i++)
562 m_data[i] = (T)other[i];
576 template<
int N,
class T>
579 for(
unsigned int i = 0; i < N; i++)
582 m_data[i] = array[i];
593 template<
int N,
class T>
596 for(
unsigned int i = 0; i < N; i++)
607 template<
int N,
class T,
class U>
611 for(
unsigned int i = 0; i < N; i++)
622 template<
int N,
class T,
class U>
634 template<
int N,
class T>
644 template<
int N,
class T>
648 for(
unsigned int i = 0; i < N; i++)
659 template<
int M,
int N,
class T>
663 const unsigned int limit=(M<N)? M: N;
664 for(
unsigned int i = 0; i < limit; i++)
675 template<
int N,
class T>
679 for(
unsigned int i = 0; i < N; i++)
690 template<
int M,
int N,
class T>
694 const int limit=(M<N)? M: N;
695 for(
unsigned int i = 0; i < limit; i++)
706 template<
int N,
class T>
711 for(
unsigned int i = 0; i < N; i++)
721 template<
int N,
class T>
725 for(
unsigned int i = 0; i < N; i++)
727 lhs[i] = lhs[i] * rhs[i];
736 template<
int M,
int N,
class T>
740 const int limit=(M<N)? M: N;
741 for(
unsigned int i = 0; i < limit; i++)
752 template<
int N,
class T,
class U>
756 for(
unsigned int i = 0; i < N; i++)
767 template<
int N,
class T>
773 for(
unsigned int i = 0; i < N; i++)
775 t += lhs[i] * rhs[i];
784 template<
int N,
class T>
793 template<
int N,
class T>
798 for(
unsigned int i = 0; i < N; i++)
800 mag += (T)rhs[i] * (T)rhs[i];
809 template<
int N,
class T>
816 feX(
"unit(Vector<N,T>)",
"attempt to normalize zero magnitude vector");
831 template<
int N,
class T>
853 template<
int N,
class T>
860 feX(
"Vector<N,T>::normal",
861 "attempt to normalize zero magnitude vector");
875 template<
int N,
class T>
895 template<
int N,
class T>
900 for(
unsigned int i = 0; i < N; i++)
914 template<
int N,
class T>
920 for(
unsigned int i = 0; i < N; i++)
922 v[i] = lhs[i] + rhs[i];
931 template<
int N,
int M,
class T>
937 for(
unsigned int i = 0; i < N; i++)
945 v[i] = lhs[i] + rhs[i];
956 template<
int N,
class T>
962 for(
unsigned int i = 0; i < N; i++)
964 v[i] = lhs[i] - rhs[i];
973 template<
int N,
int M,
class T>
979 for(
unsigned int i = 0; i < N; i++)
987 v[i] = lhs[i] - rhs[i];
997 template<
int N,
class T>
1002 for(
unsigned int i = 0; i < N; i++)
1004 if(rhs[i] != lhs[i])
1015 template<
int N,
class T,
class U>
1021 for(
unsigned int i = 0; i < N; i++)
1023 if(FE_INVALID_SCALAR(lhs[i]) ||
1024 FE_INVALID_SCALAR(rhs[i]) ||
1025 fabs(rhs[i] - lhs[i]) > margin)
1036 template<
int N,
class T>
1042 for(
unsigned int i = 0; i < N; i++)
1044 v[i] = lhs[i] * rhs[i];
1053 template<
int N,
class T,
class U>
1059 for(
unsigned int i = 0; i < N; i++)
1061 v[i] = rhs[i] * lhs;
1071 template<
int N,
class T,
class U>
1077 for(
unsigned int i = 0; i < N; i++)
1079 v[i] = lhs[i] * rhs;
1089 template<
int N,
class T,
class U>
1095 feX(e_unsolvable,
"operator/(Vector<N,T>,T)",
"divide by zero");
1096 return lhs*(1.0f/rhs);
1105 template<
int N,
class T,
class U>
1111 for(
unsigned int i = 0; i < N; i++)
1113 lhs[i]+=scalar*rhs[i];
1125 template<
int N,
class T,
class U>
1131 for(
unsigned int i = 0; i < N; i++)
1133 lhs[i]=lhs[i]*scalar+rhs[i];
Vector< N, T > operator+(const Vector< N, T > &lhs, const Vector< N, T > &rhs)
add operation
Definition: Vector.h:915
Vector< N, T > & normalize(Vector< N, T > &vec)
In place normalize operator.
Definition: Vector.h:854
bool equivalent(const Vector< N, T > &lhs, const Vector< N, T > &rhs, U margin)
Equivalence test within the given tolerance margin.
Definition: Vector.h:1016
bool operator==(const Vector< N, T > &lhs, const Vector< N, T > &rhs)
equality test
Definition: Vector.h:998
Vector< N, T > operator-(const Vector< N, T > &lhs, const Vector< M, T > &rhs)
subtract operation
Definition: Vector.h:974
Vector< N, T > unitSafe(const Vector< N, T > &vec)
Return vector scaled to unit length with zero check.
Definition: Vector.h:832
Vector< N, T > & operator-=(Vector< N, T > &lhs, const Vector< M, T > &rhs)
In place subtract operator.
Definition: Vector.h:691
Vector< N, T > & operator*=(Vector< N, T > &lhs, const Vector< M, T > &rhs)
In place piecewise multiply operator.
Definition: Vector.h:737
Vector< N, T > & scaleAndAdd(Vector< N, T > &lhs, U scalar, const Vector< N, T > &rhs)
Scale then add.
Definition: Vector.h:1126
Vector< N, T > & operator+=(Vector< N, T > &lhs, const Vector< M, T > &rhs)
In place add operator.
Definition: Vector.h:660
Vector< N, T > & operator+=(Vector< N, T > &lhs, const Vector< N, T > &rhs)
In place add operator.
Definition: Vector.h:645
void confirmValid(const T &a_value)
Definition: Vector.h:87
Vector< N, T > operator*(const Vector< N, T > &lhs, const U &rhs)
Scale operation.
Definition: Vector.h:1072
kernel
Definition: namespace.dox:3
String print(const Vector< N, T > &vec)
Print to a string.
Definition: Vector.h:896
BWORD checkValid(const T &a_value)
Definition: Vector.h:79
Vector< N, T > operator/(const Vector< N, T > &lhs, const U &rhs)
Inverse Scale operation.
Definition: Vector.h:1090
void maybeConfirmValid(const T &a_value)
Definition: Vector.h:221
Vector< N, T > & operator*=(Vector< N, T > &lhs, U scale)
In place piecewise scale operator.
Definition: Vector.h:753
Vector< N, T > operator*(const Vector< N, T > &lhs, const Vector< N, T > &rhs)
Piecewise multiply operation.
Definition: Vector.h:1037
Vector< N, T > operator-(const Vector< N, T > &rhs)
Negate operation.
Definition: Vector.h:707
Vector< N, T > & operator*=(Vector< N, T > &lhs, const Vector< N, T > &rhs)
In place piecewise multiply operator.
Definition: Vector.h:722
Dense vector - size fixed by template.
Definition: Vector.h:19
Vector< N, T > operator*(const U lhs, const Vector< N, T > &rhs)
Scale operation.
Definition: Vector.h:1054
T dot(const Vector< N, T > &lhs, const Vector< N, T > &rhs)
Dot (inner) product.
Definition: Vector.h:768
Vector< N, T > unit(const Vector< N, T > &vec)
Return vector scaled to unit length.
Definition: Vector.h:810
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
Vector< N, T > & addScaled(Vector< N, T > &lhs, U scalar, const Vector< N, T > &rhs)
Add with scaling.
Definition: Vector.h:1106
Automatically reference-counted string container.
Definition: String.h:128
Vector< N, T > operator+(const Vector< N, T > &lhs, const Vector< M, T > &rhs)
add operation
Definition: Vector.h:932
Vector< N, T > & setAll(Vector< N, T > &lhs, const U value)
Set all the elements to the given value.
Definition: Vector.h:608
Vector< N, T > & setAt(Vector< N, T > &lhs, U32 index, const U value)
Set the value at the index.
Definition: Vector.h:623
T magnitude(const Vector< N, T > &rhs)
Frobenius norm operation.
Definition: Vector.h:785
U32 size(const Vector< N, T > &lhs)
Return the number of elements.
Definition: Vector.h:635
T magnitudeSquared(const Vector< N, T > &rhs)
Square of the length.
Definition: Vector.h:794
Vector< N, T > & normalizeSafe(Vector< N, T > &vec)
In place normalize operator with zero length check.
Definition: Vector.h:876
Vector< N, T > & operator-=(Vector< N, T > &lhs, const Vector< N, T > &rhs)
In place subtract operator.
Definition: Vector.h:676
Vector< N, T > operator-(const Vector< N, T > &lhs, const Vector< N, T > &rhs)
subtract operation
Definition: Vector.h:957