Fix resize behavior w/r to semi static container

See merge request oss/rotgen!32
This commit is contained in:
Joel Falcou 2025-09-29 21:05:43 +02:00
parent a3aa130563
commit 7d65a05f72
5 changed files with 35 additions and 50 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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);
}