PolynomialSolver: fix bugs related to linear polynomials.

This commit is contained in:
Benjamin Chrétien 2014-05-19 19:08:51 +02:00
parent df92649379
commit eda79321be

View File

@ -41,7 +41,7 @@ class PolynomialSolverBase
protected: protected:
template< typename OtherPolynomial > template< typename OtherPolynomial >
inline void setPolynomial( const OtherPolynomial& poly ){ inline void setPolynomial( const OtherPolynomial& poly ){
m_roots.resize(poly.size()); } m_roots.resize(poly.size()-1); }
public: public:
template< typename OtherPolynomial > template< typename OtherPolynomial >
@ -345,11 +345,20 @@ class PolynomialSolver : public PolynomialSolverBase<_Scalar,_Deg>
void compute( const OtherPolynomial& poly ) void compute( const OtherPolynomial& poly )
{ {
eigen_assert( Scalar(0) != poly[poly.size()-1] ); eigen_assert( Scalar(0) != poly[poly.size()-1] );
eigen_assert( poly.size() > 1 );
if(poly.size() > 2 )
{
internal::companion<Scalar,_Deg> companion( poly ); internal::companion<Scalar,_Deg> companion( poly );
companion.balance(); companion.balance();
m_eigenSolver.compute( companion.denseMatrix() ); m_eigenSolver.compute( companion.denseMatrix() );
m_roots = m_eigenSolver.eigenvalues(); m_roots = m_eigenSolver.eigenvalues();
} }
else if(poly.size () == 2)
{
m_roots.resize(1);
m_roots[0] = -poly[0]/poly[1];
}
}
public: public:
template< typename OtherPolynomial > template< typename OtherPolynomial >
@ -376,8 +385,9 @@ class PolynomialSolver<_Scalar,1> : public PolynomialSolverBase<_Scalar,1>
template< typename OtherPolynomial > template< typename OtherPolynomial >
void compute( const OtherPolynomial& poly ) void compute( const OtherPolynomial& poly )
{ {
eigen_assert( Scalar(0) != poly[poly.size()-1] ); eigen_assert( poly.size() == 2 );
m_roots[0] = -poly[0]/poly[poly.size()-1]; eigen_assert( Scalar(0) != poly[1] );
m_roots[0] = -poly[0]/poly[1];
} }
public: public: