29 using Matrix2 = Eigen::Matrix<Scalar, 2, 2>;
30 using Vector2 = Eigen::Matrix<Scalar, 2, 1>;
32 PONCA_MULTIARCH
inline void computeDirect(
const Matrix2& _w)
34 PONCA_MULTIARCH_STD_MATH(sqrt);
35 PONCA_MULTIARCH_STD_MATH(max);
38 const Scalar tr = Scalar(0.5) * (_w(0, 0) + _w(1, 1));
39 const Scalar det = _w(0, 0) * _w(1, 1) - _w(0, 1) * _w(1, 0);
40 const Scalar delta = sqrt(max(tr * tr - det, Scalar(0)));
41 m_eivals << tr - delta, tr + delta;
43 const Scalar tol = Eigen::NumTraits<Scalar>::dummy_precision() * (_w.cwiseAbs().maxCoeff() + Scalar(1));
48 if (!eigenvector(_w, m_eivals(1), tol, v1))
49 v1 = Vector2::UnitY();
52 if (_w(0, 1) == _w(1, 0) || !eigenvector(_w, m_eivals(0), tol, v0))
53 v0 = Vector2(v1.y(), -v1.x());
60 PONCA_MULTIARCH [[nodiscard]]
inline const Vector2&
eigenvalues()
const {
return m_eivals; }
63 PONCA_MULTIARCH [[nodiscard]]
inline const Matrix2&
eigenvectors()
const {
return m_eivecs; }
67 return internal::isApprox(m_eivals, _other.m_eivals) && internal::isApprox(m_eivecs, _other.m_eivecs);
71 Vector2 m_eivals{Vector2::Zero()};
72 Matrix2 m_eivecs{Matrix2::Identity()};
75 PONCA_MULTIARCH
static inline bool eigenvector(
const Matrix2& _w, Scalar _k, Scalar _tol, Vector2& _v)
77 const Vector2 v0(_w(0, 1), _k - _w(0, 0));
78 const Vector2 v1(_k - _w(1, 1), _w(1, 0));
81 _v = v0.squaredNorm() > v1.squaredNorm() ? v0 : v1;
83 const Scalar n = _v.norm();