zeus/include/zeus/CVector2i.hpp
Lioncash 81f9b4a4ee General: Mark functions as nodiscard where applicable
Given this aims to be a general purpose math library for use in various
other libraries applications for axiodl, we can annotate functions that
return by value or reference with [[nodiscard]] where it's very obvious
that not making use of the return value is a bug.

This allows the compiler to diagnose and emit warnings for these API
misuses at compile-time, preventing silent bugs from occurring.

Any cases where not using the return value is desirable may still be
casted to void in order to silence warnings.
2020-03-04 03:07:54 -05:00

44 lines
1.4 KiB
C++

#pragma once
#include <cstdint>
#include "zeus/CVector2f.hpp"
namespace zeus {
class CVector2i {
public:
int32_t x = 0;
int32_t y = 0;
constexpr CVector2i() noexcept = default;
constexpr CVector2i(int32_t xin, int32_t yin) noexcept : x(xin), y(yin) {}
CVector2i(const CVector2f& vec) noexcept : x(int32_t(vec.x())), y(int32_t(vec.y())) {}
[[nodiscard]] constexpr CVector2f toVec2f() const noexcept { return CVector2f(float(x), float(y)); }
[[nodiscard]] constexpr CVector2i operator+(const CVector2i& val) const noexcept {
return CVector2i(x + val.x, y + val.y);
}
[[nodiscard]] constexpr CVector2i operator-(const CVector2i& val) const noexcept {
return CVector2i(x - val.x, y - val.y);
}
[[nodiscard]] constexpr CVector2i operator*(const CVector2i& val) const noexcept {
return CVector2i(x * val.x, y * val.y);
}
[[nodiscard]] constexpr CVector2i operator/(const CVector2i& val) const noexcept {
return CVector2i(x / val.x, y / val.y);
}
[[nodiscard]] constexpr bool operator==(const CVector2i& other) const noexcept {
return x == other.x && y == other.y;
}
[[nodiscard]] constexpr bool operator!=(const CVector2i& other) const noexcept { return !operator==(other); }
[[nodiscard]] constexpr CVector2i operator*(int32_t val) const noexcept { return CVector2i(x * val, y * val); }
};
static_assert(sizeof(CVector2i) == sizeof(int32_t) * 2);
} // namespace zeus