bug fixes in pimathvector.h

This commit is contained in:
2020-09-17 17:09:07 +03:00
parent c3abd747f2
commit 0a458d28f3

View File

@@ -37,7 +37,6 @@ template<uint Size, typename Type = double>
class PIP_EXPORT PIMathVectorT {
typedef PIMathVectorT<Size, Type> _CVector;
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
static_assert(Size > 0, "Size count must be > 0");
public:
PIMathVectorT() {resize();}
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
@@ -64,14 +63,13 @@ public:
bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;}
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
Type & at(uint index) {return c[index];}
Type at(uint index) const {return c[index];}
const Type & at(uint index) {return c[index];}
Type & operator [](uint index) {return c[index];}
Type operator [](uint index) const {return c[index];}
_CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;}
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
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 {return !(*this == c);}
bool operator !=(const _CVector & v) const {return !(*this == v);}
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];}
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
@@ -191,14 +189,13 @@ public:
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
Type & at(uint index) {return c[index];}
Type at(uint index) const {return c[index];}
const Type & at(uint index) {return c[index];}
Type & operator [](uint index) {return c[index];}
Type operator [](uint index) const {return c[index];}
_CVector & operator =(const _CVector & v) {c = v.c; return *this;}
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
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 {return !(*this == c);}
bool operator !=(const _CVector & v) const {return !(*this == v);}
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];}
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
@@ -210,7 +207,7 @@ public:
_CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
_CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;}
_CVector operator *(const _CVector & v) const {if (c.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;}
_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 {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[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;}
@@ -220,8 +217,6 @@ public:
return f;
}
template<typename Type1>
PIMathVector turnTo(uint size) const {PIMathVector<Type1> tv; uint sz = piMin<uint>(c.size(), size); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;}
PIVector<Type> toVector() const {return c;}
inline Type * data() {return c.data();}