Add n-dim versions of orientation(points) and add orientation(vectors)
This commit is contained in:
parent
767eb786d5
commit
4bb287eb70
2 changed files with 38 additions and 22 deletions
|
|
@ -14,25 +14,6 @@
|
|||
namespace psemek::geom
|
||||
{
|
||||
|
||||
// TODO: generic implementation
|
||||
template <typename T>
|
||||
#ifdef PSEMEK_GEOM_ROBUST_PREDICATES
|
||||
std::enable_if_t<!std::is_floating_point_v<T>, sign_t>
|
||||
#else
|
||||
sign_t
|
||||
#endif
|
||||
orientation(point<T, 2> const & p0, point<T, 2> const & p1, point<T, 2> const & p2)
|
||||
{
|
||||
T const d = det(p1 - p0, p2 - p0);
|
||||
|
||||
if (d > T{})
|
||||
return sign_t::positive;
|
||||
else if (d < T{})
|
||||
return sign_t::negative;
|
||||
else
|
||||
return sign_t::zero;
|
||||
}
|
||||
|
||||
#ifdef PSEMEK_GEOM_ROBUST_PREDICATES
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, sign_t>
|
||||
|
|
@ -59,10 +40,15 @@ namespace psemek::geom
|
|||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
sign_t orientation(point<T, 3> const & p0, point<T, 3> const & p1, point<T, 3> const & p2, point<T, 3> const & p3)
|
||||
template <typename T, std::size_t N, typename ... Vectors>
|
||||
#ifdef PSEMEK_GEOM_ROBUST_PREDICATES
|
||||
std::enable_if_t<!std::is_floating_point_v<T>, sign_t>
|
||||
#else
|
||||
sign_t
|
||||
#endif
|
||||
orientation(vector<T, N> const & v1, Vectors const & ... vs)
|
||||
{
|
||||
T const d = det(p0 - p3, p1 - p3, p2 - p3);
|
||||
T const d = det(v1, vs...);
|
||||
|
||||
if (d > T{})
|
||||
return sign_t::positive;
|
||||
|
|
@ -72,4 +58,24 @@ namespace psemek::geom
|
|||
return sign_t::zero;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N, typename ... Points>
|
||||
#ifdef PSEMEK_GEOM_ROBUST_PREDICATES
|
||||
std::enable_if_t<!std::is_floating_point_v<T>, sign_t>
|
||||
#else
|
||||
sign_t
|
||||
#endif
|
||||
orientation(point<T, N> const & p0, Points const & ... ps)
|
||||
{
|
||||
auto o = orientation((ps - p0)...);
|
||||
|
||||
if constexpr ((N % 2) == 0)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
else
|
||||
{
|
||||
return inverse(o);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,14 @@ namespace psemek::geom
|
|||
return o;
|
||||
}
|
||||
|
||||
inline sign_t inverse(sign_t s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case sign_t::positive: return sign_t::negative;
|
||||
case sign_t::zero: return sign_t::zero;
|
||||
case sign_t::negative: return sign_t::positive;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue