mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
Bug 1276066 - Add Union with "components" member to math classes to enable array access to members. r=bas
- Adding an array member to access the components of vector, size, and matrix classes reduces the code needed when passing all of the members to functions. MozReview-Commit-ID: A6XL7y3zwsV --HG-- extra : rebase_source : 77fb1b9784ae1213530cff7f42563e0afc8859e3
This commit is contained in:
parent
24362dc743
commit
b25f2d6a84
@ -22,7 +22,12 @@ namespace gfx {
|
||||
*/
|
||||
template <class T, class Sub, class Coord = T>
|
||||
struct BasePoint {
|
||||
T x, y;
|
||||
union {
|
||||
struct {
|
||||
T x, y;
|
||||
};
|
||||
T components[2];
|
||||
};
|
||||
|
||||
// Constructors
|
||||
MOZ_CONSTEXPR BasePoint() : x(0), y(0) {}
|
||||
|
@ -18,7 +18,12 @@ namespace gfx {
|
||||
*/
|
||||
template <class T, class Sub>
|
||||
struct BasePoint3D {
|
||||
T x, y, z;
|
||||
union {
|
||||
struct {
|
||||
T x, y, z;
|
||||
};
|
||||
T components[3];
|
||||
};
|
||||
|
||||
// Constructors
|
||||
BasePoint3D() : x(0), y(0), z(0) {}
|
||||
|
@ -18,7 +18,12 @@ namespace gfx {
|
||||
*/
|
||||
template <class T, class Sub>
|
||||
struct BasePoint4D {
|
||||
T x, y, z, w;
|
||||
union {
|
||||
struct {
|
||||
T x, y, z, w;
|
||||
};
|
||||
T components[4];
|
||||
};
|
||||
|
||||
// Constructors
|
||||
BasePoint4D() : x(0), y(0), z(0), w(0) {}
|
||||
|
@ -18,7 +18,12 @@ namespace gfx {
|
||||
*/
|
||||
template <class T, class Sub>
|
||||
struct BaseSize {
|
||||
T width, height;
|
||||
union {
|
||||
struct {
|
||||
T width, height;
|
||||
};
|
||||
T components[2];
|
||||
};
|
||||
|
||||
// Constructors
|
||||
MOZ_CONSTEXPR BaseSize() : width(0), height(0) {}
|
||||
|
@ -37,9 +37,14 @@ public:
|
||||
, _21(a21), _22(a22)
|
||||
, _31(a31), _32(a32)
|
||||
{}
|
||||
Float _11, _12;
|
||||
Float _21, _22;
|
||||
Float _31, _32;
|
||||
union {
|
||||
struct {
|
||||
Float _11, _12;
|
||||
Float _21, _22;
|
||||
Float _31, _32;
|
||||
};
|
||||
Float components[6];
|
||||
};
|
||||
|
||||
MOZ_ALWAYS_INLINE Matrix Copy() const
|
||||
{
|
||||
@ -461,10 +466,15 @@ public:
|
||||
memcpy(this, &aOther, sizeof(*this));
|
||||
}
|
||||
|
||||
Float _11, _12, _13, _14;
|
||||
Float _21, _22, _23, _24;
|
||||
Float _31, _32, _33, _34;
|
||||
Float _41, _42, _43, _44;
|
||||
union {
|
||||
struct {
|
||||
Float _11, _12, _13, _14;
|
||||
Float _21, _22, _23, _24;
|
||||
Float _31, _32, _33, _34;
|
||||
Float _41, _42, _43, _44;
|
||||
};
|
||||
Float components[16];
|
||||
};
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& aStream, const Matrix4x4Typed& aMatrix)
|
||||
{
|
||||
@ -1618,11 +1628,16 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
Float _11, _12, _13, _14;
|
||||
Float _21, _22, _23, _24;
|
||||
Float _31, _32, _33, _34;
|
||||
Float _41, _42, _43, _44;
|
||||
Float _51, _52, _53, _54;
|
||||
union {
|
||||
struct {
|
||||
Float _11, _12, _13, _14;
|
||||
Float _21, _22, _23, _24;
|
||||
Float _31, _32, _33, _34;
|
||||
Float _41, _42, _43, _44;
|
||||
Float _51, _52, _53, _54;
|
||||
};
|
||||
Float components[20];
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
Loading…
x
Reference in New Issue
Block a user