X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fpolynomial_root.h;h=1ed82f03943b34e45680f0291c8140680378a9c7;hb=f35364fcdc6d335e3dd3a0281eeadb10c724e7dc;hp=16f11237020e6d3e70fcac1db3a4ce2eeee36a29;hpb=e8a065f2385c219c511b57dac52786120bfa097d;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/polynomial_root.h b/synfig-core/trunk/src/synfig/polynomial_root.h index 16f1123..1ed82f0 100644 --- a/synfig-core/trunk/src/synfig/polynomial_root.h +++ b/synfig-core/trunk/src/synfig/polynomial_root.h @@ -2,7 +2,7 @@ /*! \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 $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley @@ -37,57 +37,57 @@ /* === 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; } - + unsigned int degree()const { return this->size() - 1; } + const Polynomial & operator+=(const Polynomial &p) { - if(p.size() > size()) + if(p.size() > this->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()) + if(p.size() > this->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); + this->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()); + + this->resize(this->size() + p.degree()); for(int i = 0; i < nc.size(); ++i) { for(int j = 1; j < p.size(); ++j) @@ -95,16 +95,16 @@ public: 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