From c07b7efe65a7b3475a96944b1fddcc206a518c4f Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 22 Sep 2020 13:53:07 +0300 Subject: [PATCH] full documentacion for PIMathVectorT --- libs/main/math/pimathvector.h | 145 +++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index deefee7b..095b4598 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -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 /// vector {Size, Type} to vector {Size1, Type1} PIMathVectorT turnTo() const {PIMathVectorT tv; uint sz = piMin(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: