31constexpr T
Pi = std::numbers::pi_v<T>;
34constexpr auto Pi_f = Pi<fp32>;
42 requires std::is_arithmetic_v<T>
51 return std::sqrt(x * x + y * y);
58 return *
this /
norm();
62using vectori = vector<int>;
63using vectorf = vector<float>;
67vector<T> operator + (vector<T> a,vector<T> b){
68 return {a.x+b.x,a.y+b.y};
74vector<T> operator - (vector<T> a,vector<T> b){
75 return {a.x-b.x,a.y-b.y};
80vector<T> operator * (vector<T> a,T b){
81 return {a.x * b,a.y * b};
86vector<T> operator / (vector<T> a,T b){
87 return {a.x / b,a.y / b};
101 return (ans < 0.f) ? ans +
Pi_f : ans -
Pi_f;
110 { c.data() } -> std::convertible_to<const std::byte*>;
111 { c.size() } -> std::convertible_to<std::size_t>;
120template<package T,
byte_container C>
122 if (bytes.size() !=
sizeof(T)) {
123 throw std::invalid_argument(
"byte buffer size does not match destination type");
126 std::memcpy(&t, bytes.data(),
sizeof(T));
131auto to_bytes(
const T& t) -> std::array<std::byte,
sizeof(T)> {
132 std::array<std::byte,
sizeof(T)> bytes{};
133 std::memcpy(bytes.data(), &t,
sizeof(T));
144template<package T,
typename C>
145requires requires(C& c) {
146 { c.data() } -> std::convertible_to<std::byte*>;
147 { c.size() } -> std::convertible_to<std::size_t>;
149void to_bytes(
const T& t, C& container) {
150 if (container.size() <
sizeof(T)) {
151 throw std::invalid_argument(
"byte buffer is smaller than source type");
153 std::memcpy(container.data(), &t,
sizeof(T));
159 static const auto init_time = std::chrono::steady_clock::now();
160 return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - init_time);
166inline constexpr uint16_t
make_u16(uint16_t high, uint16_t low)
noexcept {
167 return (
static_cast<uint16_t
>(high) << 8) |
static_cast<uint16_t
>(low);
173inline constexpr int16_t
make_i16(int16_t high, int16_t low)
noexcept {
174 return (
static_cast<int16_t
>(high) << 8) |
static_cast<int16_t
>(low);
180inline constexpr std::byte
to_byte(std::integral
auto v)
noexcept{
181 return static_cast<std::byte
>(v);
187template<
typename Ret,
typename Arg>
190template<
typename Ret,
typename Arg>
193template<
typename Ret,
typename Arg>
196template<
typename Ret,
typename Arg>
199template<
typename Ret,
typename Class,
typename Arg>
202template<
typename Ret,
typename Class,
typename Arg>
205template<
typename Ret,
typename Class,
typename Arg>
208template<
typename Ret,
typename Class,
typename Arg>
描述具有 data() 与 size() 接口的字节容器。
constexpr std::byte to_byte(std::integral auto v) noexcept
辅助将整数转换为 std::byte。
constexpr int16_t make_i16(int16_t high, int16_t low) noexcept
将高低字节组合成有符号 16 位整数。
T from_bytes(const C &bytes)
将字节容器内容反序列化为平凡类型。
constexpr uint16_t make_u16(uint16_t high, uint16_t low) noexcept
将高低字节组合成无符号 16 位整数。
auto now()
记录程序启动后的纳秒级时间戳。
constexpr fp32 rad_format(fp32 ang)
将角度限制到[-Pi,Pi]范围内
vector normalized() const
获取该向量的单位化结果。
constexpr T Pi
常量 Pi 的模板实例。
constexpr auto Pi_f
单精度浮点类型的 Pi 常量。