documentation and tests bug fix for PIMathVector.h

This commit is contained in:
2020-09-25 12:36:05 +03:00
parent b7f035178f
commit 0940e8fa44
5 changed files with 740 additions and 590 deletions

View File

@@ -47,7 +47,6 @@ public:
/**
* @brief Constructor that calls the private resize method
*
* @return resized vector of type PIMathMatrixT
*/
PIMathVectorT() {resize();}
@@ -55,7 +54,6 @@ public:
* @brief Constructor that fills a vector PIMathVectorT with the values of another vector "PIVector"
*
* @param val vector of type PIVector which is identified PIMathVectorT
* @return vector of type PIMathVectorT with values of vector val
*/
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
@@ -64,49 +62,48 @@ public:
*
* @param st vector of type PIMathVectorT
* @param fn vector of type PIMathVectorT
* @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st"
*/
PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);}
/**
* @brief Method which returns size of the vector
* @brief Method that returns the number of elements contained in the vector
*
* @return type uint shows number of elements in this vector
*/
uint size() const {return Size;}
/**
* @brief Method that fills a vector with a value
* @brief Method that set this elements to value "v"
*
* @param v value of which the vector is filled
* @return vector of type PIMathVectorT filled with "v"
* @return reference to this
*/
_CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Method that fills a vector with the subtraction of two vectors
* @brief Method that set this with the subtraction of two vectors
*
* @param st vector of type PIMathVectorT
* @param fn vector of type PIMathVectorT
* @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st"
* @return reference to this
*/
_CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;}
/**
* @brief Method that fills a vector with the adittion of vector value and "v"
* @brief Method that sets this using a vector, each element of which is added to the value of "v"
*
* @param v value of which the vector is filled
* @return vector of type PIMathVectorT with values adittion of vector value and "v"
* @return reference to this
*/
_CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;}
/**
* @brief Method that fills a vector with the adittion of vector value and "v"
* @brief Method that sets this with a vector, each element of which is added to each element of the vector "v"
*
* @param v vector of type PIMathVectorT
* @return vector of type PIMathVectorT with values adittion of vector value and "v"
* @return reference to this
*/
_CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
_CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
/**
* @brief Method that returns sum of the squares of all elements of the vector
@@ -116,7 +113,7 @@ public:
Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;}
/**
* @brief Method that returns length of a vector
* @brief Method that returns a scalar physical value equal to the absolute value of vector
*
* @return value equal to length of a vector
*/
@@ -131,56 +128,62 @@ public:
/**
* @brief Method that returns the cos of the current vector and vector "v"
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; _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"
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v".
* If the vectors have different dimensions, it returns this without changing anything
*
* @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) {if(v.size() != Size) return _CVector(*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 this normalized vector
*
* @return copy of normalized vector of type PIMathVectorT
* @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;}
@@ -215,12 +218,13 @@ 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".
* If the vectors have different dimensions, it returns false
*
* @param v vector of type PIMathVectorT
* @return true if vectors are orthogonal, else false
*/
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
bool isOrtho(const _CVector & v) const {if(v.size() != Size) return false; return ((*this) ^ v) == Type(0);}
/**
* @brief Read-only access to elements reference by index of the vector element "index"
@@ -245,10 +249,10 @@ public:
* @param index is the index of necessary element
* @return element of vector
*/
Type operator [](uint index) const {return c[index];}
const Type & operator [](uint index) const {return c[index];}
/**
* @brief Vector assignment to vector "v" of type PIMathVectorT
* @brief Vector assignment to vector "v" of type PIMathVectorT
*
* @param v vector for the assigment
* @return vector equal to vector "v"
@@ -256,12 +260,12 @@ public:
_CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;}
/**
* @brief Vector assignment to value "v"
* @brief Assignment operation. All vector values become equal to "v"
*
* @param v value for the assigment
* @return vector, each element of which is equal to the value "v"
* @return reference to this
*/
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Compare with vector "v"
@@ -280,71 +284,72 @@ public:
bool operator !=(const _CVector & v) const {return !(*this == v);}
/**
* @brief Addition assignment with vector "v"
* @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] += v[i];}
/**
* @brief Subtraction assignment with vector "v"
* @brief Subtraction assignmentthis vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] -= v[i];}
/**
* @brief Multiplication assignment with value "v"
* @brief Multiplication assignment 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 with vector "v"
* @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] *= v[i];}
/**
* @brief Division assignment with value "v"
* @brief Division assignment with this vector value "v"
*
* @param v value for the division assigment
*/
void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;}
/**
* @brief Division assignment with vector "v"
* @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] /= v[i];}
/**
* @brief Vector substraction
* @brief Vector substraction this vector
*
* @return the result of vector substraction
*/
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
/**
* @brief Matrix addition
* @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything
*
* @param sm is matrix term
* @return the result of matrix addition
* @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 {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
/**
* @brief Vector substraction
* @brief Vector substraction this vector with 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
*/
_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 {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
/**
* @brief Vector multiplication with value "v"
* @brief Vector multiplication this vector with value "v"
*
* @param v is value factor
* @return the result of vector multiplication
@@ -352,7 +357,7 @@ public:
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
/**
* @brief Vector division with value "v"
* @brief Vector division this vector with value "v"
*
* @param v is value divider
* @return the result of vector division
@@ -360,12 +365,12 @@ public:
_CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;}
/**
* @brief Vector division with vector "v"
* @brief Vector division this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything
*
* @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 {if(v.size() != Size) return _CVector(*this); _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
@@ -376,20 +381,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. If the vectors have different dimensions, it returns this without changing anything
*
* @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 {if(v.size() != Size) return _CVector(*this); _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. If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != Size) return false; 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;
@@ -397,18 +402,6 @@ public:
return ret;
}
/**
* @brief Returns the distance between two vectors. Works only for 2-element vectors
*
* @param lp0 is vector
* @param lp1 is vector
* @return resulting value
*/
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
return f;}
/**
* @brief The method returns a part of the selected vector from the given vector
*
@@ -418,7 +411,7 @@ public:
PIMathVectorT<Size1, Type1> turnTo() const {PIMathVectorT<Size1, Type1> tv; uint sz = piMin<uint>(Size, Size1); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;}
/**
* @brief Creates a vector filled with a value
* @brief Creates a vector each element of which is equal to value "v"
*
* @param v this value fills the cells of the vector
* @return filled vector of type PIMathVectorT
@@ -570,7 +563,6 @@ public:
* @brief Constructor that calls the resize method
*
* @param size vector dimension
* @return resized vector of type PIMathMatrix
*/
PIMathVector(const uint size = 0) {c.resize(size);}
@@ -578,7 +570,6 @@ public:
* @brief Constructor that fills a vector PIMathVector with the values of another vector "PIVector"
*
* @param val vector of type PIVector which is identified PIMathVector
* @return vector of type PIMathVector with values of vector val
*/
PIMathVector(const PIVector<Type> & val) {c.resize(val.size()); PIMV_FOR(i, 0) c[i] = val[i];}
@@ -587,15 +578,14 @@ public:
*
* @param st vector of type PIMathVector
* @param fn vector of type PIMathVector
* @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st"
*/
PIMathVector(const _CVector & st, const _CVector & fn) {c.resize(st.size()); PIMV_FOR(i, 0) c[i] = fn[i] - st[i];}
/**
* @brief Method which returns size of the vector
*
* @return type uint shows number of elements in this vector
*/
/**
* @brief Method that returns the number of elements contained in the vector
*
* @return type uint shows number of elements in this vector
*/
uint size() const {return c.size();}
/**
@@ -603,7 +593,7 @@ public:
*
* @param size new vector dimension
* @param new_value value with which the vector is filled
* @return resized vector
* @return reference to this
*/
_CVector & resize(uint size, const Type & new_value = Type()) {c.resize(size, new_value); return *this;}
@@ -616,37 +606,38 @@ public:
*/
_CVector resized(uint size, const Type & new_value = Type()) {_CVector tv = _CVector(*this); tv.resize(size, new_value); return tv;}
/**
* @brief Method that fills a vector with a value
*
* @param v value of which the vector is filled
* @return vector of type PIMathVector filled with "v"
*/
/**
* @brief Method that set this elements to value "v"
*
* @param v value of which the vector is filled
* @return reference to this
*/
_CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Method that fills a vector with the adittion of vector value and "v"
*
* @param v value of which the vector is filled
* @return vector of type PIMathVector with values adittion of vector value and "v"
*/
/**
* @brief Method that sets this using a vector, each element of which is added to the value of "v"
*
* @param v value of which the vector is filled
* @return reference to this
*/
_CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;}
/**
* @brief Method that fills a vector with the adittion of vector value and "v"
*
* @param v vector of type PIMathVectorT
* @return vector of type PIMathVectorT with values adittion of vector value and "v"
*/
_CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
/**
* @brief Method that sets this with a vector, each element of which is added to each element of the vector "v".
* If the vectors have different dimensions, it returns this without changing anything
*
* @param v vector of type PIMathVectorT
* @return reference to this
*/
_CVector & move(const _CVector & v) {if(v.size() != c.size()) return *this; PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
/**
* @brief Method that replaces two elements in a vector by indices. You cannot use an index larger than the number vector dimension,
* @brief Method that replaces two elements in this vector by indices. You cannot use an index larger than the number vector dimension,
* otherwise there will be "undefined behavior"
*
* @param fe index of the first element
* @param se index of the second element
* @return resulting vector of type PIMathVector
* @return reference to this
*/
_CVector & swap(uint fe, uint se) {piSwap<Type>(c[fe], c[se]); return *this;}
@@ -657,11 +648,11 @@ public:
*/
Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;}
/**
* @brief Method that returns length of a vector
*
* @return value equal to length of a vector
*/
/**
* @brief Method that returns a scalar physical value equal to the absolute value of vector
*
* @return value equal to length of a vector
*/
Type length() const {return sqrt(lengthSqr());}
/**
@@ -672,44 +663,48 @@ public:
Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;}
/**
* @brief Method that returns the cos of the current vector and vector "v"
* @brief Method that returns the cos of the current vector and vector "v". If the vectors have different dimensions, it returns false
*
* @param v vector of type PIMathVector
* @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 {if(v.size() != c.size()) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @param v vector of type PIMathVector
* @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 {if(v.size() != c.size()) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @param v vector of type PIMathVector
* @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 {if(v.size() != c.size()) return false; 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.
* If the vectors have different dimensions, it returns false
*
* @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 {if(v.size() != c.size()) return false; return toDeg(acos(angleCos(v)));}
/**
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v"
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v".
* If the vectors have different dimensions, it returns this without changing anything
*
* @param v vector of type PIMathVector
* @return vector of type PIMathVector 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) {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
@@ -740,12 +735,13 @@ public:
bool isValid() const {return !c.isEmpty();}
/**
* @brief Method which checks if current vector is orthogonal to vector "v"
* @brief Method which checks if current vector is orthogonal to vector "v".
* If the vectors have different dimensions, it returns false
*
* @param v vector of type PIMathVector
* @return true if vectors are orthogonal, else false
*/
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
bool isOrtho(const _CVector & v) const {if(v.size() != c.size()) return false; return ((*this) ^ v) == Type(0);}
/**
* @brief Read-only access to elements reference by index of the vector element "index"
@@ -770,21 +766,22 @@ public:
* @param index is the index of necessary element
* @return element of vector
*/
Type operator [](uint index) const {return c[index];}
const Type & operator [](uint index) const {return c[index];}
/**
* @brief Vector assignment to vector "v" of type PIMathVector
* 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) {c = v.c; return *this;}
_CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;}
/**
* @brief Vector assignment to value "v"
*
* @param v value for the assigment
* @return vector, each element of which is equal to the value "v"
* @return reference to this
*/
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
@@ -794,7 +791,7 @@ public:
* @param v vector for the compare
* @return if vectors are equal true, else false
*/
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;}
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"
@@ -805,71 +802,72 @@ public:
bool operator !=(const _CVector & v) const {return !(*this == v);}
/**
* @brief Addition assignment with vector "v"
* @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];}
/**
* @brief Subtraction assignment with vector "v"
* @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];}
/**
* @brief Multiplication assignment with value "v"
* @brief Multiplication assignment 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 with vector "v"
* @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];}
/**
* @brief Division assignment with value "v"
* @brief Division assignment 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 with vector "v"
* @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void()
*
* @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) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] /= v[i];}
/**
* @brief Vector substraction
* @brief Vector substraction this vector
*
* @return the result of vector substraction
*/
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
/**
* @brief Matrix addition
* @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything
*
* @param sm is matrix term
* @param v is vector term
* @return the result of matrix 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 {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
* @brief Vector substraction this vector with 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
*/
_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 {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
/**
* @brief Vector multiplication with value "v"
* @brief Vector multiplicationthis vector with value "v"
*
* @param v is value factor
* @return the result of vector multiplication
@@ -877,7 +875,7 @@ public:
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
/**
* @brief Vector division with value "v"
* @brief Vector division this vector with value "v"
*
* @param v is value divider
* @return the result of vector division
@@ -890,36 +888,23 @@ public:
* @param v is vector for cross product
* @return the result vector equal of cross product
*/
_CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); 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;}
_CVector operator *(const _CVector & v) const {if ((c.size() != 3) || (v.size() != 3)) return _CVector(); _CVector tv(3); 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. If the vectors have different dimensions, it returns this without changing anything
*
* @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 {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
/**
* @brief Absolute value of the dot product
* @brief Value of the dot product. If the vectors have different dimensions, it returns false
*
* @param v is vector for dot product
* @return resulting vector
* @return resulting value
*/
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
/**
* @brief Returns the distance between two vectors. Works only for 2-element vectors
*
* @param lp0 is vector
* @param lp1 is vector
* @return resulting value
*/
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
return f;
}
Type operator ^(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
/**
* @brief Converts PIMathVector to PIVector type