documentation correction and tests in PIMathVector.h

This commit is contained in:
2020-10-01 17:07:01 +03:00
parent e16243d64b
commit 49905a3de0
4 changed files with 202 additions and 199 deletions

View File

@@ -132,39 +132,39 @@ public:
* @param v vector of type PIMathVectorT
* @return cos value of the angle between two vectors
*/
Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);}
Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);}
/**
* @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements
* @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements
*
* @param v vector of type PIMathVectorT
* @return sin value of the angle between two vector
*/
Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);}
Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);}
/**
* @brief Method that returns the angle between of the current vector and vector "v" in Rad
* @brief Method that returns the angle between of the current vector and vector "v" in Rad
*
* @param v vector of type PIMathVectorT
* @return value of the angle between two vectors in Rad
*/
Type angleRad(const _CVector & v) const {return acos(angleCos(v));}
Type angleRad(const _CVector & v) const {return acos(angleCos(v));}
/**
* @brief Method that returns the angle between of the current vector and vector "v" in Deg
* @brief Method that returns the angle between of the current vector and vector "v" in Deg
*
* @param v vector of type PIMathVectorT
* @return value of the angle between two vectors in Deg
*/
Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));}
Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));}
/**
* @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg
* @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg
*
* @param v vector of type PIMathVectorT
* @return value of the angle elevation between two vectors in Deg
*/
Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;}
Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;}
/**
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v".
@@ -172,17 +172,17 @@ public:
* @param v vector of type PIMathVectorT
* @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v"
*/
_CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
_CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
/**
* @brief Method that returns this normalized vector
* @brief Method that returns this normalized vector (each element of a vector is divided by the absolute value of this vector)
*
* @return reference to this
*/
_CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs<Type>(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;}
/**
* @brief Method that returns a normalized vector
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
*
* @return normalized vector of type PIMathVectorT
*/
@@ -212,11 +212,11 @@ public:
bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;}
/**
* @brief Method which checks if current vector is orthogonal to vector "v"
* @brief Method which checks if current vector is orthogonal to vector "v"
*
* @param v vector of type PIMathVectorT
* @return true if vectors are orthogonal, else fal */
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
/**
* @brief Read-only access to elements reference by index of the vector element "index"
@@ -244,15 +244,16 @@ public:
const Type & operator [](uint index) const {return c[index];}
/**
* @brief Vector assignment to vector "v" of type PIMathVectorT
* @brief Assignment all elements of this vector with all elements of vector "v"
* If the vectors have different dimensions, it returns this without changing anything
*
* @param v vector for the assigment
* @return vector equal to vector "v"
* @return reference to this
*/
_CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;}
/**
* @brief Assignment operation. All vector values become equal to "v"
* @brief Assignment all elements of this vector with all elements of value "v"
*
* @param v value for the assigment
* @return reference to this
@@ -260,7 +261,7 @@ public:
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Compare with vector "v"
* @brief Compare all elements of this vector with all elements of vector "v"
*
* @param v vector for the compare
* @return if vectors are equal true, else false
@@ -268,7 +269,7 @@ public:
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;}
/**
* @brief Compare with vector "v"
* @brief Compare all elements of this vector with all elements of vector "v"
*
* @param v vector for the compare
* @return if vectors are not equal true, else false
@@ -276,46 +277,46 @@ public:
bool operator !=(const _CVector & v) const {return !(*this == v);}
/**
* @brief Vector addition this vector with vector "v"
* @brief Addition all elements of this vector with all elements vector "v"
*
* @param v vector for the addition assigment
*/
void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];}
void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];}
/**
* @brief Subtraction assignmentthis vector with vector "v"
* @brief Subtraction all elements of this vector with all elements vector "v"
*
* @param v vector for the subtraction assigment
*/
void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];}
void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];}
/**
* @brief Multiplication assignment this vector with value "v"
* @brief Multiplication all elements of this vector with value "v"
*
* @param v value for the multiplication assigment
*/
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
/**
* @brief Multiplication assignment this vector with vector "v"
* @brief Multiplication all elements of this vector with all elements vector "v"
*
* @param v vector for the multiplication assigment
*/
void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];}
void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];}
/**
* @brief Division assignment with this vector value "v"
* @brief Division all elements of this vector with value "v"
*
* @param v value for the division assigment
*/
void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;}
/**
* @brief Division assignment this vector with vector "v"
* @brief Division all elements of this vector with all elements vector "v"
*
* @param v vector for the division assigment
*/
void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];}
void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];}
/**
* @brief Vector substraction this vector
@@ -325,23 +326,23 @@ public:
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
/**
* @brief Vector addition this vector with vector "v"
* @brief Addition all elements of this vector with all elements of vector "v"
*
* @param v is vector term
* @return the result of vector addition
*/
_CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
_CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
/**
* @brief Vector substraction this vector with vector "v"
* @brief Substraction all elements of this vector with all elements of vector "v"
*
* @param v is vector term
* @return the result of vector substraction
*/
_CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
_CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
/**
* @brief Vector multiplication this vector with value "v"
* @brief Multiplication all elements of this vector with value "v"
*
* @param v is value factor
* @return the result of vector multiplication
@@ -349,7 +350,7 @@ public:
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
/**
* @brief Vector division this vector with value "v"
* @brief Division all elements of this vector with value "v"
*
* @param v is value divider
* @return the result of vector division
@@ -357,12 +358,12 @@ public:
_CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;}
/**
* @brief Vector division this vector with vector "v"
* @brief Division all elements of this vector with all elements of vector "v"
*
* @param v is vector divider
* @return the result of vector division
*/
_CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;}
_CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;}
/**
* @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector
@@ -373,20 +374,20 @@ public:
_CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;}
/**
* @brief Elementwise assignment of multiplication of two vectors
* @brief Elementwise assignment of multiplication of two vectors
*
* @param v is vector for multiplication
* @return resulting vector
*/
_CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
_CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
/**
* @brief Absolute value of the dot product
* @brief Absolute value of the dot product
*
* @param v is vector for dot product
* @return resulting vector
*/
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
PIMathMatrixT<1, Size, Type> transposed() const {
PIMathMatrixT<1, Size, Type> ret;
@@ -418,7 +419,7 @@ private:
};
/**
* @brief Inline operator which returns vector multiplication with value "x"
* @brief Multiplication all vector elements with value "x"
*
* @param x value for the multiplication
* @param v vector for the multiplication
@@ -430,7 +431,7 @@ inline PIMathVectorT<Size, Type> operator *(const Type & x, const PIMathVectorT<
}
/**
* @brief Inline operator for outputting the vector to the console
* @brief Outputting the vector to the console
*
* @param s PICout type
* @param the vector type PIMathVectorT that we print to the console
@@ -440,7 +441,7 @@ template<uint Size, typename Type>
inline PICout operator <<(PICout s, const PIMathVectorT<Size, Type> & v) {s << "{"; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << "}"; return s;}
/**
* @brief Inline operator checking if the cross product is zero. Works only with vector containing three elements, otherwise returns current vector
* @brief Checking if the cross product of two vectors is zero. Works only with vector containing three elements, otherwise returns current vector
*
* @param f vector of the first operand
* @param s vector of the second operand
@@ -450,7 +451,7 @@ template<uint Size, typename Type>
inline bool operator ||(const PIMathVectorT<Size, Type> & f, const PIMathVectorT<Size, Type> & s) {return (f * s).isNull();}
/**
* @brief Inline function which takes the square root of each element in the vector
* @brief The square root of every element in the vector
*
* @param v vector of whose elements the square root is taken
* @return resulting vector
@@ -459,7 +460,7 @@ template<uint Size, typename Type>
inline PIMathVectorT<Size, Type> sqrt(const PIMathVectorT<Size, Type> & v) {PIMathVectorT<Size, Type> ret; PIMV_FOR(i, 0) {ret[i] = sqrt(v[i]);} return ret;}
/**
* @brief Inline function which squares each element of the vector
* @brief Squares every element of the vector
*
* @param v vector whose elements are squared
* @return resulting vector
@@ -468,7 +469,7 @@ template<uint Size, typename Type>
inline PIMathVectorT<Size, Type> sqr(const PIMathVectorT<Size, Type> & v) {PIMathVectorT<Size, Type> ret; PIMV_FOR(i, 0) {ret[i] = sqr(v[i]);} return ret;}
/**
* @brief Inline operator for serializing a vector into a PIByteArray
* @brief Serializing a vector into a PIByteArray
*
* @param s PIByteArray type
* @param v PIMathVectorT type
@@ -478,7 +479,7 @@ template<uint Size, typename Type>
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s << v[i]; return s;}
/**
* @brief Inline operator to deserialize vector from PIByteArray
* @brief Deserializing vector from PIByteArray
*
* @param s PIByteArray type
* @param v PIMathVector type
@@ -488,7 +489,7 @@ template<uint Size, typename Type>
inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;}
/**
* @brief Inline function which returns vector size 2 and type of T
* @brief Function which returns vector size 2 and type of T
*
* @param x first element of vector
* @param y second element of vector
@@ -498,7 +499,7 @@ template<typename T>
inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector<T>() << x << y);}
/**
* @brief Inline function which returns vector size 3 and type of T
* @brief Function which returns vector size 3 and type of T
*
* @param x first element of vector
* @param y second element of vector
@@ -509,7 +510,7 @@ template<typename T>
inline PIMathVectorT<3u, T> createVectorT3(T x, T y, T z) {return PIMathVectorT<3u, T>(PIVector<T>() << x << y << z);}
/**
* @brief Inline function which returns vector size 4 and type of T
* @brief Function which returns vector size 4 and type of T
*
* @param x first element of vector
* @param y second element of vector
@@ -699,14 +700,14 @@ public:
_CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
/**
* @brief Method that returns a normalized vector
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
*
* @return copy of normalized vector of type PIMathVector
*/
_CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs<Type>(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;}
/**
* @brief Method that returns a normalized vector
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
*
* @return normalized vector of type PIMathVector
*/
@@ -720,7 +721,7 @@ public:
bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;}
/**
* @brief Method which checks if vector is valid
* @brief Method which checks if vector is empty
*
* @return true if vector is valid, else false
*/
@@ -761,7 +762,7 @@ public:
const Type & operator [](uint index) const {return c[index];}
/**
* @brief Vector assignment to vector "v" of type PIMathVector
* @brief Assignment all elements of this vector with all elements of vector "v"
* If the vectors have different dimensions, it returns this without changing anything
*
* @param v vector for the assigment
@@ -770,7 +771,7 @@ public:
_CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;}
/**
* @brief Vector assignment to value "v"
* @brief Assignment all elements of this vector with all elements of value "v"
*
* @param v value for the assigment
* @return reference to this
@@ -778,7 +779,7 @@ public:
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Compare with vector "v"
* @brief Compare all elements of this vector with all elements of vector "v"
*
* @param v vector for the compare
* @return if vectors are equal true, else false
@@ -786,7 +787,7 @@ public:
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;}
/**
* @brief Compare with vector "v"
* @brief Compare all elements of this vector with all elements of vector "v"
*
* @param v vector for the compare
* @return if vectors are not equal true, else false
@@ -794,42 +795,42 @@ public:
bool operator !=(const _CVector & v) const {return !(*this == v);}
/**
* @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
* @brief Addition all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
*
* @param v vector for the addition assigment
*/
void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];}
/**
* @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
* @brief Subtraction all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
*
* @param v vector for the subtraction assigment
*/
void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];}
/**
* @brief Multiplication assignment this vector with value "v"
* @brief Multiplication all elements of this vector with value "v"
*
* @param v value for the multiplication assigment
*/
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
/**
* @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
* @brief Multiplication all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
*
* @param v vector for the multiplication assigment
*/
void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];}
/**
* @brief Division assignment this vector with value "v"
* @brief Division all elements of this vector with value "v"
*
* @param v value for the division assigment
*/
void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;}
/**
* @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
* @brief Division all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
*
* @param v vector for the division assigment
*/
@@ -843,15 +844,15 @@ public:
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
/**
* @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything
* @brief Addition all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything
*
* @param v is vector term
* @return the result of matrix addition
* @return the result of vector addition
*/
_CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
/**
* @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything
* @brief Substraction all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything
*
* @param v is vector term
* @return the result of vector substraction
@@ -859,7 +860,7 @@ public:
_CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
/**
* @brief Vector multiplicationthis vector with value "v"
* @brief Multiplication all elements of this vector with value "v"
*
* @param v is value factor
* @return the result of vector multiplication
@@ -867,7 +868,7 @@ public:
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
/**
* @brief Vector division this vector with value "v"
* @brief Division all elements of this vector with value "v"
*
* @param v is value divider
* @return the result of vector division
@@ -932,7 +933,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathVector<Type> & v
#endif
/**
* @brief Inline operator for outputting the vector to the console
* @brief Outputting the vector to the console
*
* @param s PICout type
* @param the vector type PIMathVector that we print to the console
@@ -942,7 +943,7 @@ template<typename Type>
inline PICout operator <<(PICout s, const PIMathVector<Type> & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;}
/**
* @brief Inline operator for serializing a vector into a PIByteArray
* @brief Serializing a vector into a PIByteArray
*
* @param s PIByteArray type
* @param v PIMathVector type
@@ -952,7 +953,7 @@ template<typename Type>
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector<Type> & v) {s << v.c; return s;}
/**
* @brief Inline operator to deserialize vector from PIByteArray
* @brief Deserializing vector from PIByteArray
*
* @param s PIByteArray type
* @param v PIMathVector type

View File

@@ -8,7 +8,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double v
bool b = true;
for(int i = 0; i < num; i++) {
for(int j = 0; j < num; j++) {
if(matrix.at(i, j) - val >= double(1E-200)) {
if(matrix[i][j] - val >= double(1E-200)) {
b = false;
}
}
@@ -63,15 +63,15 @@ TEST(PIMathMatrixT_Test, col) {
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect;
uint g = 2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
vect = matr.col(g);
for(uint i = 0; i < matr.cols(); i++) {
if(matr.at(i, g) != vect.at(i)) {
@@ -85,15 +85,15 @@ TEST(PIMathMatrixT_Test, row) {
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect;
uint g = 2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
vect = matr.row(g);
for(uint i = 0; i < matr.rows(); i++) {
if(matr.at(g, i) != vect.at(i)) {
@@ -138,15 +138,15 @@ TEST(PIMathMatrixT_Test, setRow) {
TEST(PIMathMatrixT_Test, swapCols) {
PIMathMatrixT<rows, cols, double> matr;
int g1 = 1, g2 = 2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
matr.swapCols(g1, g2);
@@ -163,15 +163,15 @@ TEST(PIMathMatrixT_Test, swapCols) {
TEST(PIMathMatrixT_Test, swapRows) {
PIMathMatrixT<rows, cols, double> matr;
int g1 = 1, g2 = 2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
matr.swapRows(g1, g2);
@@ -192,7 +192,7 @@ TEST(PIMathMatrixT_Test, fill) {
matr.fill(g);
for(uint i = 0; i < cols; i++) {
for(uint j = 0; j < rows; j++) {
matrix1.at(j,i) = g;
matrix1[j][i] = g;
}
}
ASSERT_TRUE(matr == matrix1);
@@ -239,56 +239,56 @@ TEST(PIMathMatrixT_Test, operator_Assignment) {
TEST(PIMathMatrixT_Test, operator_EqualTrue) {
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
matrix1.at(0, 0) = 5.1;
matrix1.at(0, 1) = 1.21;
matrix1.at(1, 1) = 0.671;
matrix1.at(1, 0) = 2.623;
matrix2.at(0, 0) = 5.1;
matrix2.at(0, 1) = 1.21;
matrix2.at(1, 1) = 0.671;
matrix2.at(1, 0) = 2.623;
matrix1[0][0] = 5.1;
matrix1[0][1] = 1.21;
matrix1[1][1] = 0.671;
matrix1[1][0] = 2.623;
matrix2[0][0] = 5.1;
matrix2[0][1] = 1.21;
matrix2[1][1] = 0.671;
matrix2[1][0] = 2.623;
ASSERT_TRUE(matrix1 == matrix2);
}
TEST(PIMathMatrixT_Test, operator_EqualFalse) {
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
matrix1.at(0, 0) = 5.1;
matrix1.at(0, 1) = 1.21;
matrix1.at(1, 1) = 0.671;
matrix1.at(1, 0) = 2.623;
matrix2.at(0, 0) = 5.1;
matrix2.at(0, 1) = 1.21;
matrix2.at(1, 1) = 665.671;
matrix2.at(1, 0) = 2.623;
matrix1[0][0] = 5.1;
matrix1[0][1] = 1.21;
matrix1[1][1] = 0.671;
matrix1[1][0] = 2.623;
matrix2[0][0] = 5.1;
matrix2[0][1] = 1.21;
matrix2[1][1] = 665.671;
matrix2[1][0] = 2.623;
ASSERT_FALSE(matrix1 == matrix2);
}
TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) {
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
matrix1.at(0, 0) = 5.1;
matrix1.at(0, 1) = 1.21;
matrix1.at(1, 1) = 0.671;
matrix1.at(1, 0) = 2.623;
matrix2.at(0, 0) = 5.1;
matrix2.at(0, 1) = 1.21;
matrix2.at(1, 1) = 665.671;
matrix2.at(1, 0) = 2.623;
matrix1[0][0] = 5.1;
matrix1[0][1] = 1.21;
matrix1[1][1] = 0.671;
matrix1[1][0] = 2.623;
matrix2[0][0] = 5.1;
matrix2[0][1] = 1.21;
matrix2[1][1] = 665.671;
matrix2[1][0] = 2.623;
ASSERT_TRUE(matrix1 != matrix2);
}
TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) {
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
matrix1.at(0, 0) = 5.1;
matrix1.at(0, 1) = 1.21;
matrix1.at(1, 1) = 0.671;
matrix1.at(1, 0) = 2.623;
matrix2.at(0, 0) = 5.1;
matrix2.at(0, 1) = 1.21;
matrix2.at(1, 1) = 0.671;
matrix2.at(1, 0) = 2.623;
matrix1[0][0] = 5.1;
matrix1[0][1] = 1.21;
matrix1[1][1] = 0.671;
matrix1[1][0] = 2.623;
matrix2[0][0] = 5.1;
matrix2[0][1] = 1.21;
matrix2[1][1] = 0.671;
matrix2[1][0] = 2.623;
ASSERT_FALSE(matrix1 != matrix2);
}
@@ -343,30 +343,30 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) {
double d;
double i = 59.0;
PIMathMatrixT<rows, cols, double> matr;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
d = matr.determinant();
ASSERT_DOUBLE_EQ(i, d);
}
TEST(PIMathMatrixT_Test, determinantIfNotSquare) {
PIMathMatrixT<rows, 5u, double> matr;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
ASSERT_FALSE(matr.determinant());
}
@@ -376,15 +376,15 @@ TEST(PIMathMatrixT_Test, invert) {
PIMathMatrixT<rows, cols, double> matrix3;
PIMathMatrixT<rows, cols, double> matr;
double d1, d2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
matrix2 = matr;
matr.invert();
d1 = matr.determinant();
@@ -401,15 +401,15 @@ TEST(PIMathMatrixT_Test, inverted) {
PIMathMatrixT<rows, cols, double> matr;
double d1, d2;
matrix1 = matr.identity();
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
matrix2 = matr.inverted();
d1 = matr.determinant();
d2 = matrix2.determinant();
@@ -421,15 +421,15 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) {
PIMathMatrixT<rows, cols, double> matrix;
double d1, d2 = 1;
PIMathMatrixT<rows, cols, double> matr;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
matrix = matr.toUpperTriangular();
d1 = matrix.determinant();
for(uint i = 0; i < cols; i++)
@@ -444,15 +444,15 @@ TEST(PIMathMatrixT_Test, transposed) {
PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr;
double d1, d2;
matr.at(0,0) = 3;
matr.at(0,1) = 6;
matr.at(0,2) = 8;
matr.at(1,0) = 2;
matr.at(1,1) = 1;
matr.at(1,2) = 4;
matr.at(2,0) = 6;
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matr[0][0] = 3;
matr[0][1] = 6;
matr[0][2] = 8;
matr[1][0] = 2;
matr[1][1] = 1;
matr[1][2] = 4;
matr[2][0] = 6;
matr[2][1] = 2;
matr[2][2] = 5;
d1 = matr.determinant();
matrix1 = matr.transposed();
d2 = matrix1.determinant();

View File

@@ -24,14 +24,16 @@ TEST(PIMathVector_Test, resize) {
PIMathVector<double> vector;
vector.resize(newSize, a);
ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size()));
ASSERT_TRUE(vector.size() == newSize);
}
TEST(PIMathVector_Test, resized) {
uint newSize = 4u;
double a = 5.0;
PIMathVector<double> vector;
vector.resized(newSize, a);
ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size()));
auto vect = vector.resized(newSize, a);
ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size()) && vect.size() == newSize);
ASSERT_TRUE(vect.size() == newSize);
}
TEST(PIMathVector_Test, fill) {

View File

@@ -14,7 +14,7 @@ bool cmpVectorWithValue(PIMathVectorT<SIZE, double> vector, double val, int num)
return b;
}
TEST(PIMathVectorT_Test, SIZE) {
TEST(PIMathVectorT_Test, size) {
PIMathVectorT<SIZE, double> vector;
ASSERT_TRUE(vector.size() == SIZE);
}