diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 7c4a9b41..190da7a9 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -37,7 +37,6 @@ template class PIP_EXPORT PIMathVectorT { typedef PIMathVectorT _CVector; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Size > 0, "Size count must be > 0"); public: PIMathVectorT() {resize();} PIMathVectorT(const PIVector & 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 - PIMathVector turnTo(uint size) const {PIMathVector tv; uint sz = piMin(c.size(), size); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;} PIVector toVector() const {return c;} inline Type * data() {return c.data();}