feat(math): add constexpr to some functions & add equality comparison operators
This commit is contained in:
parent
9e6300f1aa
commit
bb6485488c
3 changed files with 35 additions and 8 deletions
|
@ -5,18 +5,28 @@ namespace lt::math {
|
|||
template<typename T = float>
|
||||
struct vec2_impl
|
||||
{
|
||||
vec2_impl(): x(), y()
|
||||
constexpr vec2_impl(): x(), y()
|
||||
{
|
||||
}
|
||||
|
||||
explicit vec2_impl(T scalar): x(scalar), y(scalar)
|
||||
constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
vec2_impl(T x, T y): x(x), y(y)
|
||||
constexpr vec2_impl(T x, T y): x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator==(const vec2_impl<T> &other) const -> bool
|
||||
{
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator!=(const vec2_impl<T> &other) const -> bool
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator*(const vec2_impl<T> &other) const -> vec2_impl
|
||||
{
|
||||
return {
|
||||
|
@ -47,6 +57,7 @@ struct vec2_impl
|
|||
T y; // NOLINT
|
||||
};
|
||||
|
||||
|
||||
using vec2 = vec2_impl<float>;
|
||||
|
||||
using ivec2 = vec2_impl<int32_t>;
|
||||
|
|
|
@ -7,19 +7,29 @@ namespace lt::math {
|
|||
template<typename T = float>
|
||||
struct vec3_impl
|
||||
{
|
||||
vec3_impl(): x(), y(), z()
|
||||
constexpr vec3_impl(): x(), y(), z()
|
||||
{
|
||||
}
|
||||
|
||||
explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar)
|
||||
constexpr explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
vec3_impl(T x, T y, T z): x(x), y(y), z(z)
|
||||
constexpr vec3_impl(T x, T y, T z): x(x), y(y), z(z)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator-(const vec3_impl<T> &other) const -> vec3_impl
|
||||
[[nodiscard]] auto operator==(const vec3_impl<T> &other) const -> bool
|
||||
{
|
||||
return x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator!=(const vec3_impl<T> &other) const -> bool
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto operator-(const vec3_impl<T> &other) const -> vec3_impl
|
||||
{
|
||||
return {
|
||||
x - other.x,
|
||||
|
@ -28,7 +38,7 @@ struct vec3_impl
|
|||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator*(const vec3_impl<T> &other) const -> vec3_impl
|
||||
[[nodiscard]] constexpr auto operator*(const vec3_impl<T> &other) const -> vec3_impl
|
||||
{
|
||||
return {
|
||||
x * other.x,
|
||||
|
|
|
@ -39,6 +39,12 @@ struct vec4_impl
|
|||
return values[idx];
|
||||
}
|
||||
|
||||
friend auto operator<<(std::ostream &stream, vec4_impl<T> value) -> std::ostream &
|
||||
{
|
||||
stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w;
|
||||
return stream;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
union
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue