Skip to main content

vec4.ixx File

4D vector type and utilities. More...

Included Headers

#include <cassert> #include <memory> #include <cstddef> #include <helios.math.types:vec3> #include <helios.math.concepts>

Namespaces Index

namespacehelios
namespacemath

Classes Index

structvec4<T>

Represents a 4-dimensional vector of the generic type <T>. More...

Description

4D vector type and utilities.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cassert>
8#include <memory>
9#include <cstddef>
10
11
12export module helios.math.types:vec4;
13
14import helios.math.concepts;
15
16import :vec3;
17
18
19export namespace helios::math {
20
21 template<helios::math::concepts::IsNumeric T>
22 struct vec4;
23
33 template<helios::math::concepts::IsNumeric T>
34 struct vec4 {
35
36 private:
40 T v[4];
41
42 public:
43
47 constexpr vec4() noexcept : v{static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0)} {}
48
49
58 constexpr vec4(const T x, const T y, const T z, const T w) noexcept : v{x, y, z, w} {}
59
65 constexpr vec4(const T v) noexcept : v{v, v, v, v} {}
66
67
74 constexpr vec4(const vec3<T>& vec, const T w) noexcept : v{vec[0], vec[1], vec[2], w} {}
75
76
82 explicit constexpr vec4(const vec3<T>& vec) noexcept : v{vec[0], vec[1], vec[2], static_cast<T>(1)} {}
83
94 [[nodiscard]] constexpr vec4<T> withW(T w) const noexcept {
95 return helios::math::vec4<T>{v[0], v[1], v[2], w};
96 }
97
106 constexpr const T& operator[](const size_t i) const noexcept {
107 assert(i <= 3 && "vec4 - Index out of bounds.");
108 return this->v[i];
109 }
110
111
120 constexpr T& operator[](const size_t i) noexcept {
121 assert(i <= 3 && "vec4 - Index out of bounds.");
122 return this->v[i];
123 }
124
133 [[nodiscard]] vec3<T> toVec3() const noexcept;
134
142 [[nodiscard]] vec2<T> toVec2() const noexcept;
143
144 };
145
146 template<helios::math::concepts::IsNumeric T>
147 inline vec3<T> vec4<T>::toVec3() const noexcept {
148 return vec3<T>{v[0], v[1], v[2]};
149 }
150
151 template<helios::math::concepts::IsNumeric T>
152 inline vec2<T> vec4<T>::toVec2() const noexcept {
153 return vec2<T>{v[0], v[1]};
154 }
155
166 template<helios::math::concepts::IsNumeric T>
167 constexpr vec4<T> operator*(const vec4<T>& v, const T n) noexcept {
168 return vec4<T>{v[0] * n, v[1] * n, v[2] * n, v[3] * n};
169 }
170
178 template<helios::math::concepts::IsNumeric T>
179 const T* value_ptr(const vec4<T>& m) noexcept {
180 return &m[0];
181 }
182
187
192
197
198}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.