BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polynomial/internal/Rational/Evaluate_polynomial.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Stanford University (USA).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Polynomial/internal/Rational/Evaluate_polynomial.h $
00016 // $Id: Evaluate_polynomial.h 28567 2006-02-16 14:30:13Z lsaboret $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 #ifndef CGAL_POLYNOMIAL_INTERNAL_EVALUATE_H
00022 #define CGAL_POLYNOMIAL_INTERNAL_EVALUATE_H
00023 #include <CGAL/Polynomial/basic.h>
00024 #include <vector>
00025 
00026 CGAL_POLYNOMIAL_BEGIN_INTERNAL_NAMESPACE
00027 
00028 double evaluate_polynomial(const double *b, const double *e, double t);
00029 
00030 template <class NT>
00031 inline NT evaluate_polynomial(const std::vector<NT> &coefs, const NT &t)
00032 {
00033     if (coefs.empty()) return NT(0);
00034     typename std::vector<NT>::const_reverse_iterator rit= coefs.rbegin();
00035     NT result = *rit;
00036     ++rit;
00037     for (; rit != coefs.rend(); ++rit) {
00038         result *= t;
00039         result += (*rit);
00040     }
00041     return result;
00042 }
00043 
00044 
00045 inline double evaluate_polynomial(const std::vector<double>& coefs, double t)
00046 {
00047     if (coefs.empty()) return 0;
00048     return evaluate_polynomial(&coefs.front(), &coefs.front()+coefs.size(), t);
00049 }
00050 
00051 
00052 template<class K, class NT >
00053 class Evaluate_polynomial
00054 {
00055     typedef typename K::Function            Polynomial;
00056 
00057     public:
00058         Evaluate_polynomial(){}
00059         Evaluate_polynomial(const Polynomial& p): coefs_(p.begin(), p.end()) {
00060 /*coefs_.resize(p.degree()+1);
00061 for (unsigned int i=0; i< p.degree(); ++i){
00062   coefs_[i]= NT(p[i]);
00063   }*/
00064         }
00065 
00066         typedef NT argument_type;
00067         typedef NT result_type;
00068 
00069         result_type operator()(const argument_type& x) const
00070         {
00071             return evaluate_polynomial(coefs_, x);
00072         }
00073 
00074     protected:
00075         std::vector<result_type> coefs_;
00076 };
00077 
00078 CGAL_POLYNOMIAL_END_INTERNAL_NAMESPACE
00079 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines