35 namespace Triangulation
41 static float GetPolygonArea(std::span<const Vec2> p)
44 const size_t n = p.size();
45 for (
size_t i = 0,
j = n - 1;
i < n;
j =
i++)
46 a += CrossProduct(p[
j], p[
i]);
50 static bool IsPointInTri(
const Vec2& p,
const Vec2& a,
const Vec2& b,
const Vec2&
c)
53 const float w0 = CrossProduct(
Vec2{ b.
X - a.
X, b.
Y - a.
Y },
Vec2{ p.
X - a.
X, p.Y - a.
Y });
54 const float w1 = CrossProduct(
Vec2{
c.X - b.
X,
c.Y - b.
Y },
Vec2{ p.
X - b.
X, p.Y - b.
Y });
55 const float w2 = CrossProduct(
Vec2{ a.
X -
c.X, a.
Y -
c.Y },
Vec2{ p.
X -
c.X, p.Y -
c.Y });
56 return (
w0 >= 0 &&
w1 >= 0 &&
w2 >= 0);
59 static float GetMinAngleDeg(
const Vec2& a,
const Vec2& b,
const Vec2&
c)
65 float d = DotProduct(
u,
v) / std::sqrt(DotProduct(
u,
u) * DotProduct(
v,
v));
66 d = std::clamp(d, -1.0f, 1.0f);
72 return std::min({
a1,
a2,
a3 }) * 57.29578f;
79 template<
CVec3 Vec3,
template<
class...>
class ContainerType,
class Vec3i,
class ...Args>
82 using IndexType = std::remove_cvref_t<decltype(std::declval<Vec3i>()[0])>;
119 const Vec3
u = Normalized(
Math::Abs(
GetZ(n)) > 0.9f ? Vec3{ 1,0,0 } : CrossProduct(Vec3{ 0,0,1 }, n));
120 const Vec3
v = CrossProduct(n,
u);
123 return { DotProduct(p,
u), DotProduct(p,
v) };
133 if (GetPolygonArea(
pts2) < 0.0f)
135 std::reverse(
poly.begin(),
poly.end());
136 std::reverse(
pts2.begin(),
pts2.end());
161 return CrossProduct(
Vec2{ b.
X - a.
X, b.
Y - a.
Y },
162 Vec2{
c.X - b.
X,
c.Y - b.
Y }) >= 0.0f;
195 const float q = GetMinAngleDeg(a, b,
c);
Definition Vec3Traits.h:44
JPL_INLINE constexpr auto Abs(const T &value) noexcept
Standard abs is not constexpr in C++20.
Definition Math.h:87
void TriangulatePoly(std::span< const Vec3 > inPositions, std::span< int > poly, ContainerType< Vec3i, Args... > &outTris)
Definition Triangulation.h:80
Definition AcousticMaterial.h:36
JPL_INLINE void SetZ(Vec3Type &v, Vec3FloatType< Vec3Type > value) noexcept
Definition Vec3Traits.h:41
JPL_INLINE auto GetX(const Vec3Type &v) noexcept
Definition Vec3Traits.h:35
JPL_INLINE void SetY(Vec3Type &v, Vec3FloatType< Vec3Type > value) noexcept
Definition Vec3Traits.h:40
JPL_INLINE auto GetZ(const Vec3Type &v) noexcept
Definition Vec3Traits.h:37
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
JPL_INLINE auto GetY(const Vec3Type &v) noexcept
Definition Vec3Traits.h:36
JPL_INLINE void SetX(Vec3Type &v, Vec3FloatType< Vec3Type > value) noexcept
Definition Vec3Traits.h:39
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
Definition MinimalVec2.h:29
float X
Definition MinimalVec2.h:30
float Y
Definition MinimalVec2.h:31
static constexpr std::size_t size() noexcept
Get number of element of the vector.
Definition SIMD.h:97