diff --git a/src/math/pimathmatrix.h b/src/math/pimathmatrix.h index 8e96acb8..e2d63418 100644 --- a/src/math/pimathmatrix.h +++ b/src/math/pimathmatrix.h @@ -4,7 +4,7 @@ /* PIP - Platform Independent Primitives PIMathMatrix - Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com + Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,6 +48,7 @@ public: //PIMathMatrixT(const _CMatrix & o) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} static _CMatrix identity() {_CMatrix tm = _CMatrix(); PIMM_FOR_WB(r, c) tm.m[r][c] = (c == r ? Type(1) : Type(0)); return tm;} + static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;} static _CMatrix rotation(double angle) {return _CMatrix();} static _CMatrix rotationX(double angle) {return _CMatrix();} static _CMatrix rotationY(double angle) {return _CMatrix();} @@ -75,7 +76,7 @@ public: Type at(uint row, uint col) const {return m[row][col];} Type * operator [](uint row) {return m[row];} const Type * operator [](uint row) const {return m[row];} - void operator =(const _CMatrix & sm) {memcpy(m, sm.m, sizeof(Type) * Cols * Rows);} + _CMatrix & operator =(const _CMatrix & sm) {memcpy(m, sm.m, sizeof(Type) * Cols * Rows); return *this;} bool operator ==(const _CMatrix & sm) const {PIMM_FOR_WB(r, c) if (m[r][c] != sm.m[r][c]) return false; return true;} bool operator !=(const _CMatrix & sm) const {return !(*this == sm);} void operator +=(const _CMatrix & sm) {PIMM_FOR_WB(r, c) m[r][c] += sm.m[r][c];} diff --git a/src/math/pimathvector.h b/src/math/pimathvector.h index 53e143ff..5e6a95d0 100644 --- a/src/math/pimathvector.h +++ b/src/math/pimathvector.h @@ -4,7 +4,7 @@ /* PIP - Platform Independent Primitives PIMathVector - Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com + Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com, Andrey Bychkov work.a.b@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -87,7 +87,7 @@ public: _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 {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} - _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;} + _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;} 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 {