From 3f446a64c55a8ec5c302e69939d6331b68d00d3b Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 17 Feb 2022 06:33:50 -0600 Subject: [PATCH] [nostalgia/geo] Fix Vec2 test --- src/nostalgia/geo/vec.cpp | 6 ++---- src/nostalgia/geo/vec.hpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/nostalgia/geo/vec.cpp b/src/nostalgia/geo/vec.cpp index 95a500f3c..3e56261c5 100644 --- a/src/nostalgia/geo/vec.cpp +++ b/src/nostalgia/geo/vec.cpp @@ -8,11 +8,9 @@ namespace nostalgia::geo { -#ifndef OX_OS_BareMetal // doesn't compile in devKitPro for some reason static_assert([] { Vec2 v(1, 2); return v.x == 1 && v.y == 2 && v[0] == 1 && v[1] == 2 && v.size() == 2; -}); -#endif +}()); -} \ No newline at end of file +} diff --git a/src/nostalgia/geo/vec.hpp b/src/nostalgia/geo/vec.hpp index e79ea6987..0af815f1d 100644 --- a/src/nostalgia/geo/vec.hpp +++ b/src/nostalgia/geo/vec.hpp @@ -9,6 +9,7 @@ #endif #include +#include #include #include #include @@ -192,11 +193,35 @@ struct Vec { } constexpr auto &operator[](std::size_t i) noexcept { - return start()[i]; + if (std::is_constant_evaluated()) { + switch (i) { + case 0: + return x; + case 1: + return y; + default: + oxAssert(false, "Read past end of Vec2"); + return y; + } + } else { + return start()[i]; + } } constexpr const auto &operator[](std::size_t i) const noexcept { - return start()[i]; + if (std::is_constant_evaluated()) { + switch (i) { + case 0: + return x; + case 1: + return y; + default: + oxAssert(false, "Read past end of Vec2"); + return y; + } + } else { + return start()[i]; + } } constexpr auto operator==(const Vec &v) const noexcept {