Support constructing a matrix by rows/columns
This commit is contained in:
parent
6eacee38f0
commit
639f8650d4
1 changed files with 24 additions and 0 deletions
|
|
@ -235,4 +235,28 @@ namespace psemek::geom
|
|||
return r;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N, typename ... Rows>
|
||||
auto by_rows(vector<T, N> const & v, Rows const & ... rows)
|
||||
{
|
||||
vector<T, N> m[] = {v, rows...};
|
||||
|
||||
matrix<T, sizeof...(Rows) + 1, N> result;
|
||||
for (std::size_t i = 0; i < result.rows; ++i)
|
||||
for (std::size_t j = 0; j < result.columns; ++j)
|
||||
result[i][j] = m[i][j];
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N, typename ... Columns>
|
||||
auto by_columns(vector<T, N> const & v, Columns const & ... columns)
|
||||
{
|
||||
vector<T, N> m[] = {v, columns...};
|
||||
|
||||
matrix<T, N, sizeof...(Columns) + 1> result;
|
||||
for (std::size_t i = 0; i < result.rows; ++i)
|
||||
for (std::size_t j = 0; j < result.columns; ++j)
|
||||
result[i][j] = m[j][i];
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue