X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fpolynomial_root.h;h=09e31e4b2e0116a71516e1fb857ccfcc1fee8256;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=a1a5c316c5949bfd74836926a52c63130546b99e;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/polynomial_root.h b/synfig-core/trunk/src/synfig/polynomial_root.h index a1a5c31..09e31e4 100644 --- a/synfig-core/trunk/src/synfig/polynomial_root.h +++ b/synfig-core/trunk/src/synfig/polynomial_root.h @@ -1,28 +1,30 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I 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 $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ /* === S T A R T =========================================================== */ -#ifndef __SINFG_POLYNOMIAL_ROOT_H -#define __SINFG_POLYNOMIAL_ROOT_H +#ifndef __SYNFIG_POLYNOMIAL_ROOT_H +#define __SYNFIG_POLYNOMIAL_ROOT_H /* === H E A D E R S ======================================================= */ @@ -36,57 +38,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) @@ -94,16 +96,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