Lugdunum  0.1.0
Vector.inl
Go to the documentation of this file.
1 template <uint8_t Rows, typename T>
2 inline constexpr Vector<Rows, T>::Vector(T value) : Matrix<Rows, 1, T>(value) {}
3 
4 template <uint8_t Rows, typename T>
5 inline Vector<Rows, T>::Vector(std::initializer_list<T> list) : Matrix<Rows, 1, T>(list) {}
6 
7 template <uint8_t Rows, typename T>
8 inline Vector<Rows, T>::Vector(const typename Vector<Rows, T>::BaseMatrix& matrix) : Matrix<Rows, 1, T>(matrix) {}
9 
10 template <uint8_t Rows, typename T>
11 inline Vector<Rows, T>::Vector(typename Vector<Rows, T>::BaseMatrix&& matrix) : Matrix<Rows, 1, T>(std::move(matrix)) {}
12 
13 template <uint8_t Rows, typename T>
14 inline Vector<Rows, T>::Vector(const Vector<Rows - 1, T>& vector, T value) {
15  for (uint8_t row = 0; row < Rows - 1; ++row) {
16  (*this)(row) = vector(row);
17  }
18 
19  (*this)(Rows - 1) = value;
20 }
21 
22 template <uint8_t Rows, typename T>
24  for (uint8_t row = 0; row < Rows; ++row) {
25  (*this)(row) = vector(row);
26  }
27 }
28 
29 template <uint8_t Rows, typename T>
31  Vector<Rows, T> tmp(0);
32 
33  for (uint8_t row = 0; row < Rows; ++row) {
34  for (uint8_t col = 0; col < Rows; ++col) {
35  tmp(row) += (*this)(col) * rhs(row, col);
36  }
37  }
38 
39  *this = std::move(tmp);
40 
41  return *this;
42 }
43 
44 template <uint8_t Rows, typename T>
47  return *this;
48 }
49 
50 template <uint8_t Rows, typename T>
53  return *this;
54 }
55 
56 template <uint8_t Rows, typename T>
57 inline constexpr T Vector<Rows, T>::length() const {
58  return T(std::sqrt(squaredLength()));
59 }
60 
61 template <uint8_t Rows, typename T>
62 inline constexpr T Vector<Rows, T>::squaredLength() const {
63  return T((BaseMatrix::_values * BaseMatrix::_values).sum());
64 }
65 
66 template <uint8_t Rows, typename T>
68  *this = ::lug::Math::normalize(*this);
69 }
70 
71 template <typename T>
72 inline constexpr Vector<3, T> cross(const Vector<3, T>& lhs, const Vector<3, T>& rhs) {
73  return {
74  lhs.y() * rhs.z() - lhs.z() * rhs.y(),
75  lhs.z() * rhs.x() - lhs.x() * rhs.z(),
76  lhs.x() * rhs.y() - lhs.y() * rhs.x()
77  };
78 }
79 
80 template <uint8_t Rows, typename T>
81 inline constexpr T dot(const Vector<Rows, T>& lhs, const Vector<Rows, T>& rhs) {
82  return (lhs.getValues() * rhs.getValues()).sum();
83 }
84 
85 template <uint8_t Rows, uint8_t Columns, typename T>
86 inline constexpr Matrix<Rows, Columns, T> outer(const Vector<Rows, T>& lhs, const Vector<Columns, T>& rhs) {
87  return lhs * rhs.transpose();
88 }
89 
90 template <uint8_t Rows, typename T>
91 inline constexpr Vector<Rows, T> normalize(const Vector<Rows, T>& lhs) {
92  return lhs / lhs.length();
93 }
94 
95 template <uint8_t Rows, typename T>
96 inline Vector<Rows, T> operator*(const Vector<Rows, T>& lhs, const Vector<Rows, T>& rhs) {
97  return {lhs.getValues() * rhs.getValues()};
98 }
99 
100 template <uint8_t Rows, typename T>
101 inline Vector<Rows, T> operator/(const Vector<Rows, T>& lhs, const Vector<Rows, T>& rhs) {
102  return {lhs.getValues() / rhs.getValues()};
103 }
104 
105 template <uint8_t Rows, typename T>
106 inline Vector<Rows, T> operator*(const Vector<Rows, T>& lhs, const Matrix<Rows, Rows, T>& rhs) {
107  Vector<Rows, T> vector{lhs};
108 
109  vector *= rhs;
110 
111  return vector;
112 }
113 
114 template <uint8_t Rows, typename T>
115 inline Vector<Rows, T> operator*(const Matrix<Rows, Rows, T>& lhs, const Vector<Rows, T>& rhs) {
116  Vector<Rows, T> vector{rhs};
117 
118  vector *= lhs;
119 
120  return vector;
121 }
122 
123 template <typename T>
124 inline Vector<3, T> operator*(const Vector<3, T>& lhs, const Matrix<4, 4, T>& rhs) {
125  return Vector<4, T>{lhs, T(1)} * rhs;
126 }
127 
128 template <typename T>
129 inline Vector<3, T> operator*(const Matrix<4, 4, T>& lhs, const Vector<3, T>& rhs) {
130  return lhs * Vector<4, T>{rhs, T(1)};
131 }
Vector< Rows, T > operator*=(const Matrix< Rows, Rows, T > &rhs)
Definition: Vector.inl:30
constexpr Vector< 3, T > cross(const Vector< 3, T > &lhs, const Vector< 3, T > &rhs)
constexpr Vector< Rows, T > normalize(const Vector< Rows, T > &lhs)
Definition: Vector.inl:91
constexpr T squaredLength() const
Definition: Vector.inl:62
void normalize()
Definition: Vector.inl:67
constexpr Matrix< Rows, Columns, T > outer(const Vector< Rows, T > &lhs, const Vector< Columns, T > &rhs)
constexpr T length() const
Definition: Vector.inl:57
Vector< Rows, T > operator/=(const Vector< Rows, T > &rhs)
Definition: Vector.inl:51
Matrix< Rows, Columns, T > operator/(const Matrix< Rows, Columns, T > &lhs, T rhs)
constexpr Vector()=default
Matrix< Rows, Columns, T > operator*(const Matrix< Rows, Columns, T > &lhs, T rhs)
T dot(const Quaternion< T > &lhs, const Quaternion< T > &rhs)