Migrating to Linux

This commit is contained in:
Thorben Höhne
2025-02-17 22:31:17 +01:00
parent c65b1c8139
commit 14f3339eee
75 changed files with 125 additions and 71 deletions

View File

@@ -0,0 +1,301 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<IntType T, bool S>
struct construct_ivec2 {};
template<IntType T, bool S>
struct compute_ivec2_add {};
template<IntType T, bool S>
struct compute_ivec2_sub {};
template<IntType T, bool S>
struct compute_ivec2_mul {};
template<IntType T, bool S>
struct compute_ivec2_div {};
template<IntType T, bool S>
struct compute_ivec2_mod {};
template<IntType T, bool S>
struct compute_ivec2_eq {};
template<IntType T, bool S>
struct compute_ivec2_ieq {};
template<IntType T, bool S>
struct compute_ivec2_inc {};
template<IntType T, bool S>
struct compute_ivec2_dec {};
template<IntType T, bool S>
struct compute_ivec2_and {};
template<IntType T, bool S>
struct compute_ivec2_or {};
template<IntType T, bool S>
struct compute_ivec2_xor {};
template<IntType T, bool S>
struct compute_ivec2_left_shift {};
template<IntType T, bool S>
struct compute_ivec2_right_shift {};
template<IntType T, bool S>
struct compute_ivec2_bnot {};
template<IntType T>
struct construct_ivec2<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
}
};
template<IntType T>
struct compute_ivec2_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
}
};
template<IntType T>
struct compute_ivec2_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
}
};
template<IntType T>
struct compute_ivec2_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
}
};
template<IntType T>
struct compute_ivec2_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x / s;
r.y = v1.y / s;
}
};
template<IntType T>
struct compute_ivec2_mod<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x % v2.x;
r.y = v1.y % v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x % s;
r.y = v1.y % s;
}
};
template<IntType T>
struct compute_ivec2_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec2_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec2_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
}
};
template<IntType T>
struct compute_ivec2_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
}
};
template<IntType T>
struct compute_ivec2_and<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x & v2.x;
r.y = v1.y & v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x & s;
r.y = v1.y & s;
}
};
template<IntType T>
struct compute_ivec2_or<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x | v2.x;
r.y = v1.y | v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const T s)
{
r.x = v1.x | s;
r.y = v1.y | s;
}
};
template<IntType T>
struct compute_ivec2_xor<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x ^ v2.x;
r.y = v1.y ^ v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const T s)
{
r.x = v1.x ^ s;
r.y = v1.y ^ s;
}
};
template<IntType T>
struct compute_ivec2_left_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x << v2.x;
r.y = v1.y << v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const T s)
{
r.x = v1.x << s;
r.y = v1.y << s;
}
};
template<IntType T>
struct compute_ivec2_right_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x >> v2.x;
r.y = v1.y >> v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const T s)
{
r.x = v1.x >> s;
r.y = v1.y >> s;
}
};
template<IntType T>
struct compute_ivec2_bnot<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = ~v1.x;
r.y = ~v1.y;
}
};
}

View File

