mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 06:53:34 +08:00
Add support for Slice to Matrix, SquareMatrix, Vector
This commit is contained in:
+21
-17
@@ -24,6 +24,12 @@ namespace matrix
|
||||
template <typename Type, size_t M>
|
||||
class Vector;
|
||||
|
||||
template<typename Type, size_t M, size_t N>
|
||||
class Matrix;
|
||||
|
||||
template <typename Type, size_t P, size_t Q, size_t M, size_t N>
|
||||
class Slice;
|
||||
|
||||
template<typename Type, size_t M, size_t N>
|
||||
class Matrix
|
||||
{
|
||||
@@ -50,6 +56,17 @@ public:
|
||||
memcpy(_data, other._data, sizeof(_data));
|
||||
}
|
||||
|
||||
template<size_t P, size_t Q>
|
||||
Matrix(const Slice<Type, M, N, P, Q>& in_slice)
|
||||
{
|
||||
Matrix<Type, M, N>& self = *this;
|
||||
for (size_t i = 0; i < M; i++) {
|
||||
for (size_t j = 0; j < N; j++) {
|
||||
self(i, j) = in_slice(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessors/ Assignment etc.
|
||||
*/
|
||||
@@ -353,27 +370,15 @@ public:
|
||||
}
|
||||
|
||||
template<size_t P, size_t Q>
|
||||
Matrix<Type, P, Q> slice(size_t x0, size_t y0) const
|
||||
const Slice<Type, P, Q, M, N> slice(size_t x0, size_t y0) const
|
||||
{
|
||||
const Matrix<Type, M, N> &self = *this;
|
||||
Matrix<Type, P, Q> res; //default constructed
|
||||
for (size_t i = 0; i < P; i++) {
|
||||
for (size_t j = 0; j < Q; j++) {
|
||||
res(i, j) = self(i + x0, j + y0);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return Slice<Type, P, Q, M, N>(x0, y0, this);
|
||||
}
|
||||
|
||||
template<size_t P, size_t Q>
|
||||
void set(const Matrix<Type, P, Q> &m, size_t x0, size_t y0)
|
||||
Slice<Type, P, Q, M, N> slice(size_t x0, size_t y0)
|
||||
{
|
||||
Matrix<Type, M, N> &self = *this;
|
||||
for (size_t i = 0; i < P; i++) {
|
||||
for (size_t j = 0; j < Q; j++) {
|
||||
self(i + x0, j + y0) = m(i, j);
|
||||
}
|
||||
}
|
||||
return Slice<Type, P, Q, M, N>(x0, y0, this);
|
||||
}
|
||||
|
||||
void setRow(size_t i, const Matrix<Type, N, 1> &row)
|
||||
@@ -517,7 +522,6 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename Type, size_t M, size_t N>
|
||||
|
||||
Reference in New Issue
Block a user