#include "roots.h" #include namespace { template int roots_helper( const int deg, const Eigen::MatrixBase& coef, const typename Derivedcoef::Scalar xmin, const typename Derivedcoef::Scalar xmax, Eigen::PlainObjectBase& R) { using cy::PolynomialRoots; if constexpr (MAX_DEG == 0) { // Should be impossible to reach here from roots() return 0; } else { if (deg == MAX_DEG) { using Scalar = typename Derivedcoef::Scalar; Scalar r[MAX_DEG]; int nr = PolynomialRoots(r, coef.derived().data(), xmin, xmax); // will resize if needed. Safe on compile-time sized matrices R.setConstant(MAX_DEG, std::numeric_limits::quiet_NaN()); for (int i = 0; i < nr; ++i) { R[i] = r[i]; } return nr; } return roots_helper(deg, coef, xmin, xmax, R); } } } template < typename Derivedcoef, typename DerivedR> IGL_INLINE int igl::cycodebase::roots( const Eigen::MatrixBase& coef, const typename Derivedcoef::Scalar xmin, const typename Derivedcoef::Scalar xmax, Eigen::PlainObjectBase& R) { using Scalar = typename Derivedcoef::Scalar; // Static assert that DerivedR::Scalar is same as Derivedcoef::Scalar static_assert( std::is_same::value, "DerivedR::Scalar must be the same as Derivedcoef::Scalar"); // Check that Derivedcoef and DerivedR are vectors static_assert( (Derivedcoef::ColsAtCompileTime == 1 || Derivedcoef::RowsAtCompileTime == 1) && (DerivedR::ColsAtCompileTime == 1 || DerivedR::RowsAtCompileTime == 1), "Derivedcoef and DerivedR must be vectors"); constexpr int MAX_DEG = 16; const int deg = coef.size() - 1; if (deg < 1 || deg > MAX_DEG) { throw std::runtime_error("Polynomial degree out of range"); } return ::roots_helper( deg, coef, xmin, xmax, R); } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization template IGL_INLINE int igl::cycodebase::roots( const Eigen::MatrixBase& coef, const double xmin, const double xmax, Eigen::PlainObjectBase& R); template int igl::cycodebase::roots, Eigen::Matrix>(Eigen::MatrixBase> const&, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase>&); template int igl::cycodebase::roots, Eigen::Matrix>(Eigen::MatrixBase> const&, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase>&); #endif