git-svn-id: svn://db.shs.com.ru/pip@201 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
PIMathMatrix
|
PIMathMatrix
|
||||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -82,11 +82,11 @@ public:
|
|||||||
void operator -=(const _CMatrix & sm) {PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c];}
|
void operator -=(const _CMatrix & sm) {PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c];}
|
||||||
void operator *=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] *= v;}
|
void operator *=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] *= v;}
|
||||||
void operator /=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] /= v;}
|
void operator /=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] /= v;}
|
||||||
_CMatrix operator -() {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = -m[r][c]; return tm;}
|
_CMatrix operator -() const {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = -m[r][c]; return tm;}
|
||||||
_CMatrix operator +(const _CMatrix & sm) {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] += sm.m[r][c]; return tm;}
|
_CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] += sm.m[r][c]; return tm;}
|
||||||
_CMatrix operator -(const _CMatrix & sm) {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] -= sm.m[r][c]; return tm;}
|
_CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] -= sm.m[r][c]; return tm;}
|
||||||
_CMatrix operator *(const Type & v) {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] *= v; return tm;}
|
_CMatrix operator *(const Type & v) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] *= v; return tm;}
|
||||||
_CMatrix operator /(const Type & v) {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] /= v; return tm;}
|
_CMatrix operator /(const Type & v) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] /= v; return tm;}
|
||||||
|
|
||||||
Type determinant(bool * ok = 0) const {
|
Type determinant(bool * ok = 0) const {
|
||||||
_CMatrix m(*this);
|
_CMatrix m(*this);
|
||||||
@@ -202,7 +202,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
_CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;}
|
_CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;}
|
||||||
_CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[r][c] = m[r][c]; return tm;}
|
_CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;}
|
void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;}
|
||||||
@@ -246,7 +246,7 @@ inline PIMathMatrixT<Rows0, Cols1, Type> operator *(const PIMathMatrixT<Rows0, C
|
|||||||
return tm;
|
return tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multiply matrix {Rows x Cols} on vector {Rows}, result is vector {Cols}
|
/// Multiply matrix {Rows x Cols} on vector {Cols}, result is vector {Rows}
|
||||||
template<uint Cols, uint Rows, typename Type>
|
template<uint Cols, uint Rows, typename Type>
|
||||||
inline PIMathVectorT<Cols, Type> operator *(const PIMathMatrixT<Rows, Cols, Type> & fm,
|
inline PIMathVectorT<Cols, Type> operator *(const PIMathMatrixT<Rows, Cols, Type> & fm,
|
||||||
const PIMathVectorT<Rows, Type> & sv) {
|
const PIMathVectorT<Rows, Type> & sv) {
|
||||||
@@ -261,6 +261,29 @@ inline PIMathVectorT<Cols, Type> operator *(const PIMathMatrixT<Rows, Cols, Type
|
|||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
/// Multiply vector {Cols}T on matrix {Rows x Cols}, result is vector {Rows}T
|
||||||
|
template<uint Cols, uint Rows, typename Type>
|
||||||
|
inline PIMathVectorT<Cols, Type> operator *(const PIMathMatrixT<Rows, Cols, Type> & fm,
|
||||||
|
const PIMathVectorT<Rows, Type> & sv) {
|
||||||
|
PIMathVectorT<Rows, Type> tv;
|
||||||
|
Type t;
|
||||||
|
for (uint j = 0; j < Rows; ++j) {
|
||||||
|
t = Type(0);
|
||||||
|
for (uint i = 0; i < Cols; ++i)
|
||||||
|
t += fm[j][i] * sv[i];
|
||||||
|
tv[j] = t;
|
||||||
|
}
|
||||||
|
return tv;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows}
|
||||||
|
template<uint Cols, uint Rows, typename Type>
|
||||||
|
inline PIMathMatrixT<Rows, Cols, Type> operator *(const Type & x, const PIMathMatrixT<Rows, Cols, Type> & v) {
|
||||||
|
return v * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef PIMathMatrixT<2u, 2u, int> PIMathMatrixT22i;
|
typedef PIMathMatrixT<2u, 2u, int> PIMathMatrixT22i;
|
||||||
typedef PIMathMatrixT<3u, 3u, int> PIMathMatrixT33i;
|
typedef PIMathMatrixT<3u, 3u, int> PIMathMatrixT33i;
|
||||||
typedef PIMathMatrixT<4u, 4u, int> PIMathMatrixT44i;
|
typedef PIMathMatrixT<4u, 4u, int> PIMathMatrixT44i;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
PIMathVector
|
PIMathVector
|
||||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -96,12 +96,13 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator PIMathMatrixT<1, Size, Type>() {return transposed();}
|
// operator PIMathMatrixT<1, Size, Type>() {return transposed();}
|
||||||
operator PIMathMatrixT<Size, 1, Type>() {
|
// operator PIMathMatrixT<Size, 1, Type>() {
|
||||||
PIMathMatrixT<Size, 1, Type> ret;
|
// PIMathMatrixT<Size, 1, Type> ret;
|
||||||
PIMV_FOR(i, 0) ret[i][0] = c[i];
|
// PIMV_FOR(i, 0) ret[i][0] = c[i];
|
||||||
return ret;
|
// return ret;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
|
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
|
||||||
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
|
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
|
||||||
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();//, s = b.length() + c.length() - a.length();
|
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();//, s = b.length() + c.length() - a.length();
|
||||||
@@ -110,6 +111,8 @@ public:
|
|||||||
template<uint Size1, typename Type1> /// vector {Size, Type} to vector {Size1, Type1}
|
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;}
|
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;}
|
||||||
|
|
||||||
|
static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resize(const Type & new_value = Type()) {for (int i = 0; i < Size; ++i) c[i] = new_value;}
|
void resize(const Type & new_value = Type()) {for (int i = 0; i < Size; ++i) c[i] = new_value;}
|
||||||
|
|
||||||
@@ -118,6 +121,11 @@ private:
|
|||||||
};
|
};
|
||||||
//#pragma pack(pop)
|
//#pragma pack(pop)
|
||||||
|
|
||||||
|
template<uint Size, typename Type>
|
||||||
|
inline PIMathVectorT<Size, Type> operator *(const Type & x, const PIMathVectorT<Size, Type> & v) {
|
||||||
|
return v * x;
|
||||||
|
}
|
||||||
|
|
||||||
template<uint Size, typename Type>
|
template<uint Size, typename Type>
|
||||||
inline std::ostream & operator <<(std::ostream & s, const PIMathVectorT<Size, Type> & v) {s << '{'; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << '}'; return s;}
|
inline std::ostream & operator <<(std::ostream & s, const PIMathVectorT<Size, Type> & v) {s << '{'; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << '}'; return s;}
|
||||||
template<uint Size, typename Type>
|
template<uint Size, typename Type>
|
||||||
@@ -228,6 +236,4 @@ inline PICout operator <<(PICout s, const PIMathVector<Type> & v) {s << '{'; for
|
|||||||
typedef PIMathVector<int> PIMathVectori;
|
typedef PIMathVector<int> PIMathVectori;
|
||||||
typedef PIMathVector<double> PIMathVectord;
|
typedef PIMathVector<double> PIMathVectord;
|
||||||
|
|
||||||
//#include "pimathmatrix.h"
|
|
||||||
|
|
||||||
#endif // PIMATHVECTOR_H
|
#endif // PIMATHVECTOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user