Fix resize behavior w/r to semi static container
See merge request oss/rotgen!32
This commit is contained in:
commit
d005d5513b
5 changed files with 35 additions and 50 deletions
|
|
@ -111,26 +111,30 @@ namespace rotgen
|
|||
decltype(auto) noalias() const { return *this; }
|
||||
decltype(auto) noalias() { return *this; }
|
||||
|
||||
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||
void resize(int r, int c)
|
||||
{
|
||||
parent::resize(new_rows, new_cols);
|
||||
if constexpr(Rows == 1) assert(c == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(r == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::resize(r, c);
|
||||
}
|
||||
|
||||
void resize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||
void resize(int s) requires(IsVectorAtCompileTime)
|
||||
{
|
||||
if constexpr(Rows == -1) parent::resize(new_size,1);
|
||||
else parent::resize(1,new_size);
|
||||
if constexpr(Rows == 1) parent::resize(1,s);
|
||||
else parent::resize(s,1);
|
||||
}
|
||||
|
||||
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||
void conservativeResize(int r, int c)
|
||||
{
|
||||
parent::conservativeResize(new_rows, new_cols);
|
||||
if constexpr(Rows == 1) assert(c == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(r == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::conservativeResize(r, c);
|
||||
}
|
||||
|
||||
void conservativeResize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||
void conservativeResize(int s) requires(IsVectorAtCompileTime)
|
||||
{
|
||||
if constexpr(Rows == -1) parent::conservativeResize(new_size,1);
|
||||
else parent::conservativeResize(1,new_size);
|
||||
if constexpr(Rows == 1) parent::conservativeResize(1,s);
|
||||
else parent::conservativeResize(s,1);
|
||||
}
|
||||
|
||||
matrix normalized() const requires(IsVectorAtCompileTime)
|
||||
|
|
|
|||
|
|
@ -215,24 +215,32 @@ namespace rotgen
|
|||
else return base().cwiseSqrt();
|
||||
}
|
||||
|
||||
void resize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||
void resize(int s) requires(IsVectorAtCompileTime)
|
||||
{
|
||||
parent::resize(new_size);
|
||||
if constexpr(Rows == 1) assert(s == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(s == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::resize(s);
|
||||
}
|
||||
|
||||
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||
void resize(int r, int c)
|
||||
{
|
||||
parent::resize(new_rows, new_cols);
|
||||
if constexpr(Rows == 1) assert(c == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(r == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::resize(r, c);
|
||||
}
|
||||
|
||||
void conservativeResize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||
void conservativeResize(int s) requires(IsVectorAtCompileTime)
|
||||
{
|
||||
parent::conservativeResize(new_size);
|
||||
if constexpr(Rows == 1) assert(s == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(s == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::conservativeResize(s);
|
||||
}
|
||||
|
||||
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||
void conservativeResize(int r, int c)
|
||||
{
|
||||
parent::conservativeResize(new_rows, new_cols);
|
||||
if constexpr(Rows == 1) assert(c == Cols && "Mismatched between dynamic and static col size");
|
||||
if constexpr(Cols == 1) assert(r == Rows && "Mismatched between dynamic and static row size");
|
||||
parent::conservativeResize(r, c);
|
||||
}
|
||||
|
||||
static matrix Constant(Scalar value) requires (Rows != -1 && Cols != -1)
|
||||
|
|
|
|||
|
|
@ -18,24 +18,15 @@ namespace rotgen
|
|||
std::size_t cols(auto const& m) requires(requires{ m.cols(); }){ return m.cols(); }
|
||||
std::size_t size(auto const& m) requires(requires{ m.size(); }){ return m.size(); }
|
||||
|
||||
void resize(auto& a, int sz) requires requires{a.resize(sz);} { a.resize(sz); }
|
||||
void resize(auto& a, int s) requires requires{a.resize(s);} { a.resize(s); }
|
||||
void resize(auto& a, int r, int c) requires requires{a.resize(r,c);} { a.resize(r,c); }
|
||||
|
||||
template<typename E>
|
||||
void resize(E& a, int r, int c)
|
||||
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
||||
void conservativeResize(auto& a, int s) requires requires{a.conservativeResize(s);}
|
||||
{
|
||||
a.resize(r, c);
|
||||
a.conservativeResize(s);
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
void conservativeResize(E& a, int sz) requires requires{a.conservativeResize(sz);}
|
||||
{
|
||||
a.conservativeResize(sz);
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
void conservativeResize(E& a, int r, int c)
|
||||
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
||||
void conservativeResize(auto& a, int r, int c) requires requires{a.conservativeResize(r,c);}
|
||||
{
|
||||
a.conservativeResize(r, c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,4 @@ TTS_CASE("Matrix size-related operations")
|
|||
std::pair{1, 2}, std::pair{11, 17}, std::pair{4, 5},
|
||||
std::pair{9, 1}, std::pair{3, 8}, std::pair{22, 0},
|
||||
});
|
||||
|
||||
rotgen::matrix<double, 3, 3> a;
|
||||
TTS_EXPECT_NOT_COMPILES(a, { rotgen::resize(a, 4, 5); });
|
||||
TTS_EXPECT_NOT_COMPILES(a, { rotgen::conservativeResize(a, 4, 5); });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,13 +44,6 @@ TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
|
|||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Resizing static matrix", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<double, 3, 3> a;
|
||||
TTS_EXPECT_NOT_COMPILES(a, { a.resize(4, 5); });
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
|
|
@ -105,13 +98,6 @@ TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
|
|||
TTS_EQUAL(a.cols(), rotgen::Index(3));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Static matrix conservative resizing", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<double, 3, 3> a;
|
||||
TTS_EXPECT_NOT_COMPILES(a, { a.conservativeResize(4, 5); });
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue