From 134aac5725c64112e317f55b2a4f4a7db2d5cee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20T=2E=20Listwon?= Date: Wed, 9 Feb 2022 09:18:05 +0100 Subject: [PATCH] Fix Vector2 and Vector2i coord access via operator[] --- core/math/vector2.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/math/vector2.h b/core/math/vector2.h index b2a8795d9d0..b7b00e3b3ad 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -60,10 +60,10 @@ struct _NO_DISCARD_CLASS_ 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(real_t p_value) { @@ -276,19 +276,25 @@ struct _NO_DISCARD_CLASS_ Vector2i { }; union { - int x; - int width; - }; - union { - int y; - int height; + struct { + union { + int x; + int width; + }; + union { + int y; + int height; + }; + }; + + int coord[2]; }; _FORCE_INLINE_ int &operator[](int p_idx) { - return p_idx ? y : x; + return coord[p_idx]; } _FORCE_INLINE_ const int &operator[](int p_idx) const { - return p_idx ? y : x; + return coord[p_idx]; } Vector2i operator+(const Vector2i &p_v) const;