diff --git a/src/Quaternion.h b/src/Quaternion.h index 5b53052fbb2..adf8ddc45b4 100644 --- a/src/Quaternion.h +++ b/src/Quaternion.h @@ -61,6 +61,15 @@ class Quaternion { axis.z = z / s; } } + bool operator==(const Quaternion &a) const + { + return is_equal_exact(a.w, w) && is_equal_exact(a.x, x) && is_equal_exact(a.y, y) && is_equal_exact(a.z, z); + } + bool ExactlyEqual(const Quaternion &a) const + { + return is_equal_exact(a.w, w) && is_equal_exact(a.x, x) && is_equal_exact(a.y, y) && is_equal_exact(a.z, z); + } + // conjugate (inverse) friend Quaternion operator~(const Quaternion &a) { @@ -234,9 +243,17 @@ class Quaternion { }; template <> -inline Quaternion::Quaternion() {} +inline Quaternion::Quaternion() : + w(1.f), + x(0.f), + y(0.f), + z(0.f) {} template <> -inline Quaternion::Quaternion() {} +inline Quaternion::Quaternion() : + w(1.), + x(0.), + y(0.), + z(0.) {} template <> inline Quaternion::Quaternion(float w_, float x_, float y_, float z_) : w(w_), diff --git a/src/vector2.h b/src/vector2.h index 0caf80ee32e..21e9afa7e9f 100644 --- a/src/vector2.h +++ b/src/vector2.h @@ -111,9 +111,13 @@ class vector2 { }; template <> -inline vector2::vector2() {} +inline vector2::vector2() : + x(0.f), + y(0.f) {} template <> -inline vector2::vector2() {} +inline vector2::vector2() : + x(0.), + y(0.) {} template <> inline vector2::vector2(const vector2 &v) : x(float(v.x)), diff --git a/src/vector3.h b/src/vector3.h index fd91f3301ad..444c641bc46 100644 --- a/src/vector3.h +++ b/src/vector3.h @@ -10,10 +10,10 @@ #include // Need this pragma due to operator[] implementation. -// #pragma pack(4) +#pragma pack(4) template -class vector3 { +class alignas(sizeof(T)) vector3 { public: T x, y, z; @@ -280,9 +280,18 @@ inline vector3::vector3(const double vals[3]) : z(vals[2]) {} -// #pragma pack() +#pragma pack() typedef vector3 vector3f; typedef vector3 vector3d; +// ensure both packing and structure alignment match the constraints we have set +static_assert(alignof(vector3d) == 8); +static_assert(offsetof(vector3d, y) == 8); +static_assert(offsetof(vector3d, z) == 16); + +static_assert(alignof(vector3f) == 4); +static_assert(offsetof(vector3f, y) == 4); +static_assert(offsetof(vector3f, z) == 8); + #endif /* _VECTOR3_H */