diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 4991002fd3..18d7984fe9 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -72,6 +72,13 @@ public: return _data[i][j]; } + void operator=(const Matrix &other) + { + if (this != &other) { + memcpy(_data, other._data, sizeof(_data)); + } + } + /** * Matrix Operations */ @@ -324,6 +331,17 @@ public: return res; } + template + void set(const Matrix &m, size_t x0, size_t y0) + { + Matrix &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); + } + } + } + void setZero() { memset(_data, 0, sizeof(_data)); diff --git a/test/attitude.cpp b/test/attitude.cpp index 59efa084a2..9117df155d 100644 --- a/test/attitude.cpp +++ b/test/attitude.cpp @@ -107,7 +107,7 @@ int main() if (yaw_expected < -180) yaw_expected += 360; if (yaw_expected > 180) yaw_expected -= 360; - printf("roll:%d pitch:%d yaw:%d\n", roll, pitch, yaw); + //printf("roll:%d pitch:%d yaw:%d\n", roll, pitch, yaw); Euler euler_expected( deg2rad*double(roll_expected), deg2rad*double(pitch), @@ -117,7 +117,7 @@ int main() deg2rad*double(pitch), deg2rad*double(yaw)); Dcm dcm_from_euler(euler); - dcm_from_euler.print(); + //dcm_from_euler.print(); Euler euler_out(dcm_from_euler); TEST(isEqual(rad2deg*euler_expected, rad2deg*euler_out)); diff --git a/test/slice.cpp b/test/slice.cpp index 1f0bf99819..36f13f504b 100644 --- a/test/slice.cpp +++ b/test/slice.cpp @@ -19,6 +19,23 @@ int main() Matrix B_check(data_check); Matrix B(A.slice<2, 3>(1, 0)); TEST(isEqual(B, B_check)); + + float data_2[4] = { + 11, 12, + 13, 14 + }; + + Matrix C(data_2); + A.set(C, 1, 1); + + float data_2_check[9] = { + 0, 2, 3, + 4, 11, 12, + 7, 13, 14 + }; + Matrix D(data_2_check); + TEST(isEqual(A, D)); + return 0; }