@@ -0,0 +1,342 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<IntType T, bool S>
struct construct_ivec3 {};
template<IntType T, bool S>
struct compute_ivec3_add {};
template<IntType T, bool S>
struct compute_ivec3_sub {};
template<IntType T, bool S>
struct compute_ivec3_mul {};
template<IntType T, bool S>
struct compute_ivec3_div {};
template<IntType T, bool S>
struct compute_ivec3_mod {};
template<IntType T, bool S>
struct compute_ivec3_eq {};
template<IntType T, bool S>
struct compute_ivec3_ieq {};
template<IntType T, bool S>
struct compute_ivec3_inc {};
template<IntType T, bool S>
struct compute_ivec3_dec {};
template<IntType T, bool S>
struct compute_ivec3_and {};
template<IntType T, bool S>
struct compute_ivec3_or {};
template<IntType T, bool S>
struct compute_ivec3_xor {};
template<IntType T, bool S>
struct compute_ivec3_left_shift {};
template<IntType T, bool S>
struct compute_ivec3_right_shift {};
template<IntType T, bool S>
struct compute_ivec3_bnot {};
template<IntType T>
struct construct_ivec3<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
v1.z = v2.z;
v1.w = (T)0;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
v1.z = s;
v1.w = (T)0;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, T x, T y, T z)
{
v1.x = x;
v1.y = y;
v1.z = z;
v1.w = (T)0;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
v1.z = comp[2];
v1.w = (T)0;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2, const T s)
{
v1.x = v2.x;
v1.y = v2.y;
v1.z = s;
v1.w = (T)0;
}
};
template<IntType T>
struct compute_ivec3_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
r.z = v1.z + v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
r.z = v1.z + s;
}
};
template<IntType T>
struct compute_ivec3_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
r.z = v1.z - v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
r.z = v1.z - s;
}
};
template<IntType T>
struct compute_ivec3_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
r.z = v1.z * v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
}
};
template<IntType T>
struct compute_ivec3_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
r.z = v1.z / v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x / s;
r.y = v1.y / s;
r.z = v1.z / s;
}
};
template<IntType T>
struct compute_ivec3_mod<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x % v2.x;
r.y = v1.y % v2.y;
r.z = v1.z % v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x % s;
r.y = v1.y % s;
r.z = v1.z % s;
}
};
template<IntType T>
struct compute_ivec3_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.z - v2.z) < P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec3_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec3_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
r.z = v1.z + 1;
}
};
template<IntType T>
struct compute_ivec3_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
r.z = v1.z - 1;
}
};
template<IntType T>
struct compute_ivec3_and<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x & v2.x;
r.y = v1.y & v2.y;
r.z = v1.z & v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x & s;
r.y = v1.y & s;
r.z = v1.z & s;
}
};
template<IntType T>
struct compute_ivec3_or<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x | v2.x;
r.y = v1.y | v2.y;
r.z = v1.z | v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x | s;
r.y = v1.y | s;
r.z = v1.z | s;
}
};
template<IntType T>
struct compute_ivec3_xor<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x ^ v2.x;
r.y = v1.y ^ v2.y;
r.z = v1.z ^ v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x ^ s;
r.y = v1.y ^ s;
r.z = v1.z ^ s;
}
};
template<IntType T>
struct compute_ivec3_left_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x << v2.x;
r.y = v1.y << v2.y;
r.z = v1.z << v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x << s;
r.y = v1.y << s;
r.z = v1.z << s;
}
};
template<IntType T>
struct compute_ivec3_right_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
{
r.x = v1.x >> v2.x;
r.y = v1.y >> v2.y;
r.z = v1.z >> v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
{
r.x = v1.x >> s;
r.y = v1.y >> s;
r.z = v1.z >> s;
}
};
template<IntType T>
struct compute_ivec3_bnot<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
{
r.x = ~v1.x;
r.y = ~v1.y;
r.z = ~v1.z;
}
};
}

View File

