From 5f892dda81e3901dec839ce7ea8fef837a098156 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 4 Sep 2019 02:41:25 -0400 Subject: [PATCH] CVector2i: Remove use of union and unnamed struct Nothing uses the v data array, so we can remove it entirely. This removes the use of a compiler extension (anonymous struct), and simplifies the underlying data within the vector. --- include/zeus/CVector2i.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/include/zeus/CVector2i.hpp b/include/zeus/CVector2i.hpp index ecb8354..99fac02 100644 --- a/include/zeus/CVector2i.hpp +++ b/include/zeus/CVector2i.hpp @@ -1,23 +1,20 @@ #pragma once +#include #include "zeus/CVector2f.hpp" namespace zeus { class CVector2i { public: - union { - struct { - int x, y; - }; - int v[2]; - }; + int32_t x = 0; + int32_t y = 0; - constexpr CVector2i() : x(0), y(0) {} + constexpr CVector2i() = default; - constexpr CVector2i(int xin, int yin) : x(xin), y(yin) {} + constexpr CVector2i(int32_t xin, int32_t yin) : x(xin), y(yin) {} - CVector2i(const CVector2f& vec) : x(int(vec.x())), y(int(vec.y())) {} + CVector2i(const CVector2f& vec) : x(int32_t(vec.x())), y(int32_t(vec.y())) {} CVector2f toVec2f() const { return CVector2f(x, y); } @@ -33,6 +30,6 @@ public: bool operator!=(const CVector2i& other) const { return x != other.x || y != other.y; } - CVector2i operator*(int val) const { return CVector2i(x * val, y * val); } + CVector2i operator*(int32_t val) const { return CVector2i(x * val, y * val); } }; } // namespace zeus