mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 19:13:35 +08:00
More features: longerThan, norm, copyTo and slice on a Slice (#97)
* Allow slices of slices, add longerThan to Vector/Slice
This commit is contained in:
@@ -52,6 +52,20 @@ int main()
|
||||
TEST(fabs(array_A[i] - array_column[i]) < eps);
|
||||
}
|
||||
|
||||
// Slice copyTo
|
||||
float dst5[2] = {};
|
||||
v.slice<2,1>(0,0).copyTo(dst5);
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
TEST(fabs(v(i) - dst5[i]) < eps);
|
||||
}
|
||||
|
||||
float subarray_A[4] = {};
|
||||
A.slice<2,2>(0,0).copyToColumnMajor(subarray_A);
|
||||
float subarray_column[4] = {1,4,2,5};
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
TEST(fabs(subarray_A[i] - subarray_column[i]) < eps);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
template class matrix::Matrix<float, 3, 2>;
|
||||
|
||||
int main()
|
||||
{
|
||||
Matrix3f m;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
template class matrix::Slice<float, 2, 3, 4, 5>; // so that we get full coverage results
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
float data[9] = {0, 2, 3,
|
||||
@@ -97,6 +100,31 @@ int main()
|
||||
Matrix<float, 1, 5> K_check(data_4_check);
|
||||
TEST(isEqual(K, K_check));
|
||||
}
|
||||
|
||||
// check that slice of a slice works for reading
|
||||
const Matrix<float, 3, 3> cm33(data);
|
||||
Matrix<float, 2, 1> topRight = cm33.slice<2,3>(0,0).slice<2,1>(0,2);
|
||||
float top_right_check[2] = {3,6};
|
||||
TEST(isEqual(topRight, Matrix<float, 2, 1>(top_right_check)));
|
||||
|
||||
// check that slice of a slice works for writing
|
||||
Matrix<float, 3, 3> m33(data);
|
||||
m33.slice<2,3>(0,0).slice<2,1>(0,2) = Matrix<float, 2, 1>();
|
||||
const float data_check[9] = {0, 2, 0,
|
||||
4, 5, 0,
|
||||
7, 8, 10
|
||||
};
|
||||
TEST(isEqual(m33, Matrix<float, 3, 3>(data_check)));
|
||||
|
||||
// longerThan
|
||||
Vector3f v5;
|
||||
v5(0) = 3;
|
||||
v5(1) = 4;
|
||||
v5(2) = 9;
|
||||
TEST(v5.xy().longerThan(4.99f));
|
||||
TEST(!v5.xy().longerThan(5.f));
|
||||
TEST(isEqualF(5.f, v5.xy().norm()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ int main()
|
||||
Vector<float, 5> v4(data1_sq);
|
||||
TEST(isEqual(v1, v4.sqrt()));
|
||||
|
||||
// longerThan
|
||||
Vector<float, 2> v5;
|
||||
v5(0) = 3;
|
||||
v5(1) = 4;
|
||||
TEST(v5.longerThan(4.99f));
|
||||
TEST(!v5.longerThan(5.f));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user