From 6c98600fe769e93a0dc6250ba6805371293ec6ef Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 28 May 2020 10:15:05 +0300 Subject: [PATCH] PIVector2D resize --- CMakeLists.txt | 4 ++-- src_main/containers/pivector2d.h | 7 +++++++ src_main/math/pimathmatrix.h | 9 ++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdba57ad..70e3fcd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(_PIP_MAJOR 1) -set(_PIP_MINOR 14) +set(_PIP_MINOR 16) set(_PIP_REVISION 0) -set(_PIP_SUFFIX beta) +set(_PIP_SUFFIX alpha) set(_PIP_COMPANY SHS) set(_PIP_DOMAIN org.SHS) diff --git a/src_main/containers/pivector2d.h b/src_main/containers/pivector2d.h index fdf673aa..50119326 100644 --- a/src_main/containers/pivector2d.h +++ b/src_main/containers/pivector2d.h @@ -212,6 +212,13 @@ public: return *this; } + inline PIVector2D & resize(size_t rows, size_t cols, const T & f = T()) { + rows_ = rows; + cols_ = cols; + mat.resize(rows*cols, f); + return *this; + } + PIVector > toVectors() const { PIVector > ret; for(size_t i = 0; i < rows_; ++i) diff --git a/src_main/math/pimathmatrix.h b/src_main/math/pimathmatrix.h index 466db6d0..5ff9de26 100644 --- a/src_main/math/pimathmatrix.h +++ b/src_main/math/pimathmatrix.h @@ -328,10 +328,10 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - PIMathMatrix(const uint cols = 0, const uint rows = 0) {resize(cols, rows);} - PIMathMatrix(const uint cols, const uint rows, const PIVector & val) {resize(cols, rows); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} - PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {resize(val[0].size(), val.size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} - PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {resize(val.cols(), val.rows()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + PIMathMatrix(const uint cols = 0, const uint rows = 0) {_V2D::resize(cols, rows);} + PIMathMatrix(const uint cols, const uint rows, const PIVector & val) {_V2D::resize(cols, rows); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} + PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val[0].size(), val.size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} + PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.cols(), val.rows()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); for (uint r = 0; r < rows; ++r) for (uint c = 0; c < cols; ++c) tm.element(r, c) = (c == r ? Type(1) : Type(0)); return tm;} static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} @@ -339,7 +339,6 @@ public: _CMatrix & setCol(uint index, const _CMCol & v) {PIMM_FOR_R(i) _V2D::element(i, index) = v[i]; return *this;} _CMatrix & setRow(uint index, const _CMCol & v) {PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this;} - _CMatrix & resize(const uint cols, const uint rows, const Type & new_value = Type()) {_V2D::_resizeRaw(rows, cols); PIMM_FOR_A(i) _V2D::mat[i] = new_value; return *this;} _CMatrix & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} return *this;} _CMatrix & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} return *this;} _CMatrix & fill(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] = v; return *this;}