feat: project skeleton, core types and math with transform tests
This commit is contained in:
1 parent
e4051bc6b5
commit
8a7e9e97f8
21 files changed
+515
-2
No files matched your search
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include <plot/core/types.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user