AP_Math: make vectors and matrix constructors constexpr

That allows some object to be constructed at compile time.
This commit is contained in:
Gustavo Jose de Sousa 2016-04-22 09:59:24 -03:00 committed by Lucas De Marchi
parent 77223a7fcb
commit 3b05ec1157
3 changed files with 25 additions and 16 deletions

View File

@ -50,16 +50,21 @@ public:
// trivial ctor
// note that the Vector3 ctor will zero the vector elements
Matrix3<T>() {
}
constexpr Matrix3<T>() {}
// setting ctor
Matrix3<T>(const Vector3<T> &a0, const Vector3<T> &b0, const Vector3<T> &c0) : a(a0), b(b0), c(c0) {
}
constexpr Matrix3<T>(const Vector3<T> &a0, const Vector3<T> &b0, const Vector3<T> &c0)
: a(a0)
, b(b0)
, c(c0) {}
// setting ctor
Matrix3<T>(const T ax, const T ay, const T az, const T bx, const T by, const T bz, const T cx, const T cy, const T cz) : a(ax,ay,az), b(bx,by,bz), c(cx,cy,cz) {
}
constexpr Matrix3<T>(const T ax, const T ay, const T az,
const T bx, const T by, const T bz,
const T cx, const T cy, const T cz)
: a(ax,ay,az)
, b(bx,by,bz)
, c(cx,cy,cz) {}
// function call operator
void operator () (const Vector3<T> &a0, const Vector3<T> &b0, const Vector3<T> &c0)

View File

@ -38,13 +38,14 @@ struct Vector2
T x, y;
// trivial ctor
Vector2<T>() {
x = y = 0;
}
constexpr Vector2<T>()
: x(0)
, y(0) {}
// setting ctor
Vector2<T>(const T x0, const T y0) : x(x0), y(y0) {
}
constexpr Vector2<T>(const T x0, const T y0)
: x(x0)
, y(y0) {}
// function call operator
void operator ()(const T x0, const T y0)

View File

@ -68,13 +68,16 @@ public:
T x, y, z;
// trivial ctor
Vector3<T>() {
x = y = z = 0;
}
constexpr Vector3<T>()
: x(0)
, y(0)
, z(0) {}
// setting ctor
Vector3<T>(const T x0, const T y0, const T z0) : x(x0), y(y0), z(z0) {
}
constexpr Vector3<T>(const T x0, const T y0, const T z0)
: x(x0)
, y(y0)
, z(z0) {}
// function call operator
void operator ()(const T x0, const T y0, const T z0)