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,22 @@
|
||||
#pragma once
|
||||
#include <plot/core/types.hpp>
|
||||
|
||||
namespace plot {
|
||||
|
||||
/// RGBA colour with components in [0,1].
|
||||
struct Color {
|
||||
f32 r = 0.0f;
|
||||
f32 g = 0.0f;
|
||||
f32 b = 0.0f;
|
||||
f32 a = 1.0f;
|
||||
|
||||
/// Build from a packed 0xRRGGBB literal, with an optional alpha override.
|
||||
static constexpr Color hex(u32 rgb, f32 alpha = 1.0f) noexcept {
|
||||
constexpr f32 kInv255 = 1.0f / 255.0f;
|
||||
return Color{static_cast<f32>((rgb >> 16) & 0xFFu) * kInv255,
|
||||
static_cast<f32>((rgb >> 8) & 0xFFu) * kInv255,
|
||||
static_cast<f32>(rgb & 0xFFu) * kInv255, alpha};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace plot
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <plot/core/types.hpp>
|
||||
|
||||
namespace plot {
|
||||
|
||||
/// Axis-aligned rectangle in pixels, origin at the top-left.
|
||||
struct Rect {
|
||||
f32 x = 0.0f;
|
||||
f32 y = 0.0f;
|
||||
f32 w = 0.0f;
|
||||
f32 h = 0.0f;
|
||||
|
||||
constexpr f32 right() const noexcept { return x + w; }
|
||||
constexpr f32 bottom() const noexcept { return y + h; }
|
||||
|
||||
/// Half-open containment: the right/bottom edges are outside the rect.
|
||||
constexpr bool contains(f32 px, f32 py) const noexcept {
|
||||
return px >= x && px < right() && py >= y && py < bottom();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace plot
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
|
||||
namespace plot {
|
||||
|
||||
/// `std::span` re-exported so public headers and callers share one spelling.
|
||||
template <class T, std::size_t Extent = std::dynamic_extent>
|
||||
using Span = std::span<T, Extent>;
|
||||
|
||||
} // namespace plot
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <plot/core/types.hpp>
|
||||
|
||||
namespace plot {
|
||||
|
||||
enum class ErrorCode {
|
||||
Ok,
|
||||
InvalidArgument,
|
||||
OutOfMemory,
|
||||
GLFailure,
|
||||
Unsupported,
|
||||
NotImplemented,
|
||||
};
|
||||
|
||||
/// Never-null human-readable name of an error code.
|
||||
const char* to_string(ErrorCode code) noexcept;
|
||||
|
||||
/// Result of a fallible operation. Falsy unless `code == ErrorCode::Ok`.
|
||||
struct Status {
|
||||
ErrorCode code = ErrorCode::Ok;
|
||||
const char* message = "";
|
||||
|
||||
constexpr explicit operator bool() const noexcept { return code == ErrorCode::Ok; }
|
||||
};
|
||||
|
||||
} // namespace plot
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace plot {
|
||||
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
using i32 = std::int32_t;
|
||||
using u32 = std::uint32_t;
|
||||
using u64 = std::uint64_t;
|
||||
using usize = std::size_t;
|
||||
|
||||
/// Sentinel for "no index", e.g. an unmatched cursor id.
|
||||
constexpr u64 kInvalid = ~u64{0};
|
||||
|
||||
/// Closed numeric interval on one axis.
|
||||
struct Range {
|
||||
f64 min = 0.0;
|
||||
f64 max = 1.0;
|
||||
|
||||
constexpr f64 span() const noexcept { return max - min; }
|
||||
constexpr f64 clamp(f64 v) const noexcept { return v < min ? min : (v > max ? max : v); }
|
||||
};
|
||||
|
||||
} // namespace plot
|
||||
Reference in new issue
Block a user