mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
Vector2: add explicit constructor for Vector3
Initialize from the first 2 elements.
This commit is contained in:
@@ -22,6 +22,7 @@ class Vector2 : public Vector<Type, 2>
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef Matrix<Type, 2, 1> Matrix21;
|
typedef Matrix<Type, 2, 1> Matrix21;
|
||||||
|
typedef Vector<Type, 3> Vector3;
|
||||||
|
|
||||||
Vector2() = default;
|
Vector2() = default;
|
||||||
|
|
||||||
@@ -42,6 +43,13 @@ public:
|
|||||||
v(1) = y;
|
v(1) = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
explicit Vector2(const Vector3 & other)
|
||||||
|
{
|
||||||
|
Vector2 &v(*this);
|
||||||
|
v(0) = other(0);
|
||||||
|
v(1) = other(1);
|
||||||
|
}
|
||||||
|
|
||||||
Type cross(const Matrix21 & b) const {
|
Type cross(const Matrix21 & b) const {
|
||||||
const Vector2 &a(*this);
|
const Vector2 &a(*this);
|
||||||
return a(0)*b(1, 0) - a(1)*b(0, 0);
|
return a(0)*b(1, 0) - a(1)*b(0, 0);
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ int main()
|
|||||||
TEST(fabs(f(0) - 4) < 1e-5);
|
TEST(fabs(f(0) - 4) < 1e-5);
|
||||||
TEST(fabs(f(1) - 5) < 1e-5);
|
TEST(fabs(f(1) - 5) < 1e-5);
|
||||||
|
|
||||||
|
Vector3f g(1.23f, 423.4f, 3221.f);
|
||||||
|
Vector2f h(g);
|
||||||
|
TEST(fabs(h(0) - 1.23f) < 1e-5);
|
||||||
|
TEST(fabs(h(1) - 423.4f) < 1e-5);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user