2025-11-04 18:50:59 +03:30
|
|
|
export module math.vec2;
|
|
|
|
|
|
|
|
|
|
import std;
|
2025-07-17 10:44:00 +03:30
|
|
|
|
|
|
|
|
namespace lt::math {
|
|
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
export template<typename T = float>
|
2025-07-17 10:44:00 +03:30
|
|
|
struct vec2_impl
|
|
|
|
|
{
|
2025-09-18 19:19:32 +03:30
|
|
|
constexpr vec2_impl(): x(), y()
|
2025-07-17 10:44:00 +03:30
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 19:19:32 +03:30
|
|
|
constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar)
|
2025-07-17 10:44:00 +03:30
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 19:19:32 +03:30
|
|
|
constexpr vec2_impl(T x, T y): x(x), y(y)
|
2025-07-17 10:44:00 +03:30
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 19:19:32 +03:30
|
|
|
[[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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 10:44:00 +03:30
|
|
|
[[nodiscard]] auto operator*(const vec2_impl<T> &other) const -> vec2_impl
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
x * other.x,
|
|
|
|
|
y * other.y,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto operator-(const vec2_impl<T> &other) const -> vec2_impl
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
x - other.x,
|
|
|
|
|
y - other.y,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto operator*(float scalar) const -> vec2_impl
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
x * scalar,
|
|
|
|
|
y * scalar,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T x; // NOLINT
|
|
|
|
|
|
|
|
|
|
T y; // NOLINT
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-18 19:19:32 +03:30
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
export using vec2 = vec2_impl<float>;
|
2025-07-17 10:44:00 +03:30
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
export using ivec2 = vec2_impl<std::int32_t>;
|
2025-07-17 10:44:00 +03:30
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
export using uvec2 = vec2_impl<std::uint32_t>;
|
2025-07-17 10:44:00 +03:30
|
|
|
|
|
|
|
|
} // namespace lt::math
|
2025-09-18 19:21:52 +03:30
|
|
|
|
2025-11-04 18:50:59 +03:30
|
|
|
export template<typename T>
|
2025-09-18 19:21:52 +03:30
|
|
|
struct std::formatter<lt::math::vec2_impl<T>>
|
|
|
|
|
{
|
|
|
|
|
constexpr auto parse(std::format_parse_context &context)
|
|
|
|
|
{
|
|
|
|
|
return context.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto format(const lt::math::vec2_impl<T> &val, std::format_context &context) const
|
|
|
|
|
{
|
|
|
|
|
return std::format_to(context.out(), "{}, {}", val.x, val.y);
|
|
|
|
|
}
|
|
|
|
|
};
|