@@ -0,0 +1,365 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<IntType T, bool S>
struct construct_ivec4 {};
template<IntType T, bool S>
struct compute_ivec4_add {};
template<IntType T, bool S>
struct compute_ivec4_sub {};
template<IntType T, bool S>
struct compute_ivec4_mul {};
template<IntType T, bool S>
struct compute_ivec4_div {};
template<IntType T, bool S>
struct compute_ivec4_mod {};
template<IntType T, bool S>
struct compute_ivec4_eq {};
template<IntType T, bool S>
struct compute_ivec4_ieq {};
template<IntType T, bool S>
struct compute_ivec4_inc {};
template<IntType T, bool S>
struct compute_ivec4_dec {};
template<IntType T, bool S>
struct compute_ivec4_and {};
template<IntType T, bool S>
struct compute_ivec4_or {};
template<IntType T, bool S>
struct compute_ivec4_xor {};
template<IntType T, bool S>
struct compute_ivec4_left_shift {};
template<IntType T, bool S>
struct compute_ivec4_right_shift {};
template<IntType T, bool S>
struct compute_ivec4_bnot {};
template<IntType T>
struct construct_ivec4<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
v1.z = v2.z;
v1.w = v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
v1.z = s;
v1.w = s;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, T x, T y, T z, T w)
{
v1.x = x;
v1.y = y;
v1.z = z;
v1.w = w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
v1.z = comp[2];
v1.w = comp[3];
}
static constexpr void map(Phanes::Core::Math::TIntVector4<int, false>& r, const Phanes::Core::Math::TIntVector2<int, false>& v1, const Phanes::Core::Math::TIntVector2<int, false>& v2)
{
r.x = v1.x;
r.y = v1.y;
r.x = v2.x;
r.y = v2.y;
}
};
template<IntType T>
struct compute_ivec4_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
r.z = v1.z + v2.z;
r.w = v1.w + v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
r.z = v1.z + s;
r.w = v1.w + s;
}
};
template<IntType T>
struct compute_ivec4_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
r.z = v1.z - v2.z;
r.w = v1.w - v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
r.z = v1.z - s;
r.w = v1.w - s;
}
};
template<IntType T>
struct compute_ivec4_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
r.z = v1.z * v2.z;
r.w = v1.w * v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
r.w = v1.w * s;
}
};
template<IntType T>
struct compute_ivec4_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
r.z = v1.z / v2.z;
r.w = v1.w / v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x / s;
r.y = v1.y / s;
r.z = v1.z / s;
r.w = v1.w / s;
}
};
template<IntType T>
struct compute_ivec4_mod<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x % v2.x;
r.y = v1.y % v2.y;
r.z = v1.z % v2.z;
r.w = v1.w % v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x % s;
r.y = v1.y % s;
r.z = v1.z % s;
r.w = v1.w % s;
}
};
template<IntType T>
struct compute_ivec4_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
return (v1.x == v2.x &&
v1.y == v2.y &&
v1.z == v2.z &&
v1.w == v2.w);
}
};
template<IntType T>
struct compute_ivec4_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
return (v1.x != v2.x ||
v1.y != v2.y ||
v1.z != v2.z ||
v1.w != v2.w);
}
};
template<IntType T>
struct compute_ivec4_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
r.z = v1.z + 1;
r.w = v1.w + 1;
}
};
template<IntType T>
struct compute_ivec4_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
r.z = v1.z - 1;
r.w = v1.w - 1;
}
};
template<IntType T>
struct compute_ivec4_and<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x & v2.x;
r.y = v1.y & v2.y;
r.z = v1.z & v2.z;
r.w = v1.w & v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x & s;
r.y = v1.y & s;
r.z = v1.z & s;
r.w = v1.w & s;
}
};
template<IntType T>
struct compute_ivec4_or<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x | v2.x;
r.y = v1.y | v2.y;
r.z = v1.z | v2.z;
r.w = v1.w | v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x | s;
r.y = v1.y | s;
r.z = v1.z | s;
r.w = v1.w | s;
}
};
template<IntType T>
struct compute_ivec4_xor<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x ^ v2.x;
r.y = v1.y ^ v2.y;
r.z = v1.z ^ v2.z;
r.w = v1.w ^ v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x ^ s;
r.y = v1.y ^ s;
r.z = v1.z ^ s;
r.w = v1.w ^ s;
}
};
template<IntType T>
struct compute_ivec4_left_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x << v2.x;
r.y = v1.y << v2.y;
r.z = v1.z << v2.z;
r.w = v1.w << v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x << s;
r.y = v1.y << s;
r.z = v1.z << s;
r.w = v1.w << s;
}
};
template<IntType T>
struct compute_ivec4_right_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x >> v2.x;
r.y = v1.y >> v2.y;
r.z = v1.z >> v2.z;
r.w = v1.w >> v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x >> s;
r.y = v1.y >> s;
r.z = v1.z >> s;
r.w = v1.w >> s;
}
};
template<IntType T>
struct compute_ivec4_bnot<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = ~v1.x;
r.y = ~v1.y;
}
};
}

View File

@@ -0,0 +1,53 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
#include "Core/public/Math/MathCommon.hpp"
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct compute_mat3_transpose {};
template<RealType T, bool S>
struct compute_mat3_mul {};
template<RealType T>
struct compute_mat3_transpose<T, false>
{
static constexpr void map(Phanes::Core::Math::TMatrix3<T, false>& r, const TMatrix3<T, false>& m1)
{
r = TMatrix3<T, false>(m1(0, 0), m1(1, 0), m1(2, 0),
m1(0, 1), m1(1, 1), m1(2, 1),
m1(0, 2), m1(1, 2), m1(2, 2)
);
}
};
template<RealType T>
struct compute_mat3_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TMatrix3<T, false>& r, const TMatrix3<T, false>& m1, const TMatrix3<T, false>& m2)
{
r(0, 0) = m1(0, 0) * m2(0, 0) + m1(0, 1) * m2(1, 0) + m1(0, 2) * m2(2, 0);
r(0, 1) = m1(0, 0) * m2(0, 1) + m1(0, 1) * m2(1, 1) + m1(0, 2) * m2(2, 1);
r(0, 2) = m1(0, 0) * m2(0, 2) + m1(0, 1) * m2(1, 2) + m1(0, 2) * m2(2, 2);
r(1, 0) = m1(1, 0) * m2(0, 0) + m1(1, 1) * m2(1, 0) + m1(1, 2) * m2(2, 0);
r(1, 1) = m1(1, 0) * m2(0, 1) + m1(1, 1) * m2(1, 1) + m1(1, 2) * m2(2, 1);
r(1, 2) = m1(1, 0) * m2(0, 2) + m1(1, 1) * m2(1, 2) + m1(1, 2) * m2(2, 2);
r(2, 0) = m1(2, 0) * m2(0, 0) + m1(2, 1) * m2(1, 0) + m1(2, 2) * m2(2, 0);
r(2, 1) = m1(2, 0) * m2(0, 1) + m1(2, 1) * m2(1, 1) + m1(2, 2) * m2(2, 1);
r(2, 2) = m1(2, 0) * m2(0, 2) + m1(2, 1) * m2(1, 2) + m1(2, 2) * m2(2, 2);
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const TMatrix3<T, false>& m1, const TVector3<T, false>& v)
{
r.x = m1(0, 0) * v.x + m1(0, 1) * v.y + m1(0, 2) * v.z;
r.y = m1(1, 0) * v.x + m1(1, 1) * v.y + m1(1, 2) * v.z;
r.z = m1(2, 0) * v.x + m1(2, 1) * v.y + m1(2, 2) * v.z;
}
};
}

