// SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2026 Martino Ferrari #pragma once #include #include namespace plot::math { /// 2D vector of `f32`, used for pixel offsets and normalised device coords. struct Vec2 { f32 x = 0.0f; f32 y = 0.0f; constexpr Vec2 operator+(const Vec2& o) const noexcept { return {x + o.x, y + o.y}; } constexpr Vec2 operator-(const Vec2& o) const noexcept { return {x - o.x, y - o.y}; } constexpr Vec2 operator*(f32 s) const noexcept { return {x * s, y * s}; } constexpr Vec2 operator/(f32 s) const noexcept { return {x / s, y / s}; } constexpr f32 dot(const Vec2& o) const noexcept { return x * o.x + y * o.y; } f32 length() const noexcept { return std::sqrt(x * x + y * y); } }; constexpr Vec2 operator*(f32 s, const Vec2& v) noexcept { return v * s; } } // namespace plot::math namespace plot { using math::Vec2; }