X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=synfig-core%2Ftags%2Fstable%2Fsrc%2Fsinfg%2Fpolynomial_root.h;fp=synfig-core%2Ftags%2Fstable%2Fsrc%2Fsinfg%2Fpolynomial_root.h;h=a1a5c316c5949bfd74836926a52c63130546b99e;hb=46036a57bc1ab5583c5d5c2188e8c52d7682d9d5;hp=0000000000000000000000000000000000000000;hpb=6745aa58ba1df6f71ccdcdb332fef4ca8774f278;p=synfig.git diff --git a/synfig-core/tags/stable/src/sinfg/polynomial_root.h b/synfig-core/tags/stable/src/sinfg/polynomial_root.h new file mode 100644 index 0000000..a1a5c31 --- /dev/null +++ b/synfig-core/tags/stable/src/sinfg/polynomial_root.h @@ -0,0 +1,119 @@ +/* === S I N F G =========================================================== */ +/*! \file polynomial_root.h +** \brief Polynomial Root Finder Header +** +** $Id: polynomial_root.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +** +** \legal +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This software and associated documentation +** are CONFIDENTIAL and PROPRIETARY property of +** the above-mentioned copyright holder. +** +** You may not copy, print, publish, or in any +** other way distribute this software without +** a prior written agreement with +** the copyright holder. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SINFG_POLYNOMIAL_ROOT_H +#define __SINFG_POLYNOMIAL_ROOT_H + +/* === H E A D E R S ======================================================= */ + +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ +template < typename T = float, typename F = float > +class Polynomial : public std::vector //a0 + a1x + a2x^2 + ... + anx^n +{ +public: + + //Will maintain all lower constants + void degree(unsigned int d, const T & def = (T)0) { resize(d+1,def); } + unsigned int degree()const { return size() - 1; } + + const Polynomial & operator+=(const Polynomial &p) + { + if(p.size() > size()) + resize(p.size(), (T)0); + + for(int i = 0; i < p.size(); ++i) + { + (*this)[i] += p[i]; + } + return *this; + } + + const Polynomial & operator-=(const Polynomial &p) + { + if(p.size() > size()) + resize(p.size(), (T)0); + + for(int i = 0; i < p.size(); ++i) + { + (*this)[i] -= p[i]; + } + return *this; + } + + const Polynomial & operator*=(const Polynomial &p) + { + if(p.size() < 1) + { + resize(0); + return *this; + } + + unsigned int i,j; + std::vector nc(*this); + + //in place for constant stuff + for(i = 0; i < nc.size(); ++i) + { + (*this)[i] *= p[0]; + } + + if(p.size() < 2) return *this; + + resize(size() + p.degree()); + for(int i = 0; i < nc.size(); ++i) + { + for(int j = 1; j < p.size(); ++j) + { + nc[i+j] += nc[i]*p[j]; + } + } + + return *this; + } +}; + +class RootFinder +{ + std::vector< std::complex > workcoefs; + int its; + +public: + std::vector< std::complex > coefs; //the number of coefficients determines the degree of polynomial + + std::vector< std::complex > roots; + + void find_all_roots(bool polish); +}; + + + +/* === E N D =============================================================== */ + +#endif