View File

@@ -0,0 +1,136 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
#include "Core/public/Math/MathCommon.hpp"
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct compute_mat4_det {};
template<RealType T, bool S>
struct compute_mat4_inv {};
template<RealType T, bool S>
struct compute_mat4_transpose {};
template<RealType T, bool S>
struct compute_mat4_mul {};
template<RealType T>
struct compute_mat4_det<T, false>
{
static constexpr T map(const Phanes::Core::Math::TMatrix4<T, false>& m)
{
const TVector3<T, false>& a = reinterpret_cast<const TVector3<T, false>&>(m[0]);
const TVector3<T, false>& b = reinterpret_cast<const TVector3<T, false>&>(m[1]);
const TVector3<T, false>& c = reinterpret_cast<const TVector3<T, false>&>(m[2]);
const TVector3<T, false>& d = reinterpret_cast<const TVector3<T, false>&>(m[3]);
const float& x = m(3, 0);
const float& y = m(3, 1);
const float& z = m(3, 2);
const float& w = m(3, 3);
TVector3<T, false> s = CrossP(a, b);
TVector3<T, false> t = CrossP(c, d);
TVector3<T, false> u = a * y - b * x;
TVector3<T, false> v = c * w - d * z;
return DotP(s, v) + DotP(t, u);
}
};
template<RealType T>
struct compute_mat4_inv<T, false>
{
static constexpr bool map(Phanes::Core::Math::TMatrix4<T, false>& r, const Phanes::Core::Math::TMatrix4<T, false>& m)
{
const TVector3<T, false>& a = reinterpret_cast<const TVector3<T, false>&>(m[0]);
const TVector3<T, false>& b = reinterpret_cast<const TVector3<T, false>&>(m[1]);
const TVector3<T, false>& c = reinterpret_cast<const TVector3<T, false>&>(m[2]);
const TVector3<T, false>& d = reinterpret_cast<const TVector3<T, false>&>(m[3]);
const float& x = m(3, 0);
const float& y = m(3, 1);
const float& z = m(3, 2);
const float& w = m(3, 3);
TVector3<T, false> s = CrossP(a, b);
TVector3<T, false> t = CrossP(c, d);
TVector3<T, false> u = a * y - b * x;
TVector3<T, false> v = c * w - d * z;
float _1_det = (T)1.0 / (DotP(s, v) + DotP(t, u));
if (_1_det == (T)0.0)
{
return false;
}
s *= _1_det;
t *= _1_det;
u *= _1_det;
v *= _1_det;
TVector3<T, false> r0 = CrossP(b, v) + t * y;
TVector3<T, false> r1 = CrossP(v, a) - t * x;
TVector3<T, false> r2 = CrossP(d, u) + s * w;
TVector3<T, false> r3 = CrossP(u, c) - s * z;
r = TMatrix4<T, false>(r0.x, r0.y, r0.z, -DotP(b, t),
r1.x, r1.y, r1.z, DotP(a, t),
r2.x, r2.y, r2.z, -DotP(d, s),
r3.x, r3.y, r3.z, DotP(c, s));
return true;
}
};
template<RealType T>
struct compute_mat4_transpose<T, false>
{
static constexpr void map(Phanes::Core::Math::TMatrix4<T, false>& r, const Phanes::Core::Math::TMatrix4<T, false>& m)
{
r = Phanes::Core::Math::TMatrix4<T, false>(m(0, 0), m(1, 0), m(2, 0), m(3, 0),
m(0, 1), m(1, 1), m(2, 1), m(3, 1),
m(0, 2), m(1, 2), m(2, 2), m(3, 2),
m(0, 3), m(1, 3), m(2, 3), m(3, 3));
}
};
template<RealType T>
struct compute_mat4_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TMatrix4<T, false>& r, const Phanes::Core::Math::TMatrix4<T, false>& m1, const Phanes::Core::Math::TMatrix4<T, false>& m2)
{
r(0, 0) = m1(0, 0) * m2(0, 0) + m1(0, 1) * m2(1, 0) + m1(0, 2) * m2(2, 0) + m1(0, 3) * m2(3, 0);
r(0, 1) = m1(0, 0) * m2(0, 1) + m1(0, 1) * m2(1, 1) + m1(0, 2) * m2(2, 1) + m1(0, 3) * m2(3, 1);
r(0, 2) = m1(0, 0) * m2(0, 2) + m1(0, 1) * m2(1, 2) + m1(0, 2) * m2(2, 2) + m1(0, 3) * m2(3, 2);
r(0, 3) = m1(0, 0) * m2(0, 3) + m1(0, 1) * m2(1, 3) + m1(0, 2) * m2(2, 3) + m1(0, 3) * m2(3, 3);
r(1, 0) = m1(1, 0) * m2(0, 0) + m1(1, 1) * m2(1, 0) + m1(1, 2) * m2(2, 0) + m1(1, 3) * m2(3, 0);
r(1, 1) = m1(1, 0) * m2(0, 1) + m1(1, 1) * m2(1, 1) + m1(1, 2) * m2(2, 1) + m1(1, 3) * m2(3, 1);
r(1, 2) = m1(1, 0) * m2(0, 2) + m1(1, 1) * m2(1, 2) + m1(1, 2) * m2(2, 2) + m1(1, 3) * m2(3, 2);
r(1, 3) = m1(1, 0) * m2(0, 3) + m1(1, 1) * m2(1, 3) + m1(1, 2) * m2(2, 3) + m1(1, 3) * m2(3, 3);
r(2, 0) = m1(2, 0) * m2(0, 0) + m1(2, 1) * m2(1, 0) + m1(2, 2) * m2(2, 0) + m1(2, 3) * m2(3, 0);
r(2, 1) = m1(2, 0) * m2(0, 1) + m1(2, 1) * m2(1, 1) + m1(2, 2) * m2(2, 1) + m1(2, 3) * m2(3, 1);
r(2, 2) = m1(2, 0) * m2(0, 2) + m1(2, 1) * m2(1, 2) + m1(2, 2) * m2(2, 2) + m1(2, 3) * m2(3, 2);
r(2, 3) = m1(2, 0) * m2(0, 3) + m1(2, 1) * m2(1, 3) + m1(2, 2) * m2(2, 3) + m1(2, 3) * m2(3, 3);
r(3, 0) = m1(3, 0) * m2(0, 0) + m1(3, 1) * m2(1, 0) + m1(3, 2) * m2(2, 0) + m1(3, 3) * m2(3, 0);
r(3, 1) = m1(3, 0) * m2(0, 1) + m1(3, 1) * m2(1, 1) + m1(3, 2) * m2(2, 1) + m1(3, 3) * m2(3, 1);
r(3, 2) = m1(3, 0) * m2(0, 2) + m1(3, 1) * m2(1, 2) + m1(3, 2) * m2(2, 2) + m1(3, 3) * m2(3, 2);
r(3, 3) = m1(3, 0) * m2(0, 3) + m1(3, 1) * m2(1, 3) + m1(3, 2) * m2(2, 3) + m1(3, 3) * m2(3, 3);
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TMatrix4<T, false>& m1, const Phanes::Core::Math::TVector4<T, false>& v)
{
r.x = m1(0, 0) * v.x + m1(0, 1) * v.y + m1(0, 2) * v.z + m1(0, 3) * v.w;
r.y = m1(1, 0) * v.x + m1(1, 1) * v.y + m1(1, 2) * v.z + m1(1, 3) * v.w;
r.z = m1(2, 0) * v.x + m1(2, 1) * v.y + m1(2, 2) * v.z + m1(2, 3) * v.w;
r.w = m1(3, 0) * v.x + m1(3, 1) * v.y + m1(3, 2) * v.z + m1(3, 3) * v.w;
}
};
}

