PX4 Firmware
PX4 Autopilot Software http://px4.io
vector.cpp
Go to the documentation of this file.
1 #include "test_macros.hpp"
2 
3 #include <matrix/math.hpp>
4 
5 using namespace matrix;
6 
7 int main()
8 {
9  // test data
10  float data1[] = {1,2,3,4,5};
11  float data2[] = {6,7,8,9,10};
12  Vector<float, 5> v1(data1);
13  Vector<float, 5> v2(data2);
14 
15  // copy constructor
16  Vector<float, 5> v3(v2);
17  TEST(isEqual(v2, v3));
18 
19  // norm, dot product
20  TEST(isEqualF(v1.norm(), 7.416198487095663f));
21  TEST(isEqualF(v1.norm_squared(), v1.norm() * v1.norm()));
22  TEST(isEqualF(v1.norm(), v1.length()));
23  TEST(isEqualF(v1.dot(v2), 130.0f));
24  TEST(isEqualF(v1.dot(v2), v1 * v2));
25 
26  // unit, unit_zero, normalize
27  TEST(isEqualF(v2.unit().norm(), 1.f));
28  TEST(isEqualF(v2.unit_or_zero().norm(), 1.f));
29  TEST(isEqualF(Vector<float, 5>().unit_or_zero().norm(), 0.f));
30  v2.normalize();
31  TEST(isEqualF(v2.norm(), 1.f));
32 
33  // sqrt
34  float data1_sq[] = {1,4,9,16,25};
35  Vector<float, 5> v4(data1_sq);
36  TEST(isEqual(v1, v4.sqrt()));
37 
38  // longerThan
40  v5(0) = 3;
41  v5(1) = 4;
42  TEST(v5.longerThan(4.99f));
43  TEST(!v5.longerThan(5.f));
44 
45  return 0;
46 }
47 
48 /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
void normalize()
Definition: Vector.hpp:87
Type norm_squared() const
Definition: Vector.hpp:78
bool isEqual(const Matrix< Type, M, N > &x, const Matrix< Type, M, N > &y, const Type eps=1e-4f)
Definition: Matrix.hpp:571
Type dot(const MatrixM1 &b) const
Definition: Vector.hpp:55
Vector unit() const
Definition: Vector.hpp:91
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8
Type length() const
Definition: Vector.hpp:83
bool longerThan(Type testVal) const
Definition: Vector.hpp:107
#define TEST(X)
Definition: test_macros.hpp:14
int main()
Definition: vector.cpp:7
bool isEqualF(const Type x, const Type y, const Type eps=1e-4f)
Compare if two floating point numbers are equal.
Type norm() const
Definition: Vector.hpp:73
Vector unit_or_zero(const Type eps=Type(1e-5)) const
Definition: Vector.hpp:95
Vector sqrt() const
Definition: Vector.hpp:111