export module lsd.math.vec2; import lsd.primitives; import lsd.str; export namespace lt::lsd { template struct vec2_impl { constexpr vec2_impl() = default; constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar) { } constexpr vec2_impl(T x, T y): x(x), y(y) { } [[nodiscard]] auto operator==(const vec2_impl &other) const -> bool { return x == other.x && y == other.y; } [[nodiscard]] auto operator!=(const vec2_impl &other) const -> bool { return !(*this == other); } [[nodiscard]] auto operator*(const vec2_impl &other) const -> vec2_impl { return { x * other.x, y * other.y, }; } [[nodiscard]] auto operator-(const vec2_impl &other) const -> vec2_impl { return { x - other.x, y - other.y, }; } [[nodiscard]] auto operator*(f32 scalar) const -> vec2_impl { return { x * scalar, y * scalar, }; } T x; // NOLINT T y; // NOLINT }; using vec2 = vec2_impl; using dvec2 = vec2_impl; using ivec2 = vec2_impl; using uvec2 = vec2_impl; } // namespace lt::lsd export template struct lt::lsd::formatter> { constexpr auto parse(lt::lsd::format_parse_context &context) { return context.begin(); } auto format(const lt::lsd::vec2_impl &val, lt::lsd::format_context &context) const { return lt::lsd::format_to(context.out(), "{}, {}", val.x, val.y); } };