Move Vectormath main
C++20 game and graphics mathematics
Loading...
Searching...
No Matches
Vectors.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <type_traits>
5
6#include <mv/math/Vec2.hpp>
7#include <mv/math/Vec3.hpp>
8#include <mv/math/Vec4.hpp>
9
10namespace mv::math
11{
13 {
14 float X{};
15 float Y{};
16
17 [[nodiscard]] friend constexpr bool operator==(
18 PackedVec2f, PackedVec2f) noexcept = default;
19 };
20
22 {
23 float X{};
24 float Y{};
25 float Z{};
26
27 [[nodiscard]] friend constexpr bool operator==(
28 PackedVec3f, PackedVec3f) noexcept = default;
29 };
30
32 {
33 float X{};
34 float Y{};
35 float Z{};
36 float W{};
37
38 [[nodiscard]] friend constexpr bool operator==(
39 PackedVec4f, PackedVec4f) noexcept = default;
40 };
41
42 [[nodiscard]] inline Vec2f Load(const PackedVec2f& value) noexcept
43 {
44 return Vec2f(value.X, value.Y);
45 }
46
47 [[nodiscard]] inline Vec3f Load(const PackedVec3f& value) noexcept
48 {
49 return Vec3f(value.X, value.Y, value.Z);
50 }
51
52 [[nodiscard]] inline Vec4f Load(const PackedVec4f& value) noexcept
53 {
54 return Vec4f(value.X, value.Y, value.Z, value.W);
55 }
56
57 inline void Store(PackedVec2f& destination, Vec2f value) noexcept
58 {
59 destination = {value.X(), value.Y()};
60 }
61
62 inline void Store(PackedVec3f& destination, Vec3f value) noexcept
63 {
64 destination = {value.X(), value.Y(), value.Z()};
65 }
66
67 inline void Store(PackedVec4f& destination, Vec4f value) noexcept
68 {
69 destination = {value.X(), value.Y(), value.Z(), value.W()};
70 }
71
72 [[nodiscard]] inline PackedVec2f Store(Vec2f value) noexcept
73 {
74 return {value.X(), value.Y()};
75 }
76
77 [[nodiscard]] inline PackedVec3f Store(Vec3f value) noexcept
78 {
79 return {value.X(), value.Y(), value.Z()};
80 }
81
82 [[nodiscard]] inline PackedVec4f Store(Vec4f value) noexcept
83 {
84 return {value.X(), value.Y(), value.Z(), value.W()};
85 }
86} // namespace mv::math
87
88static_assert(sizeof(mv::math::PackedVec2f) == 8);
89static_assert(alignof(mv::math::PackedVec2f) == 4);
90static_assert(offsetof(mv::math::PackedVec2f, X) == 0);
91static_assert(offsetof(mv::math::PackedVec2f, Y) == 4);
92static_assert(std::is_trivially_copyable_v<mv::math::PackedVec2f>);
93static_assert(std::is_standard_layout_v<mv::math::PackedVec2f>);
94
95static_assert(sizeof(mv::math::PackedVec3f) == 12);
96static_assert(alignof(mv::math::PackedVec3f) == 4);
97static_assert(offsetof(mv::math::PackedVec3f, X) == 0);
98static_assert(offsetof(mv::math::PackedVec3f, Y) == 4);
99static_assert(offsetof(mv::math::PackedVec3f, Z) == 8);
100static_assert(std::is_trivially_copyable_v<mv::math::PackedVec3f>);
101static_assert(std::is_standard_layout_v<mv::math::PackedVec3f>);
102
103static_assert(sizeof(mv::math::PackedVec4f) == 16);
104static_assert(alignof(mv::math::PackedVec4f) == 4);
105static_assert(std::is_trivially_copyable_v<mv::math::PackedVec4f>);
106static_assert(std::is_standard_layout_v<mv::math::PackedVec4f>);
void Store(PackedVec2f &destination, Vec2f value) noexcept
Definition Vectors.hpp:57
Vec2f Load(const PackedVec2f &value) noexcept
Definition Vectors.hpp:42
Vec2< float > Vec2f
Definition Vec2.hpp:234
Vec3< float > Vec3f
Definition Vec3.hpp:344
Vec4< float > Vec4f
Definition Vec4.hpp:280
friend constexpr bool operator==(PackedVec2f, PackedVec2f) noexcept=default
friend constexpr bool operator==(PackedVec3f, PackedVec3f) noexcept=default
friend constexpr bool operator==(PackedVec4f, PackedVec4f) noexcept=default