From 3971db78c07230fe1afbb027c8df393f68b19b25 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Feb 2020 14:14:02 -0800 Subject: MathLib: added data() method to math objects --- Common/interface/BasicMath.hpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/BasicMath.hpp b/Common/interface/BasicMath.hpp index afc48ceb..9f748c78 100644 --- a/Common/interface/BasicMath.hpp +++ b/Common/interface/BasicMath.hpp @@ -211,14 +211,18 @@ template struct Vector2 y >= right.y ? static_cast(1) : static_cast(0)); } + T* data() { return reinterpret_cast(this); } + + const T* data() const { return reinterpret_cast(this); } + T& operator[](size_t index) { - return reinterpret_cast(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast(this)[index]; + return data()[index]; } Vector2() : @@ -409,14 +413,18 @@ template struct Vector3 z >= right.z ? static_cast(1) : static_cast(0)); } + T* data() { return reinterpret_cast(this); } + + const T* data() const { return reinterpret_cast(this); } + T& operator[](size_t index) { - return reinterpret_cast(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast(this)[index]; + return data()[index]; } Vector3() : @@ -621,14 +629,18 @@ template struct Vector4 w >= right.w ? static_cast(1) : static_cast(0)); } + T* data() { return reinterpret_cast(this); } + + const T* data() const { return reinterpret_cast(this); } + T& operator[](size_t index) { - return reinterpret_cast(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast(this)[index]; + return data()[index]; } Vector4() : @@ -744,6 +756,11 @@ template struct Matrix2x2 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + + Matrix2x2& operator*=(T s) { for (int i = 0; i < 4; ++i) @@ -906,6 +923,10 @@ template struct Matrix3x3 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + Matrix3x3& operator*=(T s) { for (int i = 0; i < 9; ++i) @@ -1096,6 +1117,10 @@ template struct Matrix4x4 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + Matrix4x4& operator*=(T s) { for (int i = 0; i < 16; ++i) -- cgit v1.2.3