View File

@@ -0,0 +1,107 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct construct_plane {};
template<RealType T, bool S>
struct compute_plane_add {};
template<RealType T, bool S>
struct compute_plane_sub {};
template<RealType T, bool S>
struct compute_plane_mul {};
template<RealType T, bool S>
struct compute_plane_div {};
template<RealType T>
struct construct_plane<T, false>
{
static constexpr void map(TPlane<T, false>& r, const TVector3<T, false>& normal, T d)
{
r.normal = normal;
r.d = d;
}
static constexpr void map(TPlane<T, false>& r, const TVector3<T, false>& normal, const TVector3<T, false>& base)
{
r.normal = std::copy(normal);
r.d = DotP(r.normal, base);
}
static constexpr void map(TPlane<T, false>& r, T x, T y, T z, T d)
{
r.normal = TVector3<T, false>(x, y, z);
r.d = d;
}
static constexpr void map(TPlane<T, false>& r, const TVector3<T, false>& v1, const TVector3<T, false>& v2, const TVector3<T, false>& v3)
{
r.normal = Normalize(CrossP(v1, v2));
r.d = DotP(r.normal, v3);
}
};
template<RealType T>
struct compute_plane_add<T, false>
{
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, const TPlane<T, false>& pl2)
{
r.comp = pl1.comp + pl2.comp;
}
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, T s)
{
r.comp = pl1.comp + s;
}
};
template<RealType T>
struct compute_plane_sub<T, false>
{
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, const TPlane<T, false>& pl2)
{
r.comp = pl1.comp - pl2.comp;
}
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, T s)
{
r.comp = pl1.comp - s;
}
};
template<RealType T>
struct compute_plane_mul<T, false>
{
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, const TPlane<T, false>& pl2)
{
r.comp = pl1.comp * pl2.comp;
}
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, T s)
{
r.comp = pl1.comp * s;
}
};
template<RealType T>
struct compute_plane_div<T, false>
{
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, const TPlane<T, false>& pl2)
{
r.comp = pl1.comp / pl2.comp;
}
static constexpr void map(TPlane<T, false>& r, const TPlane<T, false>& pl1, T s)
{
r.comp = pl1.comp / s;
}
};
}

