Added classes generated by generate_math_lib.py
This commit is contained in:
parent
34e5a2cf56
commit
b35e0551d2
159
src/math/concepts.hpp
Normal file
159
src/math/concepts.hpp
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <concepts>
|
||||||
|
|
||||||
|
// Number
|
||||||
|
template<typename T>
|
||||||
|
concept Number = std::integral<T> or std::floating_point<T>;
|
||||||
|
|
||||||
|
// VectorX
|
||||||
|
template<typename T>
|
||||||
|
concept Vector2 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x)>;
|
||||||
|
requires Number<decltype(t.y)>;
|
||||||
|
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 2); };
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept Vector3 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x)>;
|
||||||
|
requires Number<decltype(t.y)>;
|
||||||
|
requires Number<decltype(t.z)>;
|
||||||
|
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 3); };
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept Vector4 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x)>;
|
||||||
|
requires Number<decltype(t.y)>;
|
||||||
|
requires Number<decltype(t.z)>;
|
||||||
|
requires Number<decltype(t.w)>;
|
||||||
|
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 4); };
|
||||||
|
|
||||||
|
// RowVectorX
|
||||||
|
template<typename T>
|
||||||
|
concept RowVector2 = Vector2<T> and Number<typename T::isRowVector>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept RowVector3 = Vector3<T> and Number<typename T::isRowVector>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept RowVector4 = Vector4<T> and Number<typename T::isRowVector>;
|
||||||
|
|
||||||
|
// ColumnVectorX
|
||||||
|
template<typename T>
|
||||||
|
concept ColumnVector2 = Vector2<T> and Number<typename T::isColumnVector>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept ColumnVector3 = Vector3<T> and Number<typename T::isColumnVector>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept ColumnVector4 = Vector4<T> and Number<typename T::isColumnVector>;
|
||||||
|
|
||||||
|
// Matrices
|
||||||
|
template<typename T>
|
||||||
|
concept Mat2x2 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat2x3 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat2x4 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x1_4)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
requires Number<decltype(t.x2_4)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat3x2 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat3x3 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
requires Number<decltype(t.x3_3)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat3x4 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x1_4)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
requires Number<decltype(t.x2_4)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
requires Number<decltype(t.x3_3)>;
|
||||||
|
requires Number<decltype(t.x3_4)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat4x2 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
requires Number<decltype(t.x4_1)>;
|
||||||
|
requires Number<decltype(t.x4_2)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat4x3 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
requires Number<decltype(t.x3_3)>;
|
||||||
|
requires Number<decltype(t.x4_1)>;
|
||||||
|
requires Number<decltype(t.x4_2)>;
|
||||||
|
requires Number<decltype(t.x4_3)>;
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
concept Mat4x4 = requires(T t) {
|
||||||
|
requires Number<decltype(t.x1_1)>;
|
||||||
|
requires Number<decltype(t.x1_2)>;
|
||||||
|
requires Number<decltype(t.x1_3)>;
|
||||||
|
requires Number<decltype(t.x1_4)>;
|
||||||
|
requires Number<decltype(t.x2_1)>;
|
||||||
|
requires Number<decltype(t.x2_2)>;
|
||||||
|
requires Number<decltype(t.x2_3)>;
|
||||||
|
requires Number<decltype(t.x2_4)>;
|
||||||
|
requires Number<decltype(t.x3_1)>;
|
||||||
|
requires Number<decltype(t.x3_2)>;
|
||||||
|
requires Number<decltype(t.x3_3)>;
|
||||||
|
requires Number<decltype(t.x3_4)>;
|
||||||
|
requires Number<decltype(t.x4_1)>;
|
||||||
|
requires Number<decltype(t.x4_2)>;
|
||||||
|
requires Number<decltype(t.x4_3)>;
|
||||||
|
requires Number<decltype(t.x4_4)>;
|
||||||
|
};
|
322
src/math/mat2x2.cpp
Normal file
322
src/math/mat2x2.cpp
Normal file
@ -0,0 +1,322 @@
|
|||||||
|
#include "mat2x2.hpp"
|
||||||
|
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat2x2
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::operator=(const mat2x2<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator+(const M& other) const {
|
||||||
|
return mat2x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator-(const M& other) const {
|
||||||
|
return mat2x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator%(const M& other) const {
|
||||||
|
return mat2x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat2x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat2x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void mat2x2<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void mat2x2<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void mat2x2<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void mat2x2<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void mat2x2<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator+(const N& other) const {
|
||||||
|
return mat2x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator-(const N& other) const {
|
||||||
|
return mat2x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator%(const N& other) const {
|
||||||
|
return mat2x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat2x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat2x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x2<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> mat2x2<T>::operator*(const C& other) const {
|
||||||
|
vec2<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x2<T>::operator*(const M& other) const {
|
||||||
|
mat2x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x2<T>::operator*(const M& other) const {
|
||||||
|
mat2x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x2<T>::operator*(const M& other) const {
|
||||||
|
mat2x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool mat2x2<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x2<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat2x2<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x2<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x2<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat2x2<T>::dot(const mat2x2<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x2<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x2<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 2 + col * 2) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec2<T> mat2x2<T>::row(std::size_t i) const {
|
||||||
|
return rvec2<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec2<T> mat2x2<T>::column(std::size_t i) const {
|
||||||
|
return vec2<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x2<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x2<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x2<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x2<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat2x2.tpp"
|
207
src/math/mat2x2.hpp
Normal file
207
src/math/mat2x2.hpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 4 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat2x2()
|
||||||
|
: x1_1(0), x1_2(0), x2_1(0), x2_2(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1>
|
||||||
|
constexpr mat2x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector2 V0, RowVector2 V1>
|
||||||
|
constexpr mat2x2(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector2 V0, ColumnVector2 V1>
|
||||||
|
constexpr mat2x2(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat2x2<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x2<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec2 -> vec2
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat2x2 -> mat2x2
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat2x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x3 -> mat2x3
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x4 -> mat2x4
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat2x2<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec2<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec2<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat2x2
|
||||||
|
|
||||||
|
using mat2x2f = mat2x2<float>;
|
||||||
|
using mat2x2d = mat2x2<double>;
|
||||||
|
using mat2x2i = mat2x2<int>;
|
||||||
|
using mat2x2u = mat2x2<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat2x2<mat2x2<int>>, "mat2x2<int> does not satisfy the concept Mat2x2");
|
||||||
|
} // namespace gz
|
4559
src/math/mat2x2.tpp
Normal file
4559
src/math/mat2x2.tpp
Normal file
File diff suppressed because it is too large
Load Diff
350
src/math/mat2x3.cpp
Normal file
350
src/math/mat2x3.cpp
Normal file
@ -0,0 +1,350 @@
|
|||||||
|
#include "mat2x3.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat2x3
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::operator=(const mat2x3<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator+(const M& other) const {
|
||||||
|
return mat2x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator-(const M& other) const {
|
||||||
|
return mat2x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator%(const M& other) const {
|
||||||
|
return mat2x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat2x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat2x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void mat2x3<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void mat2x3<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void mat2x3<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void mat2x3<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void mat2x3<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator+(const N& other) const {
|
||||||
|
return mat2x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator-(const N& other) const {
|
||||||
|
return mat2x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator%(const N& other) const {
|
||||||
|
return mat2x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat2x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat2x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x3<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec2<T> mat2x3<T>::operator*(const C& other) const {
|
||||||
|
vec2<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x3<T>::operator*(const M& other) const {
|
||||||
|
mat2x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x3<T>::operator*(const M& other) const {
|
||||||
|
mat2x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x3<T>::operator*(const M& other) const {
|
||||||
|
mat2x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool mat2x3<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x3<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat2x3<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x3<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x3<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat2x3<T>::dot(const mat2x3<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x3<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x3<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 2 + col * 3) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec3<T> mat2x3<T>::row(std::size_t i) const {
|
||||||
|
return rvec3<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec2<T> mat2x3<T>::column(std::size_t i) const {
|
||||||
|
return vec2<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x3<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x3<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x3<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x3<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat2x3.tpp"
|
217
src/math/mat2x3.hpp
Normal file
217
src/math/mat2x3.hpp
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 6 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat2x3()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2>
|
||||||
|
constexpr mat2x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector3 V0, RowVector3 V1>
|
||||||
|
constexpr mat2x3(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector2 V0, ColumnVector2 V1, ColumnVector2 V2>
|
||||||
|
constexpr mat2x3(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat2x3<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat2x3<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x3<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec3 -> vec2
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec2<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat3x2 -> mat2x2
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat2x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x3 -> mat2x3
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat2x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x4 -> mat2x4
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat2x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat2x3<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec3<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec2<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat2x3
|
||||||
|
|
||||||
|
using mat2x3f = mat2x3<float>;
|
||||||
|
using mat2x3d = mat2x3<double>;
|
||||||
|
using mat2x3i = mat2x3<int>;
|
||||||
|
using mat2x3u = mat2x3<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat2x3<mat2x3<int>>, "mat2x3<int> does not satisfy the concept Mat2x3");
|
||||||
|
} // namespace gz
|
4559
src/math/mat2x3.tpp
Normal file
4559
src/math/mat2x3.tpp
Normal file
File diff suppressed because it is too large
Load Diff
374
src/math/mat2x4.cpp
Normal file
374
src/math/mat2x4.cpp
Normal file
@ -0,0 +1,374 @@
|
|||||||
|
#include "mat2x4.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat2x4
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::operator=(const mat2x4<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x1_4 = static_cast<T>(other.x1_4);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
x2_4 = static_cast<T>(other.x2_4);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x1_4 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
x2_4 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator+(const M& other) const {
|
||||||
|
return mat2x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator-(const M& other) const {
|
||||||
|
return mat2x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator%(const M& other) const {
|
||||||
|
return mat2x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat2x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat2x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void mat2x4<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x1_4 += static_cast<T>(other.x1_4);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
x2_4 += static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void mat2x4<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 -= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 -= static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void mat2x4<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 %= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 %= static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void mat2x4<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 *= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 *= static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void mat2x4<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 /= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 /= static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator+(const N& other) const {
|
||||||
|
return mat2x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator-(const N& other) const {
|
||||||
|
return mat2x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator%(const N& other) const {
|
||||||
|
return mat2x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat2x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat2x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x1_4 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
x2_4 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x1_4 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
x2_4 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x1_4 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
x2_4 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x1_4 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
x2_4 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat2x4<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x1_4 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
x2_4 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec2<T> mat2x4<T>::operator*(const C& other) const {
|
||||||
|
vec2<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat2x2<T> mat2x4<T>::operator*(const M& other) const {
|
||||||
|
mat2x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat2x3<T> mat2x4<T>::operator*(const M& other) const {
|
||||||
|
mat2x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat2x4<T> mat2x4<T>::operator*(const M& other) const {
|
||||||
|
mat2x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool mat2x4<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat2x4<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat2x4<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x4<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat2x4<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat2x4<T>::dot(const mat2x4<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x4<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat2x4<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 2 + col * 4) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec4<T> mat2x4<T>::row(std::size_t i) const {
|
||||||
|
return rvec4<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)), *(&x1_1 + (2 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec2<T> mat2x4<T>::column(std::size_t i) const {
|
||||||
|
return vec2<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x4<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x4<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x4<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat2x4<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x2_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat2x4.tpp"
|
219
src/math/mat2x4.hpp
Normal file
219
src/math/mat2x4.hpp
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 8 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat2x4()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3>
|
||||||
|
constexpr mat2x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector4 V0, RowVector4 V1>
|
||||||
|
constexpr mat2x4(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector2 V0, ColumnVector2 V1, ColumnVector2 V2, ColumnVector2 V3>
|
||||||
|
constexpr mat2x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x1_4;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
T x2_4;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat2x4<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat2x4<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat2x4<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec4 -> vec2
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec2<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat4x2 -> mat2x2
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat2x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x3 -> mat2x3
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat2x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x4 -> mat2x4
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat2x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat2x4<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec4<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec2<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat2x4
|
||||||
|
|
||||||
|
using mat2x4f = mat2x4<float>;
|
||||||
|
using mat2x4d = mat2x4<double>;
|
||||||
|
using mat2x4i = mat2x4<int>;
|
||||||
|
using mat2x4u = mat2x4<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat2x4<mat2x4<int>>, "mat2x4<int> does not satisfy the concept Mat2x4");
|
||||||
|
} // namespace gz
|
4559
src/math/mat2x4.tpp
Normal file
4559
src/math/mat2x4.tpp
Normal file
File diff suppressed because it is too large
Load Diff
360
src/math/mat3x2.cpp
Normal file
360
src/math/mat3x2.cpp
Normal file
@ -0,0 +1,360 @@
|
|||||||
|
#include "mat3x2.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat3x2
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::operator=(const mat3x2<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator+(const M& other) const {
|
||||||
|
return mat3x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator-(const M& other) const {
|
||||||
|
return mat3x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator%(const M& other) const {
|
||||||
|
return mat3x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat3x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat3x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void mat3x2<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void mat3x2<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void mat3x2<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void mat3x2<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void mat3x2<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator+(const N& other) const {
|
||||||
|
return mat3x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator-(const N& other) const {
|
||||||
|
return mat3x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator%(const N& other) const {
|
||||||
|
return mat3x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat3x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat3x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x2<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec3<T> mat3x2<T>::operator*(const C& other) const {
|
||||||
|
vec3<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x2<T>::operator*(const M& other) const {
|
||||||
|
mat3x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x2<T>::operator*(const M& other) const {
|
||||||
|
mat3x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x2<T>::operator*(const M& other) const {
|
||||||
|
mat3x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool mat3x2<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x2<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat3x2<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x2<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x2<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat3x2<T>::dot(const mat3x2<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x2<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x2<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 3 + col * 2) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec2<T> mat3x2<T>::row(std::size_t i) const {
|
||||||
|
return rvec2<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec3<T> mat3x2<T>::column(std::size_t i) const {
|
||||||
|
return vec3<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x2<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x2<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x2<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x2<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat3x2.tpp"
|
217
src/math/mat3x2.hpp
Normal file
217
src/math/mat3x2.hpp
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 6 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat3x2()
|
||||||
|
: x1_1(0), x1_2(0), x2_1(0), x2_2(0), x3_1(0), x3_2(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1, Number N2_0, Number N2_1>
|
||||||
|
constexpr mat3x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2, const N2_0 x3_1, const N2_1 x3_2)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector2 V0, RowVector2 V1, RowVector2 V2>
|
||||||
|
constexpr mat3x2(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector3 V0, ColumnVector3 V1>
|
||||||
|
constexpr mat3x2(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat3x2<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x2<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec2 -> vec3
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec3<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat2x2 -> mat3x2
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat3x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x3 -> mat3x3
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat3x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x4 -> mat3x4
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat3x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat3x2<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec2<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec3<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat3x2
|
||||||
|
|
||||||
|
using mat3x2f = mat3x2<float>;
|
||||||
|
using mat3x2d = mat3x2<double>;
|
||||||
|
using mat3x2i = mat3x2<int>;
|
||||||
|
using mat3x2u = mat3x2<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat3x2<mat3x2<int>>, "mat3x2<int> does not satisfy the concept Mat3x2");
|
||||||
|
} // namespace gz
|
4559
src/math/mat3x2.tpp
Normal file
4559
src/math/mat3x2.tpp
Normal file
File diff suppressed because it is too large
Load Diff
392
src/math/mat3x3.cpp
Normal file
392
src/math/mat3x3.cpp
Normal file
@ -0,0 +1,392 @@
|
|||||||
|
#include "mat3x3.hpp"
|
||||||
|
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat3x3
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::operator=(const mat3x3<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
x3_3 = static_cast<T>(other.x3_3);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
x3_3 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator+(const M& other) const {
|
||||||
|
return mat3x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator-(const M& other) const {
|
||||||
|
return mat3x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator%(const M& other) const {
|
||||||
|
return mat3x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat3x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat3x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void mat3x3<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
x3_3 += static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void mat3x3<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 -= static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void mat3x3<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 %= static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void mat3x3<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 *= static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void mat3x3<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 /= static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator+(const N& other) const {
|
||||||
|
return mat3x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator-(const N& other) const {
|
||||||
|
return mat3x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator%(const N& other) const {
|
||||||
|
return mat3x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat3x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat3x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
x3_3 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
x3_3 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
x3_3 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
x3_3 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x3<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
x3_3 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> mat3x3<T>::operator*(const C& other) const {
|
||||||
|
vec3<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x3<T>::operator*(const M& other) const {
|
||||||
|
mat3x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x3<T>::operator*(const M& other) const {
|
||||||
|
mat3x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x3<T>::operator*(const M& other) const {
|
||||||
|
mat3x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool mat3x3<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x3<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat3x3<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x3<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x3<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat3x3<T>::dot(const mat3x3<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x3<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x3<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 3 + col * 3) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec3<T> mat3x3<T>::row(std::size_t i) const {
|
||||||
|
return rvec3<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec3<T> mat3x3<T>::column(std::size_t i) const {
|
||||||
|
return vec3<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x3<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x3<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x3<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x3<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat3x3.tpp"
|
212
src/math/mat3x3.hpp
Normal file
212
src/math/mat3x3.hpp
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 9 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat3x3()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0), x3_1(0), x3_2(0), x3_3(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2, Number N2_0, Number N2_1, Number N2_2>
|
||||||
|
constexpr mat3x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector3 V0, RowVector3 V1, RowVector3 V2>
|
||||||
|
constexpr mat3x3(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector3 V0, ColumnVector3 V1, ColumnVector3 V2>
|
||||||
|
constexpr mat3x3(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
T x3_3;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat3x3<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x3<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec3 -> vec3
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat3x2 -> mat3x2
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat3x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x3 -> mat3x3
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat3x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x4 -> mat3x4
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat3x3<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec3<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec3<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat3x3
|
||||||
|
|
||||||
|
using mat3x3f = mat3x3<float>;
|
||||||
|
using mat3x3d = mat3x3<double>;
|
||||||
|
using mat3x3i = mat3x3<int>;
|
||||||
|
using mat3x3u = mat3x3<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat3x3<mat3x3<int>>, "mat3x3<int> does not satisfy the concept Mat3x3");
|
||||||
|
} // namespace gz
|
4559
src/math/mat3x3.tpp
Normal file
4559
src/math/mat3x3.tpp
Normal file
File diff suppressed because it is too large
Load Diff
432
src/math/mat3x4.cpp
Normal file
432
src/math/mat3x4.cpp
Normal file
@ -0,0 +1,432 @@
|
|||||||
|
#include "mat3x4.hpp"
|
||||||
|
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat3x4
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::operator=(const mat3x4<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x1_4 = static_cast<T>(other.x1_4);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
x2_4 = static_cast<T>(other.x2_4);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
x3_3 = static_cast<T>(other.x3_3);
|
||||||
|
x3_4 = static_cast<T>(other.x3_4);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x1_4 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
x2_4 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
x3_3 = static_cast<T>(other);
|
||||||
|
x3_4 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator+(const M& other) const {
|
||||||
|
return mat3x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x3_4 + static_cast<T>(other.x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator-(const M& other) const {
|
||||||
|
return mat3x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x3_4 - static_cast<T>(other.x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator%(const M& other) const {
|
||||||
|
return mat3x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x3_4 % static_cast<T>(other.x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat3x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x3_4 * static_cast<T>(other.x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat3x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x3_4 / static_cast<T>(other.x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void mat3x4<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x1_4 += static_cast<T>(other.x1_4);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
x2_4 += static_cast<T>(other.x2_4);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
x3_3 += static_cast<T>(other.x3_3);
|
||||||
|
x3_4 += static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void mat3x4<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 -= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 -= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 -= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 -= static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void mat3x4<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 %= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 %= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 %= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 %= static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void mat3x4<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 *= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 *= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 *= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 *= static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void mat3x4<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 /= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 /= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 /= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 /= static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator+(const N& other) const {
|
||||||
|
return mat3x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x3_4 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator-(const N& other) const {
|
||||||
|
return mat3x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x3_4 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator%(const N& other) const {
|
||||||
|
return mat3x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x3_4 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat3x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x3_4 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat3x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x3_4 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x1_4 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
x2_4 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
x3_3 += static_cast<T>(other);
|
||||||
|
x3_4 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x1_4 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
x2_4 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
x3_3 -= static_cast<T>(other);
|
||||||
|
x3_4 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x1_4 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
x2_4 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
x3_3 %= static_cast<T>(other);
|
||||||
|
x3_4 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x1_4 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
x2_4 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
x3_3 *= static_cast<T>(other);
|
||||||
|
x3_4 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat3x4<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x1_4 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
x2_4 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
x3_3 /= static_cast<T>(other);
|
||||||
|
x3_4 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec3<T> mat3x4<T>::operator*(const C& other) const {
|
||||||
|
vec3<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z + x3_4 * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat3x2<T> mat3x4<T>::operator*(const M& other) const {
|
||||||
|
mat3x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat3x3<T> mat3x4<T>::operator*(const M& other) const {
|
||||||
|
mat3x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat3x4<T> mat3x4<T>::operator*(const M& other) const {
|
||||||
|
mat3x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4 + x3_4 * other.x4_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool mat3x4<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat3x4<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat3x4<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x3_4 * x3_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x4<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat3x4<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat3x4<T>::dot(const mat3x4<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x3_4 * static_cast<T>(other.x3_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x4<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat3x4<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 3 + col * 4) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec4<T> mat3x4<T>::row(std::size_t i) const {
|
||||||
|
return rvec4<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)), *(&x1_1 + (3 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec3<T> mat3x4<T>::column(std::size_t i) const {
|
||||||
|
return vec3<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x4<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x4<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x4<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat3x4<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x3_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat3x4.tpp"
|
223
src/math/mat3x4.hpp
Normal file
223
src/math/mat3x4.hpp
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 12 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat3x4()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0), x3_1(0), x3_2(0), x3_3(0), x3_4(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x3_4(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3, Number N2_0, Number N2_1, Number N2_2, Number N2_3>
|
||||||
|
constexpr mat3x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N2_3 x3_4)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x3_4(static_cast<T>(x3_4)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector4 V0, RowVector4 V1, RowVector4 V2>
|
||||||
|
constexpr mat3x4(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v2.w)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector3 V0, ColumnVector3 V1, ColumnVector3 V2, ColumnVector3 V3>
|
||||||
|
constexpr mat3x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v3.z)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x1_4;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
T x2_4;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
T x3_3;
|
||||||
|
T x3_4;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat3x4<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat3x4<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat3x4<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec4 -> vec3
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec3<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat4x2 -> mat3x2
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat3x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x3 -> mat3x3
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat3x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x4 -> mat3x4
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat3x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat3x4<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec4<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec3<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat3x4
|
||||||
|
|
||||||
|
using mat3x4f = mat3x4<float>;
|
||||||
|
using mat3x4d = mat3x4<double>;
|
||||||
|
using mat3x4i = mat3x4<int>;
|
||||||
|
using mat3x4u = mat3x4<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat3x4<mat3x4<int>>, "mat3x4<int> does not satisfy the concept Mat3x4");
|
||||||
|
} // namespace gz
|
4559
src/math/mat3x4.tpp
Normal file
4559
src/math/mat3x4.tpp
Normal file
File diff suppressed because it is too large
Load Diff
394
src/math/mat4x2.cpp
Normal file
394
src/math/mat4x2.cpp
Normal file
@ -0,0 +1,394 @@
|
|||||||
|
#include "mat4x2.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat4x2
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::operator=(const mat4x2<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
x4_1 = static_cast<T>(other.x4_1);
|
||||||
|
x4_2 = static_cast<T>(other.x4_2);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
x4_1 = static_cast<T>(other);
|
||||||
|
x4_2 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator+(const M& other) const {
|
||||||
|
return mat4x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator-(const M& other) const {
|
||||||
|
return mat4x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator%(const M& other) const {
|
||||||
|
return mat4x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat4x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat4x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void mat4x2<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
x4_1 += static_cast<T>(other.x4_1);
|
||||||
|
x4_2 += static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void mat4x2<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
x4_1 -= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 -= static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void mat4x2<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
x4_1 %= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 %= static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void mat4x2<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
x4_1 *= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 *= static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void mat4x2<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
x4_1 /= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 /= static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator+(const N& other) const {
|
||||||
|
return mat4x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator-(const N& other) const {
|
||||||
|
return mat4x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator%(const N& other) const {
|
||||||
|
return mat4x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat4x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat4x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
x4_1 += static_cast<T>(other);
|
||||||
|
x4_2 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
x4_1 -= static_cast<T>(other);
|
||||||
|
x4_2 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
x4_1 %= static_cast<T>(other);
|
||||||
|
x4_2 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
x4_1 *= static_cast<T>(other);
|
||||||
|
x4_2 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x2<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
x4_1 /= static_cast<T>(other);
|
||||||
|
x4_2 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec4<T> mat4x2<T>::operator*(const C& other) const {
|
||||||
|
vec4<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y;
|
||||||
|
new_.w = x4_1 * other.x + x4_2 * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x2<T>::operator*(const M& other) const {
|
||||||
|
mat4x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x2<T>::operator*(const M& other) const {
|
||||||
|
mat4x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x2<T>::operator*(const M& other) const {
|
||||||
|
mat4x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3;
|
||||||
|
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x4_1 == other.x4_1 and x4_2 == other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x4_1 < other.x4_1 and x4_2 < other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x4_1 > other.x4_1 and x4_2 > other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x4_1 == other.x4_1 and x4_2 == other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x4_1 > other.x4_1 and x4_2 > other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool mat4x2<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x4_1 < other.x4_1 and x4_2 < other.x4_2;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other and x4_1 == other and x4_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other and x4_1 < other and x4_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other and x4_1 > other and x4_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other and x4_1 == other and x4_2 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other and x4_1 > other and x4_2 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x2<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other and x4_1 < other and x4_2 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat4x2<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x2<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x2<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat4x2<T>::dot(const mat4x2<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x2<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x2<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 4 + col * 2) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec2<T> mat4x2<T>::row(std::size_t i) const {
|
||||||
|
return rvec2<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec4<T> mat4x2<T>::column(std::size_t i) const {
|
||||||
|
return vec4<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)), *(&x1_1 + (2 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x2<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x2<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x2<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x2<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_2 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat4x2.tpp"
|
219
src/math/mat4x2.hpp
Normal file
219
src/math/mat4x2.hpp
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 8 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat4x2()
|
||||||
|
: x1_1(0), x1_2(0), x2_1(0), x2_2(0), x3_1(0), x3_2(0), x4_1(0), x4_2(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1, Number N2_0, Number N2_1, Number N3_0, Number N3_1>
|
||||||
|
constexpr mat4x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2, const N2_0 x3_1, const N2_1 x3_2, const N3_0 x4_1, const N3_1 x4_2)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector2 V0, RowVector2 V1, RowVector2 V2, RowVector2 V3>
|
||||||
|
constexpr mat4x2(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector4 V0, ColumnVector4 V1>
|
||||||
|
constexpr mat4x2(const V0& v0, const V1& v1)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
T x4_1;
|
||||||
|
T x4_2;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat4x2<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x2<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec2 -> vec4
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec4<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat2x2 -> mat4x2
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr mat4x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x3 -> mat4x3
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr mat4x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x4 -> mat4x4
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr mat4x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat4x2<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec2<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec4<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat4x2
|
||||||
|
|
||||||
|
using mat4x2f = mat4x2<float>;
|
||||||
|
using mat4x2d = mat4x2<double>;
|
||||||
|
using mat4x2i = mat4x2<int>;
|
||||||
|
using mat4x2u = mat4x2<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat4x2<mat4x2<int>>, "mat4x2<int> does not satisfy the concept Mat4x2");
|
||||||
|
} // namespace gz
|
4559
src/math/mat4x2.tpp
Normal file
4559
src/math/mat4x2.tpp
Normal file
File diff suppressed because it is too large
Load Diff
442
src/math/mat4x3.cpp
Normal file
442
src/math/mat4x3.cpp
Normal file
@ -0,0 +1,442 @@
|
|||||||
|
#include "mat4x3.hpp"
|
||||||
|
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat4x3
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::operator=(const mat4x3<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
x3_3 = static_cast<T>(other.x3_3);
|
||||||
|
x4_1 = static_cast<T>(other.x4_1);
|
||||||
|
x4_2 = static_cast<T>(other.x4_2);
|
||||||
|
x4_3 = static_cast<T>(other.x4_3);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
x3_3 = static_cast<T>(other);
|
||||||
|
x4_1 = static_cast<T>(other);
|
||||||
|
x4_2 = static_cast<T>(other);
|
||||||
|
x4_3 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator+(const M& other) const {
|
||||||
|
return mat4x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2), x4_3 + static_cast<T>(other.x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator-(const M& other) const {
|
||||||
|
return mat4x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2), x4_3 - static_cast<T>(other.x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator%(const M& other) const {
|
||||||
|
return mat4x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2), x4_3 % static_cast<T>(other.x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat4x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2), x4_3 * static_cast<T>(other.x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat4x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2), x4_3 / static_cast<T>(other.x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void mat4x3<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
x3_3 += static_cast<T>(other.x3_3);
|
||||||
|
x4_1 += static_cast<T>(other.x4_1);
|
||||||
|
x4_2 += static_cast<T>(other.x4_2);
|
||||||
|
x4_3 += static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void mat4x3<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 -= static_cast<T>(other.x3_3);
|
||||||
|
x4_1 -= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 -= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 -= static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void mat4x3<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 %= static_cast<T>(other.x3_3);
|
||||||
|
x4_1 %= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 %= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 %= static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void mat4x3<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 *= static_cast<T>(other.x3_3);
|
||||||
|
x4_1 *= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 *= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 *= static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void mat4x3<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 /= static_cast<T>(other.x3_3);
|
||||||
|
x4_1 /= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 /= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 /= static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator+(const N& other) const {
|
||||||
|
return mat4x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other), x4_3 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator-(const N& other) const {
|
||||||
|
return mat4x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other), x4_3 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator%(const N& other) const {
|
||||||
|
return mat4x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other), x4_3 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat4x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other), x4_3 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat4x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other), x4_3 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
x3_3 += static_cast<T>(other);
|
||||||
|
x4_1 += static_cast<T>(other);
|
||||||
|
x4_2 += static_cast<T>(other);
|
||||||
|
x4_3 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
x3_3 -= static_cast<T>(other);
|
||||||
|
x4_1 -= static_cast<T>(other);
|
||||||
|
x4_2 -= static_cast<T>(other);
|
||||||
|
x4_3 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
x3_3 %= static_cast<T>(other);
|
||||||
|
x4_1 %= static_cast<T>(other);
|
||||||
|
x4_2 %= static_cast<T>(other);
|
||||||
|
x4_3 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
x3_3 *= static_cast<T>(other);
|
||||||
|
x4_1 *= static_cast<T>(other);
|
||||||
|
x4_2 *= static_cast<T>(other);
|
||||||
|
x4_3 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x3<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
x3_3 /= static_cast<T>(other);
|
||||||
|
x4_1 /= static_cast<T>(other);
|
||||||
|
x4_2 /= static_cast<T>(other);
|
||||||
|
x4_3 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec4<T> mat4x3<T>::operator*(const C& other) const {
|
||||||
|
vec4<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z;
|
||||||
|
new_.w = x4_1 * other.x + x4_2 * other.y + x4_3 * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x3<T>::operator*(const M& other) const {
|
||||||
|
mat4x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x3<T>::operator*(const M& other) const {
|
||||||
|
mat4x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x3<T>::operator*(const M& other) const {
|
||||||
|
mat4x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3;
|
||||||
|
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4 + x4_3 * other.x3_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool mat4x3<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other and x4_1 == other and x4_2 == other and x4_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other and x4_1 < other and x4_2 < other and x4_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other and x4_1 > other and x4_2 > other and x4_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other and x4_1 == other and x4_2 == other and x4_3 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other and x4_1 > other and x4_2 > other and x4_3 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x3<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other and x4_1 < other and x4_2 < other and x4_3 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat4x3<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2) + static_cast<float>(x4_3 * x4_3));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x3<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x3<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat4x3<T>::dot(const mat4x3<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2) + x4_3 * static_cast<T>(other.x4_3);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x3<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x3<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 4 + col * 3) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec3<T> mat4x3<T>::row(std::size_t i) const {
|
||||||
|
return rvec3<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec4<T> mat4x3<T>::column(std::size_t i) const {
|
||||||
|
return vec4<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)), *(&x1_1 + (3 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x3<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x3<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x3<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x3<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_3 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat4x3.tpp"
|
223
src/math/mat4x3.hpp
Normal file
223
src/math/mat4x3.hpp
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 12 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat4x3()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0), x3_1(0), x3_2(0), x3_3(0), x4_1(0), x4_2(0), x4_3(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)), x4_3(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2, Number N2_0, Number N2_1, Number N2_2, Number N3_0, Number N3_1, Number N3_2>
|
||||||
|
constexpr mat4x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N3_0 x4_1, const N3_1 x4_2, const N3_2 x4_3)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)), x4_3(static_cast<T>(x4_3)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector3 V0, RowVector3 V1, RowVector3 V2, RowVector3 V3>
|
||||||
|
constexpr mat4x3(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)), x4_3(static_cast<T>(v3.z)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector4 V0, ColumnVector4 V1, ColumnVector4 V2>
|
||||||
|
constexpr mat4x3(const V0& v0, const V1& v1, const V2& v2)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)), x4_3(static_cast<T>(v2.w)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
T x3_3;
|
||||||
|
T x4_1;
|
||||||
|
T x4_2;
|
||||||
|
T x4_3;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat4x3<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x3<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec3 -> vec4
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec4<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat3x2 -> mat4x2
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr mat4x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x3 -> mat4x3
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr mat4x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x4 -> mat4x4
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr mat4x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat4x3<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec3<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec4<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat4x3
|
||||||
|
|
||||||
|
using mat4x3f = mat4x3<float>;
|
||||||
|
using mat4x3d = mat4x3<double>;
|
||||||
|
using mat4x3i = mat4x3<int>;
|
||||||
|
using mat4x3u = mat4x3<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat4x3<mat4x3<int>>, "mat4x3<int> does not satisfy the concept Mat4x3");
|
||||||
|
} // namespace gz
|
4559
src/math/mat4x3.tpp
Normal file
4559
src/math/mat4x3.tpp
Normal file
File diff suppressed because it is too large
Load Diff
486
src/math/mat4x4.cpp
Normal file
486
src/math/mat4x4.cpp
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
#include "mat4x4.hpp"
|
||||||
|
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS mat4x4
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::operator=(const mat4x4<N>& other) {
|
||||||
|
x1_1 = static_cast<T>(other.x1_1);
|
||||||
|
x1_2 = static_cast<T>(other.x1_2);
|
||||||
|
x1_3 = static_cast<T>(other.x1_3);
|
||||||
|
x1_4 = static_cast<T>(other.x1_4);
|
||||||
|
x2_1 = static_cast<T>(other.x2_1);
|
||||||
|
x2_2 = static_cast<T>(other.x2_2);
|
||||||
|
x2_3 = static_cast<T>(other.x2_3);
|
||||||
|
x2_4 = static_cast<T>(other.x2_4);
|
||||||
|
x3_1 = static_cast<T>(other.x3_1);
|
||||||
|
x3_2 = static_cast<T>(other.x3_2);
|
||||||
|
x3_3 = static_cast<T>(other.x3_3);
|
||||||
|
x3_4 = static_cast<T>(other.x3_4);
|
||||||
|
x4_1 = static_cast<T>(other.x4_1);
|
||||||
|
x4_2 = static_cast<T>(other.x4_2);
|
||||||
|
x4_3 = static_cast<T>(other.x4_3);
|
||||||
|
x4_4 = static_cast<T>(other.x4_4);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::operator=(const N& other) {
|
||||||
|
x1_1 = static_cast<T>(other);
|
||||||
|
x1_2 = static_cast<T>(other);
|
||||||
|
x1_3 = static_cast<T>(other);
|
||||||
|
x1_4 = static_cast<T>(other);
|
||||||
|
x2_1 = static_cast<T>(other);
|
||||||
|
x2_2 = static_cast<T>(other);
|
||||||
|
x2_3 = static_cast<T>(other);
|
||||||
|
x2_4 = static_cast<T>(other);
|
||||||
|
x3_1 = static_cast<T>(other);
|
||||||
|
x3_2 = static_cast<T>(other);
|
||||||
|
x3_3 = static_cast<T>(other);
|
||||||
|
x3_4 = static_cast<T>(other);
|
||||||
|
x4_1 = static_cast<T>(other);
|
||||||
|
x4_2 = static_cast<T>(other);
|
||||||
|
x4_3 = static_cast<T>(other);
|
||||||
|
x4_4 = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator+(const M& other) const {
|
||||||
|
return mat4x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x3_4 + static_cast<T>(other.x3_4), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2), x4_3 + static_cast<T>(other.x4_3), x4_4 + static_cast<T>(other.x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator-(const M& other) const {
|
||||||
|
return mat4x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x3_4 - static_cast<T>(other.x3_4), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2), x4_3 - static_cast<T>(other.x4_3), x4_4 - static_cast<T>(other.x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator%(const M& other) const {
|
||||||
|
return mat4x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x3_4 % static_cast<T>(other.x3_4), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2), x4_3 % static_cast<T>(other.x4_3), x4_4 % static_cast<T>(other.x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::compWiseMult(const M& other) const {
|
||||||
|
return mat4x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x3_4 * static_cast<T>(other.x3_4), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2), x4_3 * static_cast<T>(other.x4_3), x4_4 * static_cast<T>(other.x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::compWiseDiv(const M& other) const {
|
||||||
|
return mat4x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x3_4 / static_cast<T>(other.x3_4), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2), x4_3 / static_cast<T>(other.x4_3), x4_4 / static_cast<T>(other.x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void mat4x4<T>::operator+=(const M& other) {
|
||||||
|
x1_1 += static_cast<T>(other.x1_1);
|
||||||
|
x1_2 += static_cast<T>(other.x1_2);
|
||||||
|
x1_3 += static_cast<T>(other.x1_3);
|
||||||
|
x1_4 += static_cast<T>(other.x1_4);
|
||||||
|
x2_1 += static_cast<T>(other.x2_1);
|
||||||
|
x2_2 += static_cast<T>(other.x2_2);
|
||||||
|
x2_3 += static_cast<T>(other.x2_3);
|
||||||
|
x2_4 += static_cast<T>(other.x2_4);
|
||||||
|
x3_1 += static_cast<T>(other.x3_1);
|
||||||
|
x3_2 += static_cast<T>(other.x3_2);
|
||||||
|
x3_3 += static_cast<T>(other.x3_3);
|
||||||
|
x3_4 += static_cast<T>(other.x3_4);
|
||||||
|
x4_1 += static_cast<T>(other.x4_1);
|
||||||
|
x4_2 += static_cast<T>(other.x4_2);
|
||||||
|
x4_3 += static_cast<T>(other.x4_3);
|
||||||
|
x4_4 += static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void mat4x4<T>::operator-=(const M& other) {
|
||||||
|
x1_1 -= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 -= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 -= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 -= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 -= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 -= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 -= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 -= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 -= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 -= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 -= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 -= static_cast<T>(other.x3_4);
|
||||||
|
x4_1 -= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 -= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 -= static_cast<T>(other.x4_3);
|
||||||
|
x4_4 -= static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void mat4x4<T>::operator%=(const M& other) {
|
||||||
|
x1_1 %= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 %= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 %= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 %= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 %= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 %= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 %= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 %= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 %= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 %= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 %= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 %= static_cast<T>(other.x3_4);
|
||||||
|
x4_1 %= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 %= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 %= static_cast<T>(other.x4_3);
|
||||||
|
x4_4 %= static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void mat4x4<T>::compWiseAssMult(const M& other) {
|
||||||
|
x1_1 *= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 *= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 *= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 *= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 *= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 *= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 *= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 *= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 *= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 *= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 *= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 *= static_cast<T>(other.x3_4);
|
||||||
|
x4_1 *= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 *= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 *= static_cast<T>(other.x4_3);
|
||||||
|
x4_4 *= static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void mat4x4<T>::compWiseAssDiv(const M& other) {
|
||||||
|
x1_1 /= static_cast<T>(other.x1_1);
|
||||||
|
x1_2 /= static_cast<T>(other.x1_2);
|
||||||
|
x1_3 /= static_cast<T>(other.x1_3);
|
||||||
|
x1_4 /= static_cast<T>(other.x1_4);
|
||||||
|
x2_1 /= static_cast<T>(other.x2_1);
|
||||||
|
x2_2 /= static_cast<T>(other.x2_2);
|
||||||
|
x2_3 /= static_cast<T>(other.x2_3);
|
||||||
|
x2_4 /= static_cast<T>(other.x2_4);
|
||||||
|
x3_1 /= static_cast<T>(other.x3_1);
|
||||||
|
x3_2 /= static_cast<T>(other.x3_2);
|
||||||
|
x3_3 /= static_cast<T>(other.x3_3);
|
||||||
|
x3_4 /= static_cast<T>(other.x3_4);
|
||||||
|
x4_1 /= static_cast<T>(other.x4_1);
|
||||||
|
x4_2 /= static_cast<T>(other.x4_2);
|
||||||
|
x4_3 /= static_cast<T>(other.x4_3);
|
||||||
|
x4_4 /= static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator+(const N& other) const {
|
||||||
|
return mat4x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x3_4 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other), x4_3 + static_cast<T>(other), x4_4 + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator-(const N& other) const {
|
||||||
|
return mat4x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x3_4 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other), x4_3 - static_cast<T>(other), x4_4 - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator%(const N& other) const {
|
||||||
|
return mat4x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x3_4 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other), x4_3 % static_cast<T>(other), x4_4 % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::compWiseMult(const N& other) const {
|
||||||
|
return mat4x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x3_4 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other), x4_3 * static_cast<T>(other), x4_4 * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::compWiseDiv(const N& other) const {
|
||||||
|
return mat4x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x3_4 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other), x4_3 / static_cast<T>(other), x4_4 / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::operator+=(const N& other) {
|
||||||
|
x1_1 += static_cast<T>(other);
|
||||||
|
x1_2 += static_cast<T>(other);
|
||||||
|
x1_3 += static_cast<T>(other);
|
||||||
|
x1_4 += static_cast<T>(other);
|
||||||
|
x2_1 += static_cast<T>(other);
|
||||||
|
x2_2 += static_cast<T>(other);
|
||||||
|
x2_3 += static_cast<T>(other);
|
||||||
|
x2_4 += static_cast<T>(other);
|
||||||
|
x3_1 += static_cast<T>(other);
|
||||||
|
x3_2 += static_cast<T>(other);
|
||||||
|
x3_3 += static_cast<T>(other);
|
||||||
|
x3_4 += static_cast<T>(other);
|
||||||
|
x4_1 += static_cast<T>(other);
|
||||||
|
x4_2 += static_cast<T>(other);
|
||||||
|
x4_3 += static_cast<T>(other);
|
||||||
|
x4_4 += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::operator-=(const N& other) {
|
||||||
|
x1_1 -= static_cast<T>(other);
|
||||||
|
x1_2 -= static_cast<T>(other);
|
||||||
|
x1_3 -= static_cast<T>(other);
|
||||||
|
x1_4 -= static_cast<T>(other);
|
||||||
|
x2_1 -= static_cast<T>(other);
|
||||||
|
x2_2 -= static_cast<T>(other);
|
||||||
|
x2_3 -= static_cast<T>(other);
|
||||||
|
x2_4 -= static_cast<T>(other);
|
||||||
|
x3_1 -= static_cast<T>(other);
|
||||||
|
x3_2 -= static_cast<T>(other);
|
||||||
|
x3_3 -= static_cast<T>(other);
|
||||||
|
x3_4 -= static_cast<T>(other);
|
||||||
|
x4_1 -= static_cast<T>(other);
|
||||||
|
x4_2 -= static_cast<T>(other);
|
||||||
|
x4_3 -= static_cast<T>(other);
|
||||||
|
x4_4 -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::operator%=(const N& other) {
|
||||||
|
x1_1 %= static_cast<T>(other);
|
||||||
|
x1_2 %= static_cast<T>(other);
|
||||||
|
x1_3 %= static_cast<T>(other);
|
||||||
|
x1_4 %= static_cast<T>(other);
|
||||||
|
x2_1 %= static_cast<T>(other);
|
||||||
|
x2_2 %= static_cast<T>(other);
|
||||||
|
x2_3 %= static_cast<T>(other);
|
||||||
|
x2_4 %= static_cast<T>(other);
|
||||||
|
x3_1 %= static_cast<T>(other);
|
||||||
|
x3_2 %= static_cast<T>(other);
|
||||||
|
x3_3 %= static_cast<T>(other);
|
||||||
|
x3_4 %= static_cast<T>(other);
|
||||||
|
x4_1 %= static_cast<T>(other);
|
||||||
|
x4_2 %= static_cast<T>(other);
|
||||||
|
x4_3 %= static_cast<T>(other);
|
||||||
|
x4_4 %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::compWiseAssMult(const N& other) {
|
||||||
|
x1_1 *= static_cast<T>(other);
|
||||||
|
x1_2 *= static_cast<T>(other);
|
||||||
|
x1_3 *= static_cast<T>(other);
|
||||||
|
x1_4 *= static_cast<T>(other);
|
||||||
|
x2_1 *= static_cast<T>(other);
|
||||||
|
x2_2 *= static_cast<T>(other);
|
||||||
|
x2_3 *= static_cast<T>(other);
|
||||||
|
x2_4 *= static_cast<T>(other);
|
||||||
|
x3_1 *= static_cast<T>(other);
|
||||||
|
x3_2 *= static_cast<T>(other);
|
||||||
|
x3_3 *= static_cast<T>(other);
|
||||||
|
x3_4 *= static_cast<T>(other);
|
||||||
|
x4_1 *= static_cast<T>(other);
|
||||||
|
x4_2 *= static_cast<T>(other);
|
||||||
|
x4_3 *= static_cast<T>(other);
|
||||||
|
x4_4 *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void mat4x4<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x1_1 /= static_cast<T>(other);
|
||||||
|
x1_2 /= static_cast<T>(other);
|
||||||
|
x1_3 /= static_cast<T>(other);
|
||||||
|
x1_4 /= static_cast<T>(other);
|
||||||
|
x2_1 /= static_cast<T>(other);
|
||||||
|
x2_2 /= static_cast<T>(other);
|
||||||
|
x2_3 /= static_cast<T>(other);
|
||||||
|
x2_4 /= static_cast<T>(other);
|
||||||
|
x3_1 /= static_cast<T>(other);
|
||||||
|
x3_2 /= static_cast<T>(other);
|
||||||
|
x3_3 /= static_cast<T>(other);
|
||||||
|
x3_4 /= static_cast<T>(other);
|
||||||
|
x4_1 /= static_cast<T>(other);
|
||||||
|
x4_2 /= static_cast<T>(other);
|
||||||
|
x4_3 /= static_cast<T>(other);
|
||||||
|
x4_4 /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> mat4x4<T>::operator*(const C& other) const {
|
||||||
|
vec4<T> new_;
|
||||||
|
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
||||||
|
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
||||||
|
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z + x3_4 * other.w;
|
||||||
|
new_.w = x4_1 * other.x + x4_2 * other.y + x4_3 * other.z + x4_4 * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> mat4x4<T>::operator*(const M& other) const {
|
||||||
|
mat4x2<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> mat4x4<T>::operator*(const M& other) const {
|
||||||
|
mat4x3<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3 + x4_4 * other.x4_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> mat4x4<T>::operator*(const M& other) const {
|
||||||
|
mat4x4<T> new_;
|
||||||
|
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
||||||
|
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
||||||
|
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
||||||
|
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
||||||
|
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
||||||
|
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
||||||
|
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
||||||
|
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
||||||
|
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
||||||
|
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
||||||
|
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
||||||
|
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4 + x3_4 * other.x4_4;
|
||||||
|
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
||||||
|
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
||||||
|
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3 + x4_4 * other.x4_3;
|
||||||
|
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4 + x4_3 * other.x3_4 + x4_4 * other.x4_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator==(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3 and x4_4 == other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator<(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3 and x4_4 < other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator>(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3 and x4_4 > other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator!=(const M& other) const {
|
||||||
|
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3 and x4_4 == other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator<=(const M& other) const {
|
||||||
|
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3 and x4_4 > other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool mat4x4<T>::operator>=(const M& other) const {
|
||||||
|
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3 and x4_4 < other.x4_4;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator==(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other and x4_1 == other and x4_2 == other and x4_3 == other and x4_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator<(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other and x4_1 < other and x4_2 < other and x4_3 < other and x4_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator>(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other and x4_1 > other and x4_2 > other and x4_3 > other and x4_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator!=(const N& other) const {
|
||||||
|
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other and x4_1 == other and x4_2 == other and x4_3 == other and x4_4 == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator<=(const N& other) const {
|
||||||
|
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other and x4_1 > other and x4_2 > other and x4_3 > other and x4_4 > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool mat4x4<T>::operator>=(const N& other) const {
|
||||||
|
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other and x4_1 < other and x4_2 < other and x4_3 < other and x4_4 < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float mat4x4<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x3_4 * x3_4) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2) + static_cast<float>(x4_3 * x4_3) + static_cast<float>(x4_4 * x4_4));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x4<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T mat4x4<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T mat4x4<T>::dot(const mat4x4<N>& other) const {
|
||||||
|
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x3_4 * static_cast<T>(other.x3_4) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2) + x4_3 * static_cast<T>(other.x4_3) + x4_4 * static_cast<T>(other.x4_4);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x4<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x1_1 + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T mat4x4<T>::at(std::size_t row, std::size_t col) const {
|
||||||
|
return *(&x1_1 + (row * 4 + col * 4) * sizeof(T));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr rvec4<T> mat4x4<T>::row(std::size_t i) const {
|
||||||
|
return rvec4<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)), *(&x1_1 + (4 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr vec4<T> mat4x4<T>::column(std::size_t i) const {
|
||||||
|
return vec4<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)), *(&x1_1 + (4 * 3 + i) * sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x4<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x4<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x4<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x1_1));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> mat4x4<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&x4_4 + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "mat4x4.tpp"
|
219
src/math/mat4x4.hpp
Normal file
219
src/math/mat4x4.hpp
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 16 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4 {
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr mat4x4()
|
||||||
|
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0), x3_1(0), x3_2(0), x3_3(0), x3_4(0), x4_1(0), x4_2(0), x4_3(0), x4_4(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4(const N n)
|
||||||
|
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x3_4(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)), x4_3(static_cast<T>(n)), x4_4(static_cast<T>(n)) {}
|
||||||
|
/// Create from scalars
|
||||||
|
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3, Number N2_0, Number N2_1, Number N2_2, Number N2_3, Number N3_0, Number N3_1, Number N3_2, Number N3_3>
|
||||||
|
constexpr mat4x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N2_3 x3_4, const N3_0 x4_1, const N3_1 x4_2, const N3_2 x4_3, const N3_3 x4_4)
|
||||||
|
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x3_4(static_cast<T>(x3_4)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)), x4_3(static_cast<T>(x4_3)), x4_4(static_cast<T>(x4_4)) {}
|
||||||
|
/// Create from row vectors
|
||||||
|
template<RowVector4 V0, RowVector4 V1, RowVector4 V2, RowVector4 V3>
|
||||||
|
constexpr mat4x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v2.w)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)), x4_3(static_cast<T>(v3.z)), x4_4(static_cast<T>(v3.w)) {}
|
||||||
|
/// Create from column vectors
|
||||||
|
template<ColumnVector4 V0, ColumnVector4 V1, ColumnVector4 V2, ColumnVector4 V3>
|
||||||
|
constexpr mat4x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
||||||
|
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v3.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)), x4_3(static_cast<T>(v2.w)), x4_4(static_cast<T>(v3.w)) {}
|
||||||
|
// Values
|
||||||
|
T x1_1;
|
||||||
|
T x1_2;
|
||||||
|
T x1_3;
|
||||||
|
T x1_4;
|
||||||
|
T x2_1;
|
||||||
|
T x2_2;
|
||||||
|
T x2_3;
|
||||||
|
T x2_4;
|
||||||
|
T x3_1;
|
||||||
|
T x3_2;
|
||||||
|
T x3_3;
|
||||||
|
T x3_4;
|
||||||
|
T x4_1;
|
||||||
|
T x4_2;
|
||||||
|
T x4_3;
|
||||||
|
T x4_4;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const mat4x4<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> operator+(const M& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> operator-(const M& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> operator%(const M& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> compWiseMult(const M& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> compWiseDiv(const M& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void operator+=(const M& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void operator-=(const M& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void operator%=(const M& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void compWiseAssMult(const M& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr void compWiseAssDiv(const M& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr mat4x4<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with vec4 -> vec4
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> operator*(const C& other) const;
|
||||||
|
/// Matrix multiplication with mat4x2 -> mat4x2
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr mat4x2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x3 -> mat4x3
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr mat4x3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x4 -> mat4x4
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr mat4x4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator==(const M& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator<(const M& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator>(const M& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator!=(const M& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator<=(const M& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr bool operator>=(const M& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const mat4x4<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Get the element at row and col. row and col start at 0
|
||||||
|
constexpr T at(std::size_t row, std::size_t col) const;
|
||||||
|
/// Get the ith row as column vector. i starts at 0
|
||||||
|
constexpr rvec4<T> row(std::size_t i) const;
|
||||||
|
/// Get the ith column as row vector. i starts at 0
|
||||||
|
constexpr vec4<T> column(std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // mat4x4
|
||||||
|
|
||||||
|
using mat4x4f = mat4x4<float>;
|
||||||
|
using mat4x4d = mat4x4<double>;
|
||||||
|
using mat4x4i = mat4x4<int>;
|
||||||
|
using mat4x4u = mat4x4<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(Mat4x4<mat4x4<int>>, "mat4x4<int> does not satisfy the concept Mat4x4");
|
||||||
|
} // namespace gz
|
4559
src/math/mat4x4.tpp
Normal file
4559
src/math/mat4x4.tpp
Normal file
File diff suppressed because it is too large
Load Diff
279
src/math/rvec2.cpp
Normal file
279
src/math/rvec2.cpp
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
#include "rvec2.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
#include "vec2.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS rvec2
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::operator=(const rvec2<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator+(const R& other) const {
|
||||||
|
return rvec2<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator-(const R& other) const {
|
||||||
|
return rvec2<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator%(const R& other) const {
|
||||||
|
return rvec2<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> rvec2<T>::compWiseMult(const R& other) const {
|
||||||
|
return rvec2<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> rvec2<T>::compWiseDiv(const R& other) const {
|
||||||
|
return rvec2<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void rvec2<T>::operator+=(const R& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void rvec2<T>::operator-=(const R& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void rvec2<T>::operator%=(const R& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void rvec2<T>::compWiseAssMult(const R& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void rvec2<T>::compWiseAssDiv(const R& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator+(const N& other) const {
|
||||||
|
return rvec2<T>(x + static_cast<T>(other), y + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator-(const N& other) const {
|
||||||
|
return rvec2<T>(x - static_cast<T>(other), y - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator%(const N& other) const {
|
||||||
|
return rvec2<T>(x % static_cast<T>(other), y % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> rvec2<T>::compWiseMult(const N& other) const {
|
||||||
|
return rvec2<T>(x * static_cast<T>(other), y * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> rvec2<T>::compWiseDiv(const N& other) const {
|
||||||
|
return rvec2<T>(x / static_cast<T>(other), y / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec2<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr rvec2<T> rvec2<T>::operator*(const M& other) const {
|
||||||
|
rvec2<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr rvec3<T> rvec2<T>::operator*(const M& other) const {
|
||||||
|
rvec3<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr rvec4<T> rvec2<T>::operator*(const M& other) const {
|
||||||
|
rvec4<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3;
|
||||||
|
new_.w = x * other.x1_4 + y * other.x2_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator==(const R& other) const {
|
||||||
|
return x == other.x and y == other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator<(const R& other) const {
|
||||||
|
return x < other.x and y < other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator>(const R& other) const {
|
||||||
|
return x > other.x and y > other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator!=(const R& other) const {
|
||||||
|
return x == other.x and y == other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator<=(const R& other) const {
|
||||||
|
return x > other.x and y > other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool rvec2<T>::operator>=(const R& other) const {
|
||||||
|
return x < other.x and y < other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec2<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float rvec2<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float rvec2<T>::ratio() const {
|
||||||
|
return static_cast<float>(x) / y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float rvec2<T>::invereseRatio() const {
|
||||||
|
return static_cast<float>(y) / x;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec2<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec2<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T rvec2<T>::dot(const rvec2<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T rvec2<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec2<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec2<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec2<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec2<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "rvec2.tpp"
|
202
src/math/rvec2.hpp
Normal file
202
src/math/rvec2.hpp
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
template<Number T>
|
||||||
|
class vec2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 2 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class rvec2 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept RowVector
|
||||||
|
using isRowVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr rvec2()
|
||||||
|
: x(0), y(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n
|
||||||
|
template<Number N1, Number N2>
|
||||||
|
constexpr rvec2(N1 n1, N2 n2)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)) {}
|
||||||
|
/// Create from vec2
|
||||||
|
template<Vector2 V1>
|
||||||
|
constexpr rvec2(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const rvec2<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> operator+(const R& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> operator-(const R& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> operator%(const R& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> compWiseMult(const R& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr rvec2<T> compWiseDiv(const R& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void operator+=(const R& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void operator-=(const R& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void operator%=(const R& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void compWiseAssMult(const R& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr void compWiseAssDiv(const R& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec2<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with mat2x2 -> rvec2
|
||||||
|
template<Mat2x2 M>
|
||||||
|
constexpr rvec2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x3 -> rvec3
|
||||||
|
template<Mat2x3 M>
|
||||||
|
constexpr rvec3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat2x4 -> rvec4
|
||||||
|
template<Mat2x4 M>
|
||||||
|
constexpr rvec4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator==(const R& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator<(const R& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator>(const R& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator!=(const R& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator<=(const R& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr bool operator>=(const R& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns x/y
|
||||||
|
constexpr inline float ratio() const;
|
||||||
|
/// Returns y/x
|
||||||
|
constexpr inline float invereseRatio() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const rvec2<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // rvec2
|
||||||
|
|
||||||
|
using rvec2f = rvec2<float>;
|
||||||
|
using rvec2d = rvec2<double>;
|
||||||
|
using rvec2i = rvec2<int>;
|
||||||
|
using rvec2u = rvec2<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(RowVector2<rvec2<int>>, "rvec2<int> does not satisfy the concept RowVector2");
|
||||||
|
} // namespace gz
|
4437
src/math/rvec2.tpp
Normal file
4437
src/math/rvec2.tpp
Normal file
File diff suppressed because it is too large
Load Diff
283
src/math/rvec3.cpp
Normal file
283
src/math/rvec3.cpp
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
#include "rvec3.hpp"
|
||||||
|
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
#include "vec3.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS rvec3
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::operator=(const rvec3<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
z = static_cast<T>(other.z);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
z = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator+(const R& other) const {
|
||||||
|
return rvec3<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator-(const R& other) const {
|
||||||
|
return rvec3<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator%(const R& other) const {
|
||||||
|
return rvec3<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> rvec3<T>::compWiseMult(const R& other) const {
|
||||||
|
return rvec3<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> rvec3<T>::compWiseDiv(const R& other) const {
|
||||||
|
return rvec3<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void rvec3<T>::operator+=(const R& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
z += static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void rvec3<T>::operator-=(const R& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
z -= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void rvec3<T>::operator%=(const R& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
z %= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void rvec3<T>::compWiseAssMult(const R& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
z *= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void rvec3<T>::compWiseAssDiv(const R& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
z /= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator+(const N& other) const {
|
||||||
|
return rvec3<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator-(const N& other) const {
|
||||||
|
return rvec3<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator%(const N& other) const {
|
||||||
|
return rvec3<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> rvec3<T>::compWiseMult(const N& other) const {
|
||||||
|
return rvec3<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> rvec3<T>::compWiseDiv(const N& other) const {
|
||||||
|
return rvec3<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
z += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
z -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
z %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
z *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec3<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
z /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr rvec2<T> rvec3<T>::operator*(const M& other) const {
|
||||||
|
rvec2<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr rvec3<T> rvec3<T>::operator*(const M& other) const {
|
||||||
|
rvec3<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr rvec4<T> rvec3<T>::operator*(const M& other) const {
|
||||||
|
rvec4<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3;
|
||||||
|
new_.w = x * other.x1_4 + y * other.x2_4 + z * other.x3_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator==(const R& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator<(const R& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator>(const R& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator!=(const R& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator<=(const R& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool rvec3<T>::operator>=(const R& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other and z == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other and z < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other and z > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other and z == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other and z > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec3<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other and z < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float rvec3<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec3<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec3<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T rvec3<T>::dot(const rvec3<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T rvec3<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec3<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec3<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec3<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec3<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "rvec3.tpp"
|
207
src/math/rvec3.hpp
Normal file
207
src/math/rvec3.hpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
template<Number T>
|
||||||
|
class vec3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 3 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class rvec3 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept RowVector
|
||||||
|
using isRowVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr rvec3()
|
||||||
|
: x(0), y(0), z(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n n
|
||||||
|
template<Number N1, Number N2, Number N3>
|
||||||
|
constexpr rvec3(N1 n1, N2 n2, N3 n3)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)) {}
|
||||||
|
/// Create from n vec2
|
||||||
|
template<Number N1, Vector3 V1>
|
||||||
|
constexpr rvec3(N1 n1, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)) {}
|
||||||
|
/// Create from vec2 n
|
||||||
|
template<Vector3 V1, Number N1>
|
||||||
|
constexpr rvec3(const V1& v1, N1 n1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)) {}
|
||||||
|
/// Create from vec3
|
||||||
|
template<Vector3 V1>
|
||||||
|
constexpr rvec3(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const rvec3<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> operator+(const R& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> operator-(const R& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> operator%(const R& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> compWiseMult(const R& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr rvec3<T> compWiseDiv(const R& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void operator+=(const R& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void operator-=(const R& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void operator%=(const R& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void compWiseAssMult(const R& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr void compWiseAssDiv(const R& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec3<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with mat3x2 -> rvec2
|
||||||
|
template<Mat3x2 M>
|
||||||
|
constexpr rvec2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x3 -> rvec3
|
||||||
|
template<Mat3x3 M>
|
||||||
|
constexpr rvec3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat3x4 -> rvec4
|
||||||
|
template<Mat3x4 M>
|
||||||
|
constexpr rvec4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator==(const R& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator<(const R& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator>(const R& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator!=(const R& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator<=(const R& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr bool operator>=(const R& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const rvec3<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // rvec3
|
||||||
|
|
||||||
|
using rvec3f = rvec3<float>;
|
||||||
|
using rvec3d = rvec3<double>;
|
||||||
|
using rvec3i = rvec3<int>;
|
||||||
|
using rvec3u = rvec3<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(RowVector3<rvec3<int>>, "rvec3<int> does not satisfy the concept RowVector3");
|
||||||
|
} // namespace gz
|
4437
src/math/rvec3.tpp
Normal file
4437
src/math/rvec3.tpp
Normal file
File diff suppressed because it is too large
Load Diff
295
src/math/rvec4.cpp
Normal file
295
src/math/rvec4.cpp
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
#include "rvec4.hpp"
|
||||||
|
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS rvec4
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::operator=(const rvec4<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
z = static_cast<T>(other.z);
|
||||||
|
w = static_cast<T>(other.w);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
z = static_cast<T>(other);
|
||||||
|
w = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator+(const R& other) const {
|
||||||
|
return rvec4<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z), w + static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator-(const R& other) const {
|
||||||
|
return rvec4<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z), w - static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator%(const R& other) const {
|
||||||
|
return rvec4<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z), w % static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> rvec4<T>::compWiseMult(const R& other) const {
|
||||||
|
return rvec4<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z), w * static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> rvec4<T>::compWiseDiv(const R& other) const {
|
||||||
|
return rvec4<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z), w / static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void rvec4<T>::operator+=(const R& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
z += static_cast<T>(other.z);
|
||||||
|
w += static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void rvec4<T>::operator-=(const R& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
z -= static_cast<T>(other.z);
|
||||||
|
w -= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void rvec4<T>::operator%=(const R& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
z %= static_cast<T>(other.z);
|
||||||
|
w %= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void rvec4<T>::compWiseAssMult(const R& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
z *= static_cast<T>(other.z);
|
||||||
|
w *= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void rvec4<T>::compWiseAssDiv(const R& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
z /= static_cast<T>(other.z);
|
||||||
|
w /= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator+(const N& other) const {
|
||||||
|
return rvec4<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other), w + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator-(const N& other) const {
|
||||||
|
return rvec4<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other), w - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator%(const N& other) const {
|
||||||
|
return rvec4<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other), w % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> rvec4<T>::compWiseMult(const N& other) const {
|
||||||
|
return rvec4<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other), w * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> rvec4<T>::compWiseDiv(const N& other) const {
|
||||||
|
return rvec4<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other), w / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
z += static_cast<T>(other);
|
||||||
|
w += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
z -= static_cast<T>(other);
|
||||||
|
w -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
z %= static_cast<T>(other);
|
||||||
|
w %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
z *= static_cast<T>(other);
|
||||||
|
w *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void rvec4<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
z /= static_cast<T>(other);
|
||||||
|
w /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr rvec2<T> rvec4<T>::operator*(const M& other) const {
|
||||||
|
rvec2<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr rvec3<T> rvec4<T>::operator*(const M& other) const {
|
||||||
|
rvec3<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3 + w * other.x4_3;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr rvec4<T> rvec4<T>::operator*(const M& other) const {
|
||||||
|
rvec4<T> new_;
|
||||||
|
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
||||||
|
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
||||||
|
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3 + w * other.x4_3;
|
||||||
|
new_.w = x * other.x1_4 + y * other.x2_4 + z * other.x3_4 + w * other.x4_4;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator==(const R& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z and w == other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator<(const R& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z and w < other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator>(const R& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z and w > other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator!=(const R& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z and w == other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator<=(const R& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z and w > other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool rvec4<T>::operator>=(const R& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z and w < other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other and z == other and w == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other and z < other and w < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other and z > other and w > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other and z == other and w == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other and z > other and w > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool rvec4<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other and z < other and w < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float rvec4<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z) + static_cast<float>(w * w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec4<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T rvec4<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T rvec4<T>::dot(const rvec4<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z) + w * static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T rvec4<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec4<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec4<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec4<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> rvec4<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "rvec4.tpp"
|
224
src/math/rvec4.hpp
Normal file
224
src/math/rvec4.hpp
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class vec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 4 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class rvec4 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept RowVector
|
||||||
|
using isRowVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr rvec4()
|
||||||
|
: x(0), y(0), z(0), w(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)), w(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n n n
|
||||||
|
template<Number N1, Number N2, Number N3, Number N4>
|
||||||
|
constexpr rvec4(N1 n1, N2 n2, N3 n3, N4 n4)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)), w(static_cast<T>(n4)) {}
|
||||||
|
/// Create from n n vec2
|
||||||
|
template<Number N1, Number N2, Vector4 V1>
|
||||||
|
constexpr rvec4(N1 n1, N2 n2, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(v1.x)), w(static_cast<T>(v1.y)) {}
|
||||||
|
/// Create from n vec2 n
|
||||||
|
template<Number N1, Vector4 V1, Number N2>
|
||||||
|
constexpr rvec4(N1 n1, const V1& v1, N2 n2)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(n2)) {}
|
||||||
|
/// Create from n vec3
|
||||||
|
template<Number N1, Vector4 V1>
|
||||||
|
constexpr rvec4(N1 n1, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(v1.z)) {}
|
||||||
|
/// Create from vec2 n n
|
||||||
|
template<Vector4 V1, Number N1, Number N2>
|
||||||
|
constexpr rvec4(const V1& v1, N1 n1, N2 n2)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)), w(static_cast<T>(n2)) {}
|
||||||
|
/// Create from vec2 vec2
|
||||||
|
template<Vector4 V1, Vector4 V2>
|
||||||
|
constexpr rvec4(const V1& v1, const V2& v2)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v2.x)), w(static_cast<T>(v2.y)) {}
|
||||||
|
/// Create from vec3 n
|
||||||
|
template<Vector4 V1, Number N1>
|
||||||
|
constexpr rvec4(const V1& v1, N1 n1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(n1)) {}
|
||||||
|
/// Create from vec4
|
||||||
|
template<Vector4 V1>
|
||||||
|
constexpr rvec4(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(v1.w)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
T w;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const rvec4<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> operator+(const R& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> operator-(const R& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> operator%(const R& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> compWiseMult(const R& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr rvec4<T> compWiseDiv(const R& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void operator+=(const R& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void operator-=(const R& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void operator%=(const R& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void compWiseAssMult(const R& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr void compWiseAssDiv(const R& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr rvec4<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with mat4x2 -> rvec2
|
||||||
|
template<Mat4x2 M>
|
||||||
|
constexpr rvec2<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x3 -> rvec3
|
||||||
|
template<Mat4x3 M>
|
||||||
|
constexpr rvec3<T> operator*(const M& other) const;
|
||||||
|
/// Matrix multiplication with mat4x4 -> rvec4
|
||||||
|
template<Mat4x4 M>
|
||||||
|
constexpr rvec4<T> operator*(const M& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator==(const R& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator<(const R& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator>(const R& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator!=(const R& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator<=(const R& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr bool operator>=(const R& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const rvec4<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // rvec4
|
||||||
|
|
||||||
|
using rvec4f = rvec4<float>;
|
||||||
|
using rvec4d = rvec4<double>;
|
||||||
|
using rvec4i = rvec4<int>;
|
||||||
|
using rvec4u = rvec4<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(RowVector4<rvec4<int>>, "rvec4<int> does not satisfy the concept RowVector4");
|
||||||
|
} // namespace gz
|
4437
src/math/rvec4.tpp
Normal file
4437
src/math/rvec4.tpp
Normal file
File diff suppressed because it is too large
Load Diff
288
src/math/vec2.cpp
Normal file
288
src/math/vec2.cpp
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
#include "vec2.hpp"
|
||||||
|
|
||||||
|
#include "mat2x2.hpp"
|
||||||
|
#include "mat2x3.hpp"
|
||||||
|
#include "mat2x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS vec2
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::operator=(const vec2<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> vec2<T>::operator+(const C& other) const {
|
||||||
|
return vec2<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> vec2<T>::operator-(const C& other) const {
|
||||||
|
return vec2<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> vec2<T>::operator%(const C& other) const {
|
||||||
|
return vec2<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> vec2<T>::compWiseMult(const C& other) const {
|
||||||
|
return vec2<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> vec2<T>::compWiseDiv(const C& other) const {
|
||||||
|
return vec2<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void vec2<T>::operator+=(const C& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void vec2<T>::operator-=(const C& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void vec2<T>::operator%=(const C& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void vec2<T>::compWiseAssMult(const C& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void vec2<T>::compWiseAssDiv(const C& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> vec2<T>::operator+(const N& other) const {
|
||||||
|
return vec2<T>(x + static_cast<T>(other), y + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> vec2<T>::operator-(const N& other) const {
|
||||||
|
return vec2<T>(x - static_cast<T>(other), y - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> vec2<T>::operator%(const N& other) const {
|
||||||
|
return vec2<T>(x % static_cast<T>(other), y % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> vec2<T>::compWiseMult(const N& other) const {
|
||||||
|
return vec2<T>(x * static_cast<T>(other), y * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> vec2<T>::compWiseDiv(const N& other) const {
|
||||||
|
return vec2<T>(x / static_cast<T>(other), y / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec2<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat2x2<T> vec2<T>::operator*(const R& other) const {
|
||||||
|
mat2x2<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat2x3<T> vec2<T>::operator*(const R& other) const {
|
||||||
|
mat2x3<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat2x4<T> vec2<T>::operator*(const R& other) const {
|
||||||
|
mat2x4<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x1_4 = x * other.w;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
new_.x2_4 = y * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator==(const C& other) const {
|
||||||
|
return x == other.x and y == other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator<(const C& other) const {
|
||||||
|
return x < other.x and y < other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator>(const C& other) const {
|
||||||
|
return x > other.x and y > other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator!=(const C& other) const {
|
||||||
|
return x == other.x and y == other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator<=(const C& other) const {
|
||||||
|
return x > other.x and y > other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool vec2<T>::operator>=(const C& other) const {
|
||||||
|
return x < other.x and y < other.y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec2<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float vec2<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float vec2<T>::ratio() const {
|
||||||
|
return static_cast<float>(x) / y;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float vec2<T>::invereseRatio() const {
|
||||||
|
return static_cast<float>(y) / x;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec2<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec2<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T vec2<T>::dot(const vec2<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T vec2<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec2<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec2<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec2<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec2<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "vec2.tpp"
|
202
src/math/vec2.hpp
Normal file
202
src/math/vec2.hpp
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat2x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat2x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 2 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class vec2 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept ColumnVector
|
||||||
|
using isColumnVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr vec2()
|
||||||
|
: x(0), y(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n
|
||||||
|
template<Number N1, Number N2>
|
||||||
|
constexpr vec2(N1 n1, N2 n2)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)) {}
|
||||||
|
/// Create from vec2
|
||||||
|
template<Vector2 V1>
|
||||||
|
constexpr vec2(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const vec2<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> operator+(const C& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> operator-(const C& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> operator%(const C& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> compWiseMult(const C& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr vec2<T> compWiseDiv(const C& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void operator+=(const C& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void operator-=(const C& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void operator%=(const C& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void compWiseAssMult(const C& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr void compWiseAssDiv(const C& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec2<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with rvec2 -> mat2x2
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat2x2<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec3 -> mat2x3
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat2x3<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec4 -> mat2x4
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat2x4<T> operator*(const R& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator==(const C& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator<(const C& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator>(const C& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator!=(const C& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator<=(const C& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<ColumnVector2 C>
|
||||||
|
constexpr bool operator>=(const C& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns x/y
|
||||||
|
constexpr inline float ratio() const;
|
||||||
|
/// Returns y/x
|
||||||
|
constexpr inline float invereseRatio() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const vec2<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // vec2
|
||||||
|
|
||||||
|
using vec2f = vec2<float>;
|
||||||
|
using vec2d = vec2<double>;
|
||||||
|
using vec2i = vec2<int>;
|
||||||
|
using vec2u = vec2<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(ColumnVector2<vec2<int>>, "vec2<int> does not satisfy the concept ColumnVector2");
|
||||||
|
} // namespace gz
|
4437
src/math/vec2.tpp
Normal file
4437
src/math/vec2.tpp
Normal file
File diff suppressed because it is too large
Load Diff
301
src/math/vec3.cpp
Normal file
301
src/math/vec3.cpp
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
#include "vec3.hpp"
|
||||||
|
|
||||||
|
#include "mat3x2.hpp"
|
||||||
|
#include "mat3x3.hpp"
|
||||||
|
#include "mat3x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS vec3
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::operator=(const vec3<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
z = static_cast<T>(other.z);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
z = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> vec3<T>::operator+(const C& other) const {
|
||||||
|
return vec3<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> vec3<T>::operator-(const C& other) const {
|
||||||
|
return vec3<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> vec3<T>::operator%(const C& other) const {
|
||||||
|
return vec3<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> vec3<T>::compWiseMult(const C& other) const {
|
||||||
|
return vec3<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> vec3<T>::compWiseDiv(const C& other) const {
|
||||||
|
return vec3<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void vec3<T>::operator+=(const C& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
z += static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void vec3<T>::operator-=(const C& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
z -= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void vec3<T>::operator%=(const C& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
z %= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void vec3<T>::compWiseAssMult(const C& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
z *= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void vec3<T>::compWiseAssDiv(const C& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
z /= static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> vec3<T>::operator+(const N& other) const {
|
||||||
|
return vec3<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> vec3<T>::operator-(const N& other) const {
|
||||||
|
return vec3<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> vec3<T>::operator%(const N& other) const {
|
||||||
|
return vec3<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> vec3<T>::compWiseMult(const N& other) const {
|
||||||
|
return vec3<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> vec3<T>::compWiseDiv(const N& other) const {
|
||||||
|
return vec3<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
z += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
z -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
z %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
z *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec3<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
z /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat3x2<T> vec3<T>::operator*(const R& other) const {
|
||||||
|
mat3x2<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat3x3<T> vec3<T>::operator*(const R& other) const {
|
||||||
|
mat3x3<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
new_.x3_3 = z * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat3x4<T> vec3<T>::operator*(const R& other) const {
|
||||||
|
mat3x4<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x1_4 = x * other.w;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
new_.x2_4 = y * other.w;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
new_.x3_3 = z * other.z;
|
||||||
|
new_.x3_4 = z * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator==(const C& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator<(const C& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator>(const C& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator!=(const C& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator<=(const C& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool vec3<T>::operator>=(const C& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other and z == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other and z < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other and z > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other and z == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other and z > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec3<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other and z < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float vec3<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec3<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec3<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T vec3<T>::dot(const vec3<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T vec3<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec3<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec3<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec3<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec3<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "vec3.tpp"
|
207
src/math/vec3.hpp
Normal file
207
src/math/vec3.hpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat3x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat3x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 3 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class vec3 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept ColumnVector
|
||||||
|
using isColumnVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr vec3()
|
||||||
|
: x(0), y(0), z(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n n
|
||||||
|
template<Number N1, Number N2, Number N3>
|
||||||
|
constexpr vec3(N1 n1, N2 n2, N3 n3)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)) {}
|
||||||
|
/// Create from n vec2
|
||||||
|
template<Number N1, Vector3 V1>
|
||||||
|
constexpr vec3(N1 n1, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)) {}
|
||||||
|
/// Create from vec2 n
|
||||||
|
template<Vector3 V1, Number N1>
|
||||||
|
constexpr vec3(const V1& v1, N1 n1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)) {}
|
||||||
|
/// Create from vec3
|
||||||
|
template<Vector3 V1>
|
||||||
|
constexpr vec3(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const vec3<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> operator+(const C& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> operator-(const C& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> operator%(const C& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> compWiseMult(const C& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr vec3<T> compWiseDiv(const C& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void operator+=(const C& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void operator-=(const C& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void operator%=(const C& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void compWiseAssMult(const C& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr void compWiseAssDiv(const C& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec3<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with rvec2 -> mat3x2
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat3x2<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec3 -> mat3x3
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat3x3<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec4 -> mat3x4
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat3x4<T> operator*(const R& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator==(const C& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator<(const C& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator>(const C& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator!=(const C& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator<=(const C& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<ColumnVector3 C>
|
||||||
|
constexpr bool operator>=(const C& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const vec3<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // vec3
|
||||||
|
|
||||||
|
using vec3f = vec3<float>;
|
||||||
|
using vec3d = vec3<double>;
|
||||||
|
using vec3i = vec3<int>;
|
||||||
|
using vec3u = vec3<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(ColumnVector3<vec3<int>>, "vec3<int> does not satisfy the concept ColumnVector3");
|
||||||
|
} // namespace gz
|
4437
src/math/vec3.tpp
Normal file
4437
src/math/vec3.tpp
Normal file
File diff suppressed because it is too large
Load Diff
322
src/math/vec4.cpp
Normal file
322
src/math/vec4.cpp
Normal file
@ -0,0 +1,322 @@
|
|||||||
|
#include "vec4.hpp"
|
||||||
|
|
||||||
|
#include "mat4x2.hpp"
|
||||||
|
#include "mat4x3.hpp"
|
||||||
|
#include "mat4x4.hpp"
|
||||||
|
#include "rvec2.hpp"
|
||||||
|
#include "rvec3.hpp"
|
||||||
|
#include "rvec4.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
//
|
||||||
|
// CLASS vec4
|
||||||
|
//
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::operator=(const vec4<N>& other) {
|
||||||
|
x = static_cast<T>(other.x);
|
||||||
|
y = static_cast<T>(other.y);
|
||||||
|
z = static_cast<T>(other.z);
|
||||||
|
w = static_cast<T>(other.w);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::operator=(const N& other) {
|
||||||
|
x = static_cast<T>(other);
|
||||||
|
y = static_cast<T>(other);
|
||||||
|
z = static_cast<T>(other);
|
||||||
|
w = static_cast<T>(other);
|
||||||
|
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> vec4<T>::operator+(const C& other) const {
|
||||||
|
return vec4<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z), w + static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> vec4<T>::operator-(const C& other) const {
|
||||||
|
return vec4<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z), w - static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> vec4<T>::operator%(const C& other) const {
|
||||||
|
return vec4<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z), w % static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> vec4<T>::compWiseMult(const C& other) const {
|
||||||
|
return vec4<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z), w * static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> vec4<T>::compWiseDiv(const C& other) const {
|
||||||
|
return vec4<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z), w / static_cast<T>(other.w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void vec4<T>::operator+=(const C& other) {
|
||||||
|
x += static_cast<T>(other.x);
|
||||||
|
y += static_cast<T>(other.y);
|
||||||
|
z += static_cast<T>(other.z);
|
||||||
|
w += static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void vec4<T>::operator-=(const C& other) {
|
||||||
|
x -= static_cast<T>(other.x);
|
||||||
|
y -= static_cast<T>(other.y);
|
||||||
|
z -= static_cast<T>(other.z);
|
||||||
|
w -= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void vec4<T>::operator%=(const C& other) {
|
||||||
|
x %= static_cast<T>(other.x);
|
||||||
|
y %= static_cast<T>(other.y);
|
||||||
|
z %= static_cast<T>(other.z);
|
||||||
|
w %= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void vec4<T>::compWiseAssMult(const C& other) {
|
||||||
|
x *= static_cast<T>(other.x);
|
||||||
|
y *= static_cast<T>(other.y);
|
||||||
|
z *= static_cast<T>(other.z);
|
||||||
|
w *= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void vec4<T>::compWiseAssDiv(const C& other) {
|
||||||
|
x /= static_cast<T>(other.x);
|
||||||
|
y /= static_cast<T>(other.y);
|
||||||
|
z /= static_cast<T>(other.z);
|
||||||
|
w /= static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> vec4<T>::operator+(const N& other) const {
|
||||||
|
return vec4<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other), w + static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> vec4<T>::operator-(const N& other) const {
|
||||||
|
return vec4<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other), w - static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> vec4<T>::operator%(const N& other) const {
|
||||||
|
return vec4<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other), w % static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> vec4<T>::compWiseMult(const N& other) const {
|
||||||
|
return vec4<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other), w * static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> vec4<T>::compWiseDiv(const N& other) const {
|
||||||
|
return vec4<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other), w / static_cast<T>(other));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::operator+=(const N& other) {
|
||||||
|
x += static_cast<T>(other);
|
||||||
|
y += static_cast<T>(other);
|
||||||
|
z += static_cast<T>(other);
|
||||||
|
w += static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::operator-=(const N& other) {
|
||||||
|
x -= static_cast<T>(other);
|
||||||
|
y -= static_cast<T>(other);
|
||||||
|
z -= static_cast<T>(other);
|
||||||
|
w -= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::operator%=(const N& other) {
|
||||||
|
x %= static_cast<T>(other);
|
||||||
|
y %= static_cast<T>(other);
|
||||||
|
z %= static_cast<T>(other);
|
||||||
|
w %= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::compWiseAssMult(const N& other) {
|
||||||
|
x *= static_cast<T>(other);
|
||||||
|
y *= static_cast<T>(other);
|
||||||
|
z *= static_cast<T>(other);
|
||||||
|
w *= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr void vec4<T>::compWiseAssDiv(const N& other) {
|
||||||
|
x /= static_cast<T>(other);
|
||||||
|
y /= static_cast<T>(other);
|
||||||
|
z /= static_cast<T>(other);
|
||||||
|
w /= static_cast<T>(other);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat4x2<T> vec4<T>::operator*(const R& other) const {
|
||||||
|
mat4x2<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
new_.x4_1 = w * other.x;
|
||||||
|
new_.x4_2 = w * other.y;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat4x3<T> vec4<T>::operator*(const R& other) const {
|
||||||
|
mat4x3<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
new_.x3_3 = z * other.z;
|
||||||
|
new_.x4_1 = w * other.x;
|
||||||
|
new_.x4_2 = w * other.y;
|
||||||
|
new_.x4_3 = w * other.z;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat4x4<T> vec4<T>::operator*(const R& other) const {
|
||||||
|
mat4x4<T> new_;
|
||||||
|
new_.x1_1 = x * other.x;
|
||||||
|
new_.x1_2 = x * other.y;
|
||||||
|
new_.x1_3 = x * other.z;
|
||||||
|
new_.x1_4 = x * other.w;
|
||||||
|
new_.x2_1 = y * other.x;
|
||||||
|
new_.x2_2 = y * other.y;
|
||||||
|
new_.x2_3 = y * other.z;
|
||||||
|
new_.x2_4 = y * other.w;
|
||||||
|
new_.x3_1 = z * other.x;
|
||||||
|
new_.x3_2 = z * other.y;
|
||||||
|
new_.x3_3 = z * other.z;
|
||||||
|
new_.x3_4 = z * other.w;
|
||||||
|
new_.x4_1 = w * other.x;
|
||||||
|
new_.x4_2 = w * other.y;
|
||||||
|
new_.x4_3 = w * other.z;
|
||||||
|
new_.x4_4 = w * other.w;
|
||||||
|
return new_;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator==(const C& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z and w == other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator<(const C& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z and w < other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator>(const C& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z and w > other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator!=(const C& other) const {
|
||||||
|
return x == other.x and y == other.y and z == other.z and w == other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator<=(const C& other) const {
|
||||||
|
return x > other.x and y > other.y and z > other.z and w > other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool vec4<T>::operator>=(const C& other) const {
|
||||||
|
return x < other.x and y < other.y and z < other.z and w < other.w;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator==(const N& other) const {
|
||||||
|
return x == other and y == other and z == other and w == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator<(const N& other) const {
|
||||||
|
return x < other and y < other and z < other and w < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator>(const N& other) const {
|
||||||
|
return x > other and y > other and z > other and w > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator!=(const N& other) const {
|
||||||
|
return x == other and y == other and z == other and w == other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator<=(const N& other) const {
|
||||||
|
return x > other and y > other and z > other and w > other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool vec4<T>::operator>=(const N& other) const {
|
||||||
|
return x < other and y < other and z < other and w < other;
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline float vec4<T>::abs() const {
|
||||||
|
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z) + static_cast<float>(w * w));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec4<T>::min() const {
|
||||||
|
return *std::min_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr inline T vec4<T>::max() const {
|
||||||
|
return *std::max_element(cbegin(), cend());
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T vec4<T>::dot(const vec4<N>& other) const {
|
||||||
|
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z) + w * static_cast<T>(other.w);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr T vec4<T>::operator[](std::size_t i) const {
|
||||||
|
return *(&x + sizeof(T) * i);
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec4<T>::cbegin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec4<T>::cend() const {
|
||||||
|
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec4<T>::begin() const {
|
||||||
|
return Iterator(const_cast<T*>(&x));
|
||||||
|
}
|
||||||
|
template<Number T>
|
||||||
|
constexpr Iterator<T> vec4<T>::end() const {
|
||||||
|
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace gz
|
||||||
|
|
||||||
|
#include "vec4.tpp"
|
224
src/math/vec4.hpp
Normal file
224
src/math/vec4.hpp
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
|
#include "../container/iterator.hpp"
|
||||||
|
|
||||||
|
namespace gz {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<Number T>
|
||||||
|
class mat4x2;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x3;
|
||||||
|
template<Number T>
|
||||||
|
class mat4x4;
|
||||||
|
template<Number T>
|
||||||
|
class rvec2;
|
||||||
|
template<Number T>
|
||||||
|
class rvec3;
|
||||||
|
template<Number T>
|
||||||
|
class rvec4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class containing 4 numbers
|
||||||
|
*/
|
||||||
|
template<Number T>
|
||||||
|
class vec4 {
|
||||||
|
public:
|
||||||
|
/// just to satisfy concept ColumnVector
|
||||||
|
using isColumnVector = T;
|
||||||
|
// Constructors
|
||||||
|
/// Default constructor
|
||||||
|
constexpr vec4()
|
||||||
|
: x(0), y(0), z(0), w(0) {}
|
||||||
|
/// Create from scalar, all components will have value n
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4(const N n)
|
||||||
|
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)), w(static_cast<T>(n)) {}
|
||||||
|
/// Create from n n n n
|
||||||
|
template<Number N1, Number N2, Number N3, Number N4>
|
||||||
|
constexpr vec4(N1 n1, N2 n2, N3 n3, N4 n4)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)), w(static_cast<T>(n4)) {}
|
||||||
|
/// Create from n n vec2
|
||||||
|
template<Number N1, Number N2, Vector4 V1>
|
||||||
|
constexpr vec4(N1 n1, N2 n2, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(v1.x)), w(static_cast<T>(v1.y)) {}
|
||||||
|
/// Create from n vec2 n
|
||||||
|
template<Number N1, Vector4 V1, Number N2>
|
||||||
|
constexpr vec4(N1 n1, const V1& v1, N2 n2)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(n2)) {}
|
||||||
|
/// Create from n vec3
|
||||||
|
template<Number N1, Vector4 V1>
|
||||||
|
constexpr vec4(N1 n1, const V1& v1)
|
||||||
|
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(v1.z)) {}
|
||||||
|
/// Create from vec2 n n
|
||||||
|
template<Vector4 V1, Number N1, Number N2>
|
||||||
|
constexpr vec4(const V1& v1, N1 n1, N2 n2)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)), w(static_cast<T>(n2)) {}
|
||||||
|
/// Create from vec2 vec2
|
||||||
|
template<Vector4 V1, Vector4 V2>
|
||||||
|
constexpr vec4(const V1& v1, const V2& v2)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v2.x)), w(static_cast<T>(v2.y)) {}
|
||||||
|
/// Create from vec3 n
|
||||||
|
template<Vector4 V1, Number N1>
|
||||||
|
constexpr vec4(const V1& v1, N1 n1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(n1)) {}
|
||||||
|
/// Create from vec4
|
||||||
|
template<Vector4 V1>
|
||||||
|
constexpr vec4(const V1& v1)
|
||||||
|
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(v1.w)) {}
|
||||||
|
// Values
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
T w;
|
||||||
|
// Assignment
|
||||||
|
/// Component-wise assignment
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const vec4<N>& other);
|
||||||
|
/// Assignment from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator=(const N& other);
|
||||||
|
// Arithmetic
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise +
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> operator+(const C& other) const;
|
||||||
|
/// Component-wise -
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> operator-(const C& other) const;
|
||||||
|
/// Component-wise %
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> operator%(const C& other) const;
|
||||||
|
/// Component-wise *
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> compWiseMult(const C& other) const;
|
||||||
|
/// Component-wise /
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr vec4<T> compWiseDiv(const C& other) const;
|
||||||
|
/// Component-wise assignment +=
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void operator+=(const C& other);
|
||||||
|
/// Component-wise assignment -=
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void operator-=(const C& other);
|
||||||
|
/// Component-wise assignment %=
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void operator%=(const C& other);
|
||||||
|
/// Component-wise assignment *=
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void compWiseAssMult(const C& other);
|
||||||
|
/// Component-wise assignment /=
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr void compWiseAssDiv(const C& other);
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise + with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> operator+(const N& other) const;
|
||||||
|
/// Component-wise - with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> operator-(const N& other) const;
|
||||||
|
/// Component-wise % with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> operator%(const N& other) const;
|
||||||
|
/// Component-wise * with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> compWiseMult(const N& other) const;
|
||||||
|
/// Component-wise / with scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr vec4<T> compWiseDiv(const N& other) const;
|
||||||
|
/// Component-wise assignment += from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator+=(const N& other);
|
||||||
|
/// Component-wise assignment -= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator-=(const N& other);
|
||||||
|
/// Component-wise assignment %= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void operator%=(const N& other);
|
||||||
|
/// Component-wise assignment *= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssMult(const N& other);
|
||||||
|
/// Component-wise assignment /= from scalar
|
||||||
|
template<Number N>
|
||||||
|
constexpr void compWiseAssDiv(const N& other);
|
||||||
|
// Matrix Multiplication
|
||||||
|
/// Matrix multiplication with rvec2 -> mat4x2
|
||||||
|
template<RowVector2 R>
|
||||||
|
constexpr mat4x2<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec3 -> mat4x3
|
||||||
|
template<RowVector3 R>
|
||||||
|
constexpr mat4x3<T> operator*(const R& other) const;
|
||||||
|
/// Matrix multiplication with rvec4 -> mat4x4
|
||||||
|
template<RowVector4 R>
|
||||||
|
constexpr mat4x4<T> operator*(const R& other) const;
|
||||||
|
// Comparison
|
||||||
|
// Vectorial
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator==(const C& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator<(const C& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator>(const C& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator!=(const C& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator<=(const C& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<ColumnVector4 C>
|
||||||
|
constexpr bool operator>=(const C& other) const;
|
||||||
|
// Scalar
|
||||||
|
/// Component-wise comparison == (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator==(const N& other) const;
|
||||||
|
/// Component-wise comparison < (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<(const N& other) const;
|
||||||
|
/// Component-wise comparison > (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>(const N& other) const;
|
||||||
|
/// Component-wise comparison != (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator!=(const N& other) const;
|
||||||
|
/// Component-wise comparison <= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator<=(const N& other) const;
|
||||||
|
/// Component-wise comparison >= (and)
|
||||||
|
template<Number N>
|
||||||
|
constexpr bool operator>=(const N& other) const;
|
||||||
|
// Functional
|
||||||
|
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
||||||
|
constexpr inline float abs() const;
|
||||||
|
/// Returns the min of the components
|
||||||
|
constexpr inline T min() const;
|
||||||
|
/// Returns the max of the components
|
||||||
|
constexpr inline T max() const;
|
||||||
|
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
||||||
|
template<Number N>
|
||||||
|
constexpr inline T dot(const vec4<N>& other) const;
|
||||||
|
// Utility
|
||||||
|
/// Get the ith element. i starts at 0
|
||||||
|
constexpr T operator[](std::size_t i) const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> cbegin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> cend() const;
|
||||||
|
/// Return an Iterator to the first element
|
||||||
|
constexpr Iterator<T> begin() const;
|
||||||
|
/// Return an Iterator past the last element
|
||||||
|
constexpr Iterator<T> end() const;
|
||||||
|
}; // vec4
|
||||||
|
|
||||||
|
using vec4f = vec4<float>;
|
||||||
|
using vec4d = vec4<double>;
|
||||||
|
using vec4i = vec4<int>;
|
||||||
|
using vec4u = vec4<unsigned int>;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(ColumnVector4<vec4<int>>, "vec4<int> does not satisfy the concept ColumnVector4");
|
||||||
|
} // namespace gz
|
4437
src/math/vec4.tpp
Normal file
4437
src/math/vec4.tpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user