Add geom::lerpn - n-ary baricentric interpolation

This commit is contained in:
Nikita Lisitsa 2020-11-23 18:14:06 +03:00
parent c6fe38989c
commit 75b847ec23

View file

@ -32,6 +32,30 @@ namespace psemek::geom
return x0 * (T(1) - t) + x1 * t;
}
namespace detail
{
template <typename P>
auto lerpn_impl(P &, P const &)
{}
template <typename P, typename T, typename ... Args>
auto lerpn_impl(P & res, P const & o, P const & p, T const & t, Args const & ... args)
{
res += t * (p - o);
lerpn_impl(res, o, args...);
}
}
template <typename P, typename T, typename ... Args>
auto lerpn(P const & p, T const &, Args const & ... args)
{
P res = p;
detail::lerpn_impl(res, p, args...);
return res;
}
// roots of ax^2 + bx + c = 0
// in increasing order
template <typename T>