8template <
typename T, std::
size_t N>
20 for (
size_t i = 0; i < N; ++i) {
28 auto at(std::size_t i) -> T& {
return data.at(i); }
29 [[nodiscard]]
auto at(std::size_t i)
const {
return data.at(i); }
32 for (
auto& d :
data) {
39 for (std::size_t i = 0; i < N; i++) v.
data.at(i) =
data.at(i) * scalar;
44 for (std::size_t i = 0; i < N; i++) {
51 for (std::size_t i = 0; i < N; i++) {
57 [[nodiscard]]
constexpr auto dot(
const vec_t& other)
const {
61 for (std::size_t i = 0; i < N; i++)
dot += a.data.at(i) * b.data.at(i);
66 for (std::size_t i = 0; i < N; i++)
72 for (std::size_t i = 0; i < N; i++)
79 for (std::size_t i = 0; i < N; i++)
86 for (std::size_t i = 0; i < N; i++) v.
data.at(i) = -
data.at(i);
92 for (std::size_t i = 0; i < N; i++) v.
data.at(i) =
data.at(i) / scalar;
101 return !(*
this == other);
104 [[nodiscard]]
constexpr auto length()
const {
106 for (
const auto& d :
data) sum += d * d;
107 return std::sqrt(sum);
129 [[nodiscard]]
auto x()
const {
return data.at(0); }
130 [[nodiscard]]
auto y()
const {
return data.at(1); }
140 [[nodiscard]]
auto x()
const {
return data.at(0); }
142 [[nodiscard]]
auto y()
const {
return data.at(1); }
144 [[nodiscard]]
auto z()
const {
return data.at(2); }
148 return Vec3f{
y() * other.
z() -
z() * other.
y(),
149 z() * other.
x() -
x() * other.
z(),
150 x() * other.
y() -
y() * other.
x()};
159 :
Vec<float, 4>({vec.
x(), vec.
y(), vec.
z(),
w}) {}
163 [[nodiscard]]
auto x()
const {
return data.at(0); }
164 [[nodiscard]]
auto y()
const {
return data.at(1); }
165 [[nodiscard]]
auto z()
const {
return data.at(2); }
166 [[nodiscard]]
auto w()
const {
return data.at(3); }
Definition geometry.hpp:8
Definition vector.hpp:124
auto x() const
Definition vector.hpp:129
Vec2f(float x, float y)
Definition vector.hpp:126
Vec2f(const Vec< float, 2 > &other)
Definition vector.hpp:127
Vec2f()
Definition vector.hpp:125
auto y() const
Definition vector.hpp:130
Definition vector.hpp:133
auto z(float z)
Definition vector.hpp:145
Vec3f(const auto &other)
Definition vector.hpp:135
Vec3f(float x, float y, float z)
Definition vector.hpp:137
auto y() const
Definition vector.hpp:142
Vec3f(const Vec< float, 3 > &other)
Definition vector.hpp:138
Vec3f()
Definition vector.hpp:134
auto z() const
Definition vector.hpp:144
auto x() const
Definition vector.hpp:140
auto x(float x)
Definition vector.hpp:141
auto operator%(const Vec3f &other) const
Definition vector.hpp:147
auto y(float y)
Definition vector.hpp:143
Definition vector.hpp:154
auto z() const
Definition vector.hpp:165
auto x() const
Definition vector.hpp:163
Vec4f(const auto &other)
Definition vector.hpp:156
auto w() const
Definition vector.hpp:166
Vec4f(float x, float y, float z, float w)
Definition vector.hpp:157
auto y() const
Definition vector.hpp:164
Vec4f(const Vec< float, 4 > &other)
Definition vector.hpp:160
Vec4f()
Definition vector.hpp:155
Vec4f(const Vec3f &vec, float w)
Definition vector.hpp:158
Vec(std::array< T, N > data)
Definition vector.hpp:18
constexpr auto operator*=(float scalar) const
Definition vector.hpp:31
constexpr auto operator==(const vec_t &other) const
Definition vector.hpp:96
std::array< T, N > data
Definition vector.hpp:112
constexpr auto length() const
Definition vector.hpp:104
static auto UnitX()
Definition vector.hpp:12
constexpr auto operator*=(const vec_t &other)
Definition vector.hpp:43
constexpr auto operator+=(const vec_t &other)
Definition vector.hpp:65
auto normalized() const
Definition vector.hpp:110
Vec(float scalar)
Definition vector.hpp:19
constexpr auto operator-() const
Definition vector.hpp:84
Vec()
Definition vector.hpp:16
constexpr auto operator-(const vec_t &other) const
Definition vector.hpp:77
constexpr auto dot(const vec_t &other) const
Definition vector.hpp:57
auto at(std::size_t i) const
Definition vector.hpp:29
constexpr auto operator*(const vec_t &other) const
Definition vector.hpp:49
static auto UnitY()
Definition vector.hpp:13
constexpr auto operator+(const vec_t &other) const
Definition vector.hpp:70
static auto UnitZ()
Definition vector.hpp:14
auto operator/(float scalar) const
Definition vector.hpp:90
constexpr auto operator*(float scalar) const
Definition vector.hpp:37
auto at(std::size_t i) -> T &
Definition vector.hpp:28
constexpr auto operator!=(const vec_t &other) const
Definition vector.hpp:100