From 1b32a8a0472df161d9d812decde48f4c6b76d70b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 4 Feb 2024 15:56:42 +0100 Subject: c --- src/global-coords.hpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/global-coords.hpp b/src/global-coords.hpp index 1f6c2def..03dfc67e 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -1,7 +1,6 @@ #pragma once #include "local-coords.hpp" #include "compat/assert.hpp" -#include #include #include #include @@ -39,33 +38,44 @@ struct chunk_coords_ final { constexpr chunk_coords_(chunk_coords c, int8_t z) noexcept : x{c.x}, y{c.y}, z{z} {} constexpr bool operator==(const chunk_coords_&) const noexcept = default; - template constexpr chunk_coords_ operator+(Math::Vector2 off) const noexcept { + template requires std::is_integral_v constexpr chunk_coords_ operator+(Math::Vector2 off) const noexcept + { return { int16_t(x + int{off.x()}), int16_t(y + int{off.y()}), z }; } - template constexpr chunk_coords_ operator-(Math::Vector2 off) const noexcept { + template requires std::is_integral_v constexpr chunk_coords_ operator-(Math::Vector2 off) const noexcept + { return { int16_t(x - int{off.x()}), int16_t(y - int{off.y()}), z }; } - template constexpr chunk_coords_& operator+=(Math::Vector2 off) noexcept { + template requires std::is_integral_v constexpr chunk_coords_& operator+=(Math::Vector2 off) noexcept + { x = int16_t(x + int{off.x()}); y = int16_t(y + int{off.y()}); return *this; } - template constexpr chunk_coords_& operator-=(Math::Vector2 off) noexcept { + template requires std::is_integral_v constexpr chunk_coords_& operator-=(Math::Vector2 off) noexcept + { x = int16_t(x - int{off.x()}); y = int16_t(y - int{off.y()}); return *this; } - template constexpr chunk_coords_ operator+(Math::Vector3 off) const noexcept { + template requires std::is_integral_v constexpr chunk_coords_ operator+(Math::Vector3 off) const noexcept + { return { int16_t(x + int{off.x()}), int16_t(y + int{off.y()}), int8_t(z + int{off.z()}) }; } - template constexpr chunk_coords_ operator-(Math::Vector3 off) const noexcept { + template requires std::is_integral_v constexpr chunk_coords_ operator-(Math::Vector3 off) const noexcept + { return { int16_t(x - int{off.x()}), int16_t(y - int{off.y()}), int8_t(z - int{off.z()}) }; } - template constexpr chunk_coords_& operator+=(Math::Vector3 off) noexcept { + template requires std::is_integral_v constexpr chunk_coords_& operator+=(Math::Vector3 off) noexcept + { x = int16_t(x + int{off.x()}); y = int16_t(y + int{off.y()}); z = int8_t(z + int{off.z()}); return *this; } - template constexpr chunk_coords_& operator-=(Math::Vector3 off) noexcept { + template requires std::is_integral_v constexpr chunk_coords_& operator-=(Math::Vector3 off) noexcept + { x = int16_t(x - int{off.x()}); y = int16_t(y - int{off.y()}); z = int8_t(z + int{off.z()}); return *this; } - constexpr Vector3i operator-(chunk_coords_ other) const noexcept { return Vector3i{x - other.x, y - other.y, z - other.z}; } + constexpr Vector3i operator-(chunk_coords_ other) const noexcept + { + return Vector3i{x - other.x, y - other.y, z - other.z}; + } explicit constexpr inline operator chunk_coords() const noexcept { return chunk_coords{x, y}; } -- cgit v1.2.3