View File

@@ -0,0 +1,266 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
#include <iostream>
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct construct_vec2 {};
template<RealType T, bool S>
struct compute_vec2_add {};
template<RealType T, bool S>
struct compute_vec2_sub {};
template<RealType T, bool S>
struct compute_vec2_mul {};
template<RealType T, bool S>
struct compute_vec2_div {};
template<RealType T, bool S>
struct compute_vec2_inc {};
template<RealType T, bool S>
struct compute_vec2_dec {};
// Magnitude
template<RealType T, bool S>
struct compute_vec2_mag {};
// Dot product
template<RealType T, bool S>
struct compute_vec2_dotp {};
// Max
template<RealType T, bool S>
struct compute_vec2_max {};
// Min
template<RealType T, bool S>
struct compute_vec2_min {};
// Set
template<RealType T, bool S>
struct compute_vec2_set {};
template<RealType T>
struct construct_vec2<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& v1, const TVector2<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
}
};
template<RealType T>
struct compute_vec2_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
}
};
template<RealType T>
struct compute_vec2_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, T s, const Phanes::Core::Math::TVector2<T, false>& v1)
{
r.x = s - v1.x;
r.y = s - v1.y;
}
};
template<RealType T>
struct compute_vec2_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
}
};
template<RealType T>
struct compute_vec2_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
s = (T)1.0 / s;
r.x = v1.x * s;
r.y = v1.y * s;
}
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, T s, const Phanes::Core::Math::TVector2<T, false>& v1)
{
r.x = s / v1.x;
r.y = s / v1.y;
}
};
template<RealType T, bool S>
struct compute_vec2_eq
{
static constexpr bool map(const Phanes::Core::Math::TVector2<T, S>& v1, const Phanes::Core::Math::TVector2<T, S>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC);
}
};
template<RealType T, bool S>
struct compute_vec2_ieq
{
static constexpr bool map(const Phanes::Core::Math::TVector2<T, S>& v1, const Phanes::Core::Math::TVector2<T, S>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
}
};
template<RealType T>
struct compute_vec2_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
}
};
template<RealType T>
struct compute_vec2_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
}
};
template<RealType T>
struct compute_vec2_mag<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector2<T, false>& v1)
{
return sqrt(v1.x * v1.x + v1.y * v1.y);
}
};
template<RealType T>
struct compute_vec2_dotp<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
return v1.x * v2.x + v1.y * v2.y;
}
};
template<RealType T>
struct compute_vec2_max<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = (v1.x > v2.x) ? v1.x : v2.x;
r.y = (v1.y > v2.y) ? v1.y : v2.y;
}
};
template<RealType T>
struct compute_vec2_min<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, const Phanes::Core::Math::TVector2<T, false>& v2)
{
r.x = (v1.x < v2.x) ? v1.x : v2.x;
r.y = (v1.y < v2.y) ? v1.y : v2.y;
}
};
template<RealType T>
struct compute_vec2_set<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector2<T, false>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
}
};
}

View File

@@ -0,0 +1,320 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct construct_vec3 {};
template<RealType T, bool S>
struct move_vec3 {};
template<RealType T, bool S>
struct compute_vec3_add {};
template<RealType T, bool S>
struct compute_vec3_sub {};
template<RealType T, bool S>
struct compute_vec3_mul {};
template<RealType T, bool S>
struct compute_vec3_div {};
template<RealType T, bool S>
struct compute_vec3_eq {};
template<RealType T, bool S>
struct compute_vec3_ieq {};
template<RealType T, bool S>
struct compute_vec3_inc {};
template<RealType T, bool S>
struct compute_vec3_dec {};
// Cross product
template<RealType T, bool S>
struct compute_vec3_cross_p {};
// Magnitude
template<RealType T, bool S>
struct compute_vec3_mag {};
// dot product
template<RealType T, bool S>
struct compute_vec3_dotp {};
// set
template<RealType T, bool S>
struct compute_vec3_set {};
// clamp to cube
template<RealType T, bool S>
struct compute_vec3_clamp {};
// max
template<RealType T, bool S>
struct compute_vec3_max {};
// min
template<RealType T, bool S>
struct compute_vec3_min {};
template<RealType T>
struct construct_vec3<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const TVector3<T, false>& v1)
{
memcpy(r.data, v1.data, 4 * sizeof(T));
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, T s)
{
r.x = s;
r.y = s;
r.z = s;
r.w = (T)0.0;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, T x, T y, T z)
{
r.x = x;
r.y = y;
r.z = z;
r.w = (T)0.0;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v1, T s)
{
r.x = v1.x;
r.y = v1.y;
r.z = s;
r.w = (T)0.0;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const T* comp)
{
memcpy(r.data, comp, 3 * sizeof(T));
r.w = (T)0.0;
}
};
template<RealType T>
struct compute_vec3_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
r.z = v1.z + v2.z;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
r.z = v1.z + s;
}
};
template<RealType T>
struct compute_vec3_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
r.z = v1.z - v2.z;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
r.z = v1.z - s;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, T s, const Phanes::Core::Math::TVector3<T, false>& v1)
{
r.x = s - v1.x;
r.y = s - v1.y;
r.z = s - v1.z;
}
};
template<RealType T>
struct compute_vec3_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
r.z = v1.z * v2.z;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
}
};
template<RealType T>
struct compute_vec3_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
r.z = v1.z / v2.z;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, T s)
{
s = (T)1.0 / s;
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
}
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, T s, const Phanes::Core::Math::TVector3<T, false>& v1)
{
r.x = s / v1.x;
r.y = s / v1.y;
r.z = s / v1.z;
}
};
template<RealType T>
struct compute_vec3_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.z - v2.z) < P_FLT_INAC);
}
};
template<RealType T>
struct compute_vec3_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.z - v2.z) > P_FLT_INAC);
}
};
template<RealType T>
struct compute_vec3_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
r.z = v1.z + 1;
}
};
template<RealType T>
struct compute_vec3_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
r.z = v1.z - 1;
}
};
template<RealType T>
struct compute_vec3_cross_p<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false> v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
// V1 has to be copied, as otherwise changes to r affect calculation -> r is v1.
r.x = (v1.y * v2.z) - (v1.z * v2.y);
r.y = (v1.z * v2.x) - (v1.x * v2.z);
r.z = (v1.x * v2.y) - (v1.y * v2.x);
}
};
template<RealType T>
struct compute_vec3_mag<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector3<T, false>& v1)
{
return sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
}
};
template<RealType T>
struct compute_vec3_dotp<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
};
template<RealType T>
struct compute_vec3_set<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& v1, T x, T y, T z)
{
v1.x = x;
v1.y = y;
v1.z = z;
}
};
template<RealType T>
struct compute_vec3_clamp<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, T radius)
{
r.x = Clamp(v1.x, -radius, radius);
r.y = Clamp(v1.y, -radius, radius);
r.z = Clamp(v1.z, -radius, radius);
}
};
template<RealType T>
struct compute_vec3_max<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = (v1.x > v2.x) ? v1.x : v2.x;
r.y = (v1.y > v2.y) ? v1.y : v2.y;
r.z = (v1.z > v2.z) ? v1.z : v2.z;
}
};
template<RealType T>
struct compute_vec3_min<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector3<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v1, const Phanes::Core::Math::TVector3<T, false>& v2)
{
r.x = (v1.x < v2.x) ? v1.x : v2.x;
r.y = (v1.y < v2.y) ? v1.y : v2.y;
r.z = (v1.z < v2.z) ? v1.z : v2.z;
}
};
}

View File

