full documentacion for PIMathVectorT

This commit is contained in:
2020-09-22 13:53:07 +03:00
parent b60c147f9d
commit c07b7efe65

View File

@@ -1,4 +1,4 @@
/*! \file pimathvector.h
/*! \file pimathvector.h
* \brief PIMathVector
*
* This file declare math vector class, which performs various vector operations
@@ -244,24 +244,149 @@ public:
* @return element of vector
*/
Type operator [](uint index) const {return c[index];}
/**
* @brief Vector assignment to vector "v" of type PIMathVectorT
*
* @param v vector for the assigment
* @return vector equal to vector "v"
*/
_CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); 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"
*/
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
/**
* @brief Compare with vector "v"
*
* @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;}
/**
* @brief Compare with vector "v"
*
* @param v vector for the compare
* @return if vectors are not equal true, else false
*/
bool operator !=(const _CVector & v) const {return !(*this == v);}
/**
* @brief Addition assignment with vector "v"
*
* @param v vector for the addition assigment
*/
void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];}
/**
* @brief Subtraction assignment with vector "v"
*
* @param v vector for the subtraction assigment
*/
void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];}
/**
* @brief Multiplication assignment 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"
*
* @param v vector for the multiplication assigment
*/
void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];}
/**
* @brief Division assignment 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"
*
* @param v vector for the division assigment
*/
void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];}
/**
* @brief Vector substraction
*
* @return the result of vector substraction
*/
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
/**
* @brief Matrix addition
*
* @param sm is matrix 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;}
/**
* @brief Vector substraction
*
* @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;}
/**
* @brief Vector multiplication with value "v"
*
* @param v is value factor
* @return the result of vector multiplication
*/
_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"
*
* @param v is value divider
* @return the result of vector division
*/
_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"
*
* @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;}
/**
* @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector
*
* @param v is vector for cross product
* @return the result vector equal of cross product
*/
_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
*
* @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;}
/**
* @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;}
PIMathMatrixT<1, Size, Type> transposed() const {
@@ -270,14 +395,32 @@ 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
*
* @return the resulting vector that is part of this vector
*/
template<uint Size1, typename Type1> /// vector {Size, Type} to vector {Size1, Type1}
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
*
* @param v this value fills the cells of the vector
* @return filled vector of type PIMathVectorT
*/
static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;}
private: