fix PVector2D resize
This commit is contained in:
21
main.cpp
21
main.cpp
@@ -117,12 +117,19 @@ PIKbdListener kbd(0, 0, false);
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
//piCout << PISerial::availableDevicesInfo();
|
||||
PIIODevice * d = PIIODevice::createFromFullPath(argv[1]);
|
||||
piCout << d;
|
||||
if (d) {
|
||||
d->open();
|
||||
piCout << d->constructFullPath() << d->isOpened();
|
||||
}
|
||||
PIMathMatrixd m = PIMathMatrixd::identity(3,3);
|
||||
m*=33;
|
||||
piCout << m;
|
||||
PIMathMatrixd m2;
|
||||
m2 = m; m2.resize(3,5, 99);
|
||||
piCout << m2;
|
||||
m2 = m; m2.resize(5,3, 88);
|
||||
piCout << m2;
|
||||
m2 = m; m2.resize(4,9, 77);
|
||||
piCout << m2;
|
||||
m2 = m; m2.resize(2,2, 66);
|
||||
piCout << m2;
|
||||
m2 = m; m2.resize(2,8, 66);
|
||||
piCout << m2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -213,9 +213,24 @@ public:
|
||||
}
|
||||
|
||||
inline PIVector2D<T> & resize(size_t rows, size_t cols, const T & f = T()) {
|
||||
mat.resize(rows*cols_, f);
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
int cs = (cols - cols_);
|
||||
if (cs < 0) {
|
||||
for (size_t r=0; r<rows; ++r) {
|
||||
mat.remove(r*cols_ + cols_, -cs);
|
||||
}
|
||||
}
|
||||
mat.resize(rows*cols, f);
|
||||
if (!mat.isEmpty()) {
|
||||
if (cs > 0) {
|
||||
for (size_t r=0; r<rows_; ++r) {
|
||||
for (int i=0; i<cs; ++i)
|
||||
mat.insert(r*cols + cols_, mat.take_back());
|
||||
}
|
||||
}
|
||||
}
|
||||
cols_ = cols;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user