@@ -0,0 +1,328 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<RealType T, bool S>
struct construct_vec4 {};
template<RealType T, bool S>
struct move_vec4 {};
template<RealType T, bool S>
struct compute_vec4_add {};
template<RealType T, bool S>
struct compute_vec4_sub {};
template<RealType T, bool S>
struct compute_vec4_mul {};
template<RealType T, bool S>
struct compute_vec4_div {};
template<RealType T, bool S>
struct compute_vec4_eq {};
template<RealType T, bool S>
struct compute_vec4_ieq {};
template<RealType T, bool S>
struct compute_vec4_inc {};
template<RealType T, bool S>
struct compute_vec4_dec {};
// Magnitude
template<RealType T, bool S>
struct compute_vec4_mag {};
// dot product
template<RealType T, bool S>
struct compute_vec4_dotp {};
// set
template<RealType T, bool S>
struct compute_vec4_set {};
// max
template<RealType T, bool S>
struct compute_vec4_max {};
// min
template<RealType T, bool S>
struct compute_vec4_min {};
// perspective divide
template<RealType T, bool S>
struct compute_vec4_pdiv {};
template<RealType T>
struct construct_vec4<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const TVector4<T, false>& v1)
{
memcpy(r.data, v1.data, 4 * sizeof(T));
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, T s)
{
r.x = s;
r.y = s;
r.z = s;
r.w = s;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, T x, T y, T z, T w)
{
r.x = x;
r.y = y;
r.z = z;
r.w = w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector2<T, false>& v2, const Phanes::Core::Math::TVector2<T, false>& v3)
{
r.x = v2.x;
r.y = v2.y;
r.z = v3.x;
r.w = v3.y;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector3<T, false>& v, T w)
{
r.x = v.x;
r.y = v.y;
r.z = v.z;
r.w = w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const T* comp)
{
memcpy(r.data, comp, 4 * sizeof(T));
}
};
template<RealType T>
struct compute_vec4_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
r.z = v1.z + v2.z;
r.w = v1.w + v2.w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
r.z = v1.z + s;
r.w = v1.w + s;
}
};
template<RealType T>
struct compute_vec4_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
r.z = v1.z - v2.z;
r.w = v1.w - v2.w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
r.z = v1.z - s;
r.w = v1.w - s;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, T s, const Phanes::Core::Math::TVector4<T, false>& v1)
{
r.x = s - v1.x;
r.y = s - v1.y;
r.z = s - v1.z;
r.w = s - v1.w;
}
};
template<RealType T>
struct compute_vec4_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
r.z = v1.z * v2.z;
r.w = v1.w * v2.w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
r.w = v1.w * s;
}
};
template<RealType T>
struct compute_vec4_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
r.z = v1.z / v2.z;
r.w = v1.w / v2.w;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, T s)
{
s = (T)1.0 / s;
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
r.w = v1.w * s;
}
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, T s, const Phanes::Core::Math::TVector4<T, false>& v1)
{
r.x = s / v1.x;
r.y = s / v1.y;
r.z = s / v1.z;
r.w = s / v1.w;
}
};
template<RealType T>
struct compute_vec4_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.z - v2.z) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.w - v2.w) < P_FLT_INAC);
}
};
template<RealType T>
struct compute_vec4_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.z - v2.z) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.w - v2.w) > P_FLT_INAC);
}
};
template<RealType T>
struct compute_vec4_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
r.z = v1.z + 1;
r.w = v1.w + 1;
}
};
template<RealType T>
struct compute_vec4_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
r.z = v1.z - 1;
r.w = v1.w - 1;
}
};
template<RealType T>
struct compute_vec4_mag<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector4<T, false>& v1)
{
return sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z + v1.w * v1.w);
}
};
template<RealType T>
struct compute_vec4_dotp<T, false>
{
static constexpr T map(const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
}
};
template<RealType T>
struct compute_vec4_set<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& v1, T x, T y, T z, T w)
{
v1.x = x;
v1.y = y;
v1.z = z;
v1.w = w;
}
};
template<RealType T>
struct compute_vec4_max<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = (v1.x > v2.x) ? v1.x : v2.x;
r.y = (v1.y > v2.y) ? v1.y : v2.y;
r.z = (v1.z > v2.z) ? v1.z : v2.z;
r.w = (v1.w > v2.w) ? v1.w : v2.w;
}
};
template<RealType T>
struct compute_vec4_min<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1, const Phanes::Core::Math::TVector4<T, false>& v2)
{
r.x = (v1.x < v2.x) ? v1.x : v2.x;
r.y = (v1.y < v2.y) ? v1.y : v2.y;
r.z = (v1.z < v2.z) ? v1.z : v2.z;
r.w = (v1.w < v2.w) ? v1.w : v2.w;
}
};
template<RealType T>
struct compute_vec4_pdiv<T, false>
{
static constexpr void map(Phanes::Core::Math::TVector4<T, false>& r, const Phanes::Core::Math::TVector4<T, false>& v1)
{
T _1_w = (T)1.0 / v1.w;
r.x = v1.x * _1_w;
r.y = v1.y * _1_w;
r.z = v1.z * _1_w;
r.w = (T)0.0;
}
};
}