diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-02-09 13:25:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 13:25:18 +0100 |
commit | 85610588d189e220799ca00237ebe4f00efcd445 (patch) | |
tree | c18ece2f42a2e0eafbd1250150298da2c30426e9 | |
parent | f88a83f6113ac8c7788fda163b831f2f8dabb96b (diff) | |
parent | 51cac0709e9c053b0785fc11cd26cb9cc83c01ae (diff) |
Merge pull request #57843 from Pineapple/vector2-brackets-operator-master
-rw-r--r-- | core/math/vector2.h | 4 | ||||
-rw-r--r-- | core/math/vector2i.h | 22 |
2 files changed, 16 insertions, 10 deletions
diff --git a/core/math/vector2.h b/core/math/vector2.h index 123e3dc7b6..92ac5257b0 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -60,10 +60,10 @@ struct _NO_DISCARD_ Vector2 { }; _FORCE_INLINE_ real_t &operator[](int p_idx) { - return p_idx ? y : x; + return coord[p_idx]; } _FORCE_INLINE_ const real_t &operator[](int p_idx) const { - return p_idx ? y : x; + return coord[p_idx]; } _FORCE_INLINE_ void set_all(const real_t p_value) { diff --git a/core/math/vector2i.h b/core/math/vector2i.h index 707c8c9490..3f5f12d4dd 100644 --- a/core/math/vector2i.h +++ b/core/math/vector2i.h @@ -43,19 +43,25 @@ struct _NO_DISCARD_ Vector2i { }; union { - int32_t x = 0; - int32_t width; - }; - union { - int32_t y = 0; - int32_t height; + struct { + union { + int32_t x; + int32_t width; + }; + union { + int32_t y; + int32_t height; + }; + }; + + int32_t coord[2] = { 0 }; }; _FORCE_INLINE_ int32_t &operator[](int p_idx) { - return p_idx ? y : x; + return coord[p_idx]; } _FORCE_INLINE_ const int32_t &operator[](int p_idx) const { - return p_idx ? y : x; + return coord[p_idx]; } _FORCE_INLINE_ Vector2i::Axis min_axis_index() const { |