From 917ee28ac254c9a944dabf194299e82930084dac Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Wed, 27 Jan 2021 01:02:03 +0100 Subject: [PATCH] Fix getters for negative numbers --- openVulkanoCpp/Math/DenseVector3i.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openVulkanoCpp/Math/DenseVector3i.hpp b/openVulkanoCpp/Math/DenseVector3i.hpp index df46dea..dc062f5 100644 --- a/openVulkanoCpp/Math/DenseVector3i.hpp +++ b/openVulkanoCpp/Math/DenseVector3i.hpp @@ -86,9 +86,9 @@ namespace openVulkanoCpp::Math constexpr T Data() const { return data; } - [[nodiscard]] constexpr int X() const { return static_cast(data & BITMASK); } - [[nodiscard]] constexpr int Y() const { return static_cast((data >> (2 * BITS)) & BITMASK); } - [[nodiscard]] constexpr int Z() const { return static_cast((data >> BITS) & BITMASK); } + [[nodiscard]] constexpr int X() const { int v = data & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } + [[nodiscard]] constexpr int Y() const { int v = (data >> (2 * BITS)) & BITMASK; if (v > MAX_VALUE_Y) v |= ~BITMASK; return reinterpret_cast(v); } + [[nodiscard]] constexpr int Z() const { int v = (data >> BITS) & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } void SetX(int x) {