Commit f2ebd2ea authored by Philip Trettner's avatar Philip Trettner
Browse files

improved quadric interface

parent c3026fe2
......@@ -85,32 +85,13 @@ TG_NODISCARD constexpr ScalarT distance_sqr(ScalarT a, ScalarT b)
template <class ScalarT>
TG_NODISCARD constexpr ScalarT distance_sqr(pos<2, ScalarT> const& p, quadric<2, ScalarT> const& q)
{
/// Residual L2 error as given by x^T A x - 2 r^T x + c
vec<2, ScalarT> Ax = {
q.A00 * p.x + q.A01 * p.y, //
q.A01 * p.x + q.A11 * p.y, //
};
return dot(vec<2, ScalarT>(p), Ax) // x^T A x
- 2 * dot(vec<2, ScalarT>(p), q.r) // - 2 r^T x
+ q.d_sqr; // + c
return q(p);
}
template <class ScalarT>
TG_NODISCARD constexpr ScalarT distance_sqr(pos<3, ScalarT> const& p, quadric<3, ScalarT> const& q)
{
/// Residual L2 error as given by x^T A x - 2 r^T x + c
vec<3, ScalarT> Ax = {
q.A00 * p.x + q.A01 * p.y + q.A02 * p.z, //
q.A01 * p.x + q.A11 * p.y + q.A12 * p.z, //
q.A02 * p.x + q.A12 * p.y + q.A22 * p.z, //
};
return dot(vec<3, ScalarT>(p), Ax) // x^T A x
- 2 * dot(vec<3, ScalarT>(p), q.r) // - 2 r^T x
+ q.d_sqr; // + c
return q(p);
}
template <int D, class ScalarT>
......
......@@ -88,6 +88,19 @@ public:
d_sqr += rhs.d_sqr;
}
// Residual L2 error as given by x^T A x - 2 r^T x + c
TG_NODISCARD constexpr ScalarT operator()(pos<2, ScalarT> const& p) const
{
vec<2, ScalarT> Ax = {
A00 * p.x + A01 * p.y, //
A01 * p.x + A11 * p.y, //
};
return dot(vec<2, ScalarT>(p), Ax) // x^T A x
- 2 * dot(vec<2, ScalarT>(p), r) // - 2 r^T x
+ d_sqr; // + c
}
// TODO: fix me
template <class T>
friend constexpr T distance_sqr(pos<2, T> const& p, quadric<2, T> const& q);
......@@ -225,6 +238,20 @@ public:
d_sqr += c;
}
// Residual L2 error as given by x^T A x - 2 r^T x + c
TG_NODISCARD constexpr ScalarT operator()(pos<3, ScalarT> const& p) const
{
vec<3, ScalarT> Ax = {
A00 * p.x + A01 * p.y + A02 * p.z, //
A01 * p.x + A11 * p.y + A12 * p.z, //
A02 * p.x + A12 * p.y + A22 * p.z, //
};
return dot(vec<3, ScalarT>(p), Ax) // x^T A x
- 2 * dot(vec<3, ScalarT>(p), r) // - 2 r^T x
+ d_sqr; // + c
}
// TODO: fix me
template <class T>
friend constexpr T distance_sqr(pos<3, T> const& p, quadric<3, T> const& q);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment