1#ifndef TOPAZ_CORE_VECTOR_HPP
2#define TOPAZ_CORE_VECTOR_HPP
21 template<
typename T,
int N>
22 requires std::integral<T> || std::floating_point<T>
34 std::array<T, N> values;
35 std::fill(values.begin(), values.end(), t);
43 template<
typename... Ts>
47 && std::is_convertible_v<std::tuple_element_t<0, std::tuple<Ts...>>, T>)
49 arr({ std::forward<Ts>(ts)... }) {}
53 constexpr vector(std::array<T, N> data): arr(data){}
79 vector<T, N> operator*(T scalar)
const{
auto cpy = *
this;
return cpy *= scalar;}
80 vector<T, N> operator/(T scalar)
const{
auto cpy = *
this;
return cpy /= scalar;}
101 operator vector<C, N>() const requires(std::is_convertible_v<T, C>)
103 std::array<C, N> arr;
104 std::transform(this->arr.begin(), this->arr.end(), arr.begin(), [](
const T& t)->C{return static_cast<C>(t);});
118 std::array<T, N> arr;
Represents the generic vector.
Definition vector.hpp:24
T length() const
Retrieve the magnitude of the vector.
bool operator==(const vector< T, N > &rhs) const =default
Compare two vectors. Two vectors are equal if all of their components are exactly equal.
vector< T, N > cross(const vector< T, N > &rhs) const
Retrieve a cross product between two three-dimensional vectors.
static constexpr vector< T, N > zero()
Retrieve a vector filled with zeroes.
Definition vector.hpp:26
vector< T, N > & operator-=(const vector< T, N > &rhs)
Subtract one vector from another.
constexpr vector(std::array< T, N > data)
Definition vector.hpp:53
vector< T, N > & operator+=(const vector< T, N > &rhs)
Add one vector to another.
constexpr vector(Ts &&... ts)
Definition vector.hpp:48
static constexpr vector< T, N > filled(T t)
Retrieve a vector filled with the given value.
Definition vector.hpp:32
vector< T, N > operator-(const vector< T, N > &rhs) const
Subtract one vector from another.
Definition vector.hpp:94
vector< T, N > operator*(const vector< T, N > &rhs) const
Multiply one vector with another.
Definition vector.hpp:96
T & operator[](std::size_t idx)
vector< T, N > & operator*=(const vector< T, N > &rhs)
Multiply one vector with another.
const T & operator[](std::size_t idx) const
vector< T, N > & operator/=(const vector< T, N > &rhs)
Divide one vector by another.
vector< T, N > operator+(const vector< T, N > &rhs) const
Add one vector to another.
Definition vector.hpp:92
T dot(const vector< T, N > &rhs) const
Retrieve the dot (scalar) product of two vectors.
vector< T, N > operator/(const vector< T, N > &rhs) const
Divide one vector by another.
Definition vector.hpp:98