3 #if _MSC_VER && defined(min) 4 #pragma push_macro("min") 5 #pragma push_macro("max") 20 template <
class T,
int Dim,
bool Packed>
22 static constexpr T epsilon = T(1) / ConstexprExp10<T>(
ConstexprAbs(std::numeric_limits<T>::min_exponent10) / 2);
24 return length < epsilon;
28 template <
class T,
int Dim,
bool Packed>
34 template <
class T,
int Dim,
bool Packed>
40 template <
class T,
int Dim,
bool Packed>
42 T maxElement = std::abs(v(0));
44 maxElement = std::max(maxElement, std::abs(v(i)));
46 if (maxElement == T(0)) {
49 auto scaled = v / maxElement;
50 return sqrt(
Dot(scaled, scaled)) * maxElement;
54 template <
class T,
class U,
int Dim,
bool Packed1,
bool Packed2>
56 return (lhs - rhs).Length();
60 template <
class T,
int Dim,
bool Packed>
68 template <
class T,
int Dim,
bool Packed>
71 return T(0.9999) <= n && n <= T(1.0001);
75 template <
class T,
int Dim,
bool Packed>
78 vmod(0) = std::abs(v(0)) > std::numeric_limits<T>::denorm_min() ? v(0) : std::numeric_limits<T>::denorm_min();
85 template <
class T,
int Dim,
bool Packed>
96 template <
class T,
int Dim,
bool Packed>
104 using SimdT = decltype(VectorData<T, Dim, Packed>::simd);
105 lhs.simd = SimdT::spread(all);
110 template <
class T,
int Dim,
bool Packed>
114 for (
int i = 0; i < Dim; ++i) {
115 sum += lhs.data[i] * rhs.data[i];
120 using SimdT = decltype(VectorData<T, Dim, Packed>::simd);
121 return SimdT::template dot<Dim>(lhs.simd, rhs.simd);
129 template <
class T,
int Dim,
bool Packed,
class... Args>
135 template <
class T,
int Dim,
bool Packed>
139 template <
class T,
bool Packed>
145 template <
class T,
bool Packed>
147 return Cross(*(arg[0]));
152 template <
class T,
bool Packed>
155 lhs.z * rhs.x - lhs.x * rhs.z,
156 lhs.x * rhs.y - lhs.y * rhs.x);
159 template <
class T,
bool Packed>
161 return Cross(*(args[0]), *(args[1]));
166 template <
class T,
int Dim,
bool Packed>
169 for (
int i = 0; i < lhs.
Dimension(); ++i) {
170 res[i] = std::min(lhs[i], rhs[i]);
175 template <
class T,
int Dim,
bool Packed>
178 for (
int i = 0; i < lhs.
Dimension(); ++i) {
179 res[i] = std::max(lhs[i], rhs[i]);
190 #include "../Matrix.hpp" 194 template <
class T,
int Dim,
bool Packed>
200 int sign = 2 * (Dim % 2) - 1;
201 for (
int base = 0; base < result.
Dimension(); ++base, sign *= -1) {
203 for (
int j = 0; j < base; ++j) {
204 for (
int i = 0; i < detCalc.
RowCount(); ++i) {
205 detCalc(i, j) = (*(args[i]))[j];
208 for (
int j = base + 1; j < result.
Dimension(); ++j) {
209 for (
int i = 0; i < detCalc.
RowCount(); ++i) {
210 detCalc(i, j - 1) = (*(args[i]))[j];
215 result(base) = coefficient;
222 template <
class T,
int Dim,
bool Packed,
class... Args>
224 static_assert(1 +
sizeof...(args) == Dim - 1,
"Number of arguments must be (Dimension - 1).");
226 std::array<const Vector<T, Dim, Packed>*, Dim - 1> vectors = { &head, &args... };
227 return Cross(vectors);
233 #if defined(MATHTER_MINMAX) 234 #pragma pop_macro("min") 235 #pragma pop_macro("max") void Fill(Vector< T, Dim, Packed > &lhs, T all)
Sets all elements of the vector to the same value.
Definition: VectorFunction.hpp:97
Vector< T, Dim, Packed > Min(const Vector< T, Dim, Packed > &lhs, const Vector< T, Dim, Packed > &rhs)
Returns the element-wise minimum of arguments
Definition: VectorFunction.hpp:167
auto Distance(const Vector< T, Dim, Packed1 > &lhs, const Vector< U, Dim, Packed2 > &rhs)
Returns the euclidean distance between to vectors.
Definition: VectorFunction.hpp:55
bool IsNullvector(const Vector< T, Dim, Packed > &v)
Returns true if the vector's length is too small for precise calculations (i.e. normalization).
Definition: VectorFunction.hpp:21
Quaternion< T, Packed > Normalize(const Quaternion< T, Packed > &q)
Returns the unit quaternion of the same direction. Does not change this object.
Definition: QuaternionFunction.hpp:66
Represents a vector in N-dimensional space.
Definition: Definitions.hpp:57
T Dot(const Vector< T, Dim, Packed > &lhs, const Vector< T, Dim, Packed > &rhs)
Calculates the scalar product (dot product) of the two arguments.
Definition: VectorFunction.hpp:111
Definition: Approx.hpp:11
Vector< T, Dim, Packed > Max(const Vector< T, Dim, Packed > &lhs, const Vector< T, Dim, Packed > &rhs)
Returns the element-wise maximum of arguments
Definition: VectorFunction.hpp:176
Definition: Definitions.hpp:63
T LengthSquared(const Quaternion< T, Packed > &q)
Returns the square of the absolute value.
Definition: QuaternionFunction.hpp:53
constexpr int Dimension() const
Returns the number of dimensions of the vector.
Definition: VectorImpl.hpp:402
auto Cross(const Vector< T, Dim, Packed > &head, Args &&... args) -> Vector< T, Dim, Packed >
Returns the generalized cross-product in N dimensions.
Definition: VectorFunction.hpp:223
T Determinant(const Matrix< T, Dim, Dim, Order, Layout, Packed > &m)
Returns the determinant of the matrix.
Definition: MatrixFunction.hpp:21
Definition: Traits.hpp:218
constexpr T ConstexprAbs(T arg)
Definition: MathUtil.hpp:21
T Length(const Quaternion< T, Packed > &q)
Returns the absolute value of the quaternion.
Definition: QuaternionFunction.hpp:60
T LengthPrecise(const Vector< T, Dim, Packed > &v)
Returns the length of the vector, avoids overflow and underflow, so it's more expensive.
Definition: VectorFunction.hpp:41
Vector< T, Dim, Packed > SafeNormalize(const Vector< T, Dim, Packed > &v)
Makes a unit vector, but keeps direction. Leans towards (1,0,0...) for nullvectors, costs more.
Definition: VectorFunction.hpp:76
constexpr int RowCount() const
Returns the number of rows of the matrix.
Definition: MatrixImpl.hpp:31
T sign(T arg)
Definition: MathUtil.hpp:6
bool IsNormalized(const Quaternion< T, Packed > &q)
Check if the quaternion is a unit quaternion, with some tolerance for floats.
Definition: QuaternionFunction.hpp:78