Merge pull request #14 from lioncash/vec

CVector2i: Make interface constexpr where applicable
This commit is contained in:
Phillip Stephens 2019-09-04 01:03:42 -07:00 committed by GitHub
commit 2206497e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 21 deletions

View File

@ -1,38 +1,33 @@
#pragma once
#include <cstdint>
#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() noexcept = default;
constexpr CVector2i(int xin, int yin) : x(xin), y(yin) {}
constexpr CVector2i(int32_t xin, int32_t yin) noexcept : x(xin), y(yin) {}
CVector2i(const CVector2f& vec) : x(int(vec.x())), y(int(vec.y())) {}
constexpr CVector2i(const CVector2f& vec) noexcept : x(int32_t(vec.x())), y(int32_t(vec.y())) {}
CVector2f toVec2f() const { return CVector2f(x, y); }
constexpr CVector2f toVec2f() const noexcept { return CVector2f(float(x), float(y)); }
CVector2i operator+(const CVector2i& val) const { return CVector2i(x + val.x, y + val.y); }
constexpr CVector2i operator+(const CVector2i& val) const noexcept { return CVector2i(x + val.x, y + val.y); }
constexpr CVector2i operator-(const CVector2i& val) const noexcept { return CVector2i(x - val.x, y - val.y); }
constexpr CVector2i operator*(const CVector2i& val) const noexcept { return CVector2i(x * val.x, y * val.y); }
constexpr CVector2i operator/(const CVector2i& val) const noexcept { return CVector2i(x / val.x, y / val.y); }
CVector2i operator-(const CVector2i& val) const { return CVector2i(x - val.x, y - val.y); }
constexpr bool operator==(const CVector2i& other) const noexcept { return x == other.x && y == other.y; }
constexpr bool operator!=(const CVector2i& other) const noexcept { return !operator==(other); }
CVector2i operator*(const CVector2i& val) const { return CVector2i(x * val.x, y * val.y); }
CVector2i operator/(const CVector2i& val) const { return CVector2i(x / val.x, y / val.y); }
bool operator==(const CVector2i& other) const { return x == other.x && y == other.y; }
bool operator!=(const CVector2i& other) const { return x != other.x || y != other.y; }
CVector2i operator*(int val) const { return CVector2i(x * val, y * val); }
constexpr CVector2i operator*(int32_t val) const noexcept { return CVector2i(x * val, y * val); }
};
static_assert(sizeof(CVector2i) == sizeof(int32_t) * 2);
} // namespace zeus