sandbox
Loading...
Searching...
No Matches
vector4.hpp
1#ifndef LIBSBX_MATH_VECTOR4_HPP_
2#define LIBSBX_MATH_VECTOR4_HPP_
3
4#include <cstddef>
5#include <cmath>
6#include <cstdint>
7#include <concepts>
8#include <fstream>
9#include <ostream>
10#include <type_traits>
11
12#include <fmt/format.h>
13
14#include <yaml-cpp/yaml.h>
15
16#include <libsbx/math/concepts.hpp>
17#include <libsbx/math/vector3.hpp>
18
19namespace sbx::math {
20
21template<scalar Type>
22class basic_vector4 : public basic_vector<4u, Type> {
23
25
26 inline static constexpr auto x_axis = std::size_t{0u};
27 inline static constexpr auto y_axis = std::size_t{1u};
28 inline static constexpr auto z_axis = std::size_t{2u};
29 inline static constexpr auto w_axis = std::size_t{3u};
30
31public:
32
33 using value_type = base_type::value_type;
34 using reference = base_type::reference;
35 using const_reference = base_type::const_reference;
36 using size_type = base_type::size_type;
37 using length_type = base_type::length_type;
38
39 inline static constexpr basic_vector4 zero{base_type::fill(value_type{0})};
40 inline static constexpr basic_vector4 one{base_type::fill(value_type{1})};
41
42 using base_type::base_type;
43
44 constexpr basic_vector4(const base_type& base) noexcept;
45
46 template<scalar Other>
47 constexpr basic_vector4(Other x, Other y, Other z, Other w) noexcept;
48
49 template<scalar Other, scalar Scalar = Other>
50 constexpr basic_vector4(const basic_vector3<Other>& vector, Scalar w = Scalar{0}) noexcept;
51
52 [[nodiscard]] static constexpr auto dot(const basic_vector4& lhs, const basic_vector4& rhs) noexcept -> length_type;
53
54 [[nodiscard]] static constexpr auto normalized(const basic_vector4& vector) noexcept -> basic_vector4;
55
56 [[nodiscard]] constexpr operator basic_vector3<Type>() const noexcept;
57
58 [[nodiscard]] constexpr auto x() noexcept -> reference;
59
60 [[nodiscard]] constexpr auto x() const noexcept -> const_reference;
61
62 [[nodiscard]] constexpr auto y() noexcept -> reference;
63
64 [[nodiscard]] constexpr auto y() const noexcept -> const_reference;
65
66 [[nodiscard]] constexpr auto z() noexcept -> reference;
67
68 [[nodiscard]] constexpr auto z() const noexcept -> const_reference;
69
70 [[nodiscard]] constexpr auto w() noexcept -> reference;
71
72 [[nodiscard]] constexpr auto w() const noexcept -> const_reference;
73
74}; // class basic_vector4
75
76template<scalar Lhs, scalar Rhs>
77[[nodiscard]] constexpr auto operator+(basic_vector4<Lhs> lhs, const basic_vector4<Rhs>& rhs) noexcept -> basic_vector4<Lhs>;
78
79template<scalar Lhs, scalar Rhs>
80[[nodiscard]] constexpr auto operator-(basic_vector4<Lhs> lhs, const basic_vector4<Rhs>& rhs) noexcept -> basic_vector4<Lhs>;
81
82template<scalar Type>
83[[nodiscard]] constexpr auto operator-(basic_vector4<Type> vector) noexcept -> basic_vector4<Type>;
84
85template<scalar Lhs, scalar Rhs>
86[[nodiscard]] constexpr auto operator*(basic_vector4<Lhs> lhs, Rhs scalar) noexcept -> basic_vector4<Lhs>;
87
88template<scalar Lhs, scalar Rhs>
89[[nodiscard]] constexpr auto operator*(basic_vector4<Lhs> lhs, const basic_vector4<Rhs>& rhs) noexcept -> basic_vector4<Lhs>;
90
91template<scalar Lhs, scalar Rhs>
92[[nodiscard]] constexpr auto operator/(basic_vector4<Lhs> lhs, Rhs scalar) noexcept -> basic_vector4<Lhs>;
93
95
97
99
100using vector4 = vector4f;
101
102} // namespace sbx::math
103
104template<sbx::math::scalar Type>
105struct std::hash<sbx::math::basic_vector4<Type>> {
106
107 auto operator()(const sbx::math::basic_vector4<Type>& vector) const noexcept -> std::size_t;
108
109}; // struct std::hash
110
111template<sbx::math::scalar Type>
112struct fmt::formatter<sbx::math::basic_vector4<Type>> {
113
114 template<typename ParseContext>
115 constexpr auto parse(ParseContext& context) noexcept -> decltype(context.begin());
116
117 template<typename FormatContext>
118 auto format(const sbx::math::basic_vector4<Type>& vector, FormatContext& context) noexcept -> decltype(context.out());
119
120}; // struct fmt::formatter
121
122template<sbx::math::scalar Type>
123struct YAML::convert<sbx::math::basic_vector4<Type>> {
124
125 static auto encode(const sbx::math::basic_vector4<Type>& vector) -> Node;
126
127 static auto decode(const Node& node, sbx::math::basic_vector4<Type>& vector) -> bool;
128
129}; // struct YAML::convert
130
131#include <libsbx/math/vector4.ipp>
132
133#endif // LIBSBX_MATH_VECTOR4_HPP_
Definition: vector3.hpp:22
Definition: vector4.hpp:22
Definition: vector.hpp:19