6#include <initializer_list>
13template<
typename T, u32 LENGTH>
21 for (
u32 i = 0; i < LENGTH; i++) this->vec[i] = val;
24 NumVec(std::initializer_list<T> list) {
25 assert(list.size() == LENGTH)
26 for (
u32 i = 0; i < LENGTH; i++) {
27 this->vec[i] = list.begin()[i];
31 explicit NumVec(
const T(&list)[LENGTH]) {
32 for (
u32 i = 0; i < LENGTH; i++) {
33 this->vec[i] = list[i];
38 for (
u32 i = 0; i < LENGTH; i++) {
39 this->vec[i] = other.
vec[i];
50 this->vec[idx] = arg0;
53 template<
u64 idx,
typename... Args>
54 void init(T arg0, Args... args) {
55 this->init<idx>(arg0);
56 this->init<idx+1>(args...);
60 template<
typename... Args>
62 this->init<0>(arg0, args...);
66 for (
u32 i = 0; i < LENGTH; i++) {
67 if (this->vec[i] != other.
vec[i])
return false;
73#pragma clang diagnostic push
74#pragma ide diagnostic ignored "Simplify"
75 return !(*
this == other);
76#pragma clang diagnostic pop
80 for (
u32 i = 0; i < LENGTH; i++) {
81 if (this->vec[i] <= other.
vec[i])
return false;
87 for (
u32 i = 0; i < LENGTH; i++) {
88 if (this->vec[i] < other.
vec[i])
return false;
94 for (
u32 i = 0; i < LENGTH; i++) {
95 if (this->vec[i] >= other.
vec[i])
return false;
101 for (
u32 i = 0; i < LENGTH; i++) {
102 if (this->vec[i] > other.
vec[i])
return false;
109 return this->vec[idx];
114 return this->vec[idx];
117#define SCALAR_OP(op) \
118 NumVec operator STRCAT(op, =) (const T &scalar) { \
119 for (u32 i = 0; i < LENGTH; i++) { \
120 this->vec[i] STRCAT(op, =) scalar; \
122 return NumVec(*this); \
125 NumVec operator op (const T &scalar) const { \
126 return NumVec(*this) STRCAT(op, =) scalar; \
140#define VECTOR_OP(op) \
141 NumVec operator STRCAT(op, =) (const NumVec &other) { \
142 for (u32 i = 0; i < LENGTH; i++) { \
143 this->vec[i] STRCAT(op, =) other.vec[i]; \
145 return NumVec(*this); \
148 NumVec operator op (const NumVec &other) const { \
149 return NumVec(*this) STRCAT(op, =) other; \
163 bool eq(
const NumVec &other,
const T eps = std::numeric_limits<T>::epsilon())
const {
164 return (*
this - other).abs() <=
NumVec(eps);
169 for (
u32 i = 0; i < LENGTH; i++) val += this->vec[i];
175 for (
u32 i = 0; i < LENGTH; i++) val *= this->vec[i];
181 for (
u32 i = 0; i < LENGTH; i++) val[i] = std::floor(val[i]);
187 for (
u32 i = 0; i < LENGTH; i++) val[i] = std::ceil(val[i]);
193 for (
u32 i = 0; i < LENGTH; i++) val[i] =
std::abs(val[i]);
199 for (
u32 i = 0; i < LENGTH; i++) val[i] = std::pow(val[i],
pow);
207 for (
u32 i = 0; i < LENGTH; i++) {
208 result[i] = (Q) this->vec[i];
216 for (
u32 i = 0; i < LENGTH - 1; i++) stream << value.vec[i] <<
", ";
217 stream << value.vec[LENGTH - 1] <<
']';
bool operator>(const NumVec &other) const
bool operator!=(const NumVec &other) const
friend std::ostream & operator<<(std::ostream &stream, const NumVec &value)
NumVec(const NumVec &other)
bool operator<(const NumVec &other) const
void init(T arg0, Args... args)
NumVec(T arg0, Args... args)
NumVec< Q, LENGTH > castAs() const
static constexpr u32 size()
bool eq(const NumVec &other, const T eps=std::numeric_limits< T >::epsilon()) const
NumVec(std::initializer_list< T > list)
bool operator==(const NumVec &other) const
bool operator<=(const NumVec &other) const
const T & operator[](u32 idx) const
NumVec(const T(&list)[LENGTH])
bool operator>=(const NumVec &other) const
NumVec pow(float pow) const