dust3d/thirdparty/cgal/CGAL-5.1/include/CGAL/Polynomial/Degree.h

75 lines
1.9 KiB
C
Raw Normal View History

// Copyright (c) 2009 Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved.
//
2020-10-13 12:44:25 +00:00
// This file is part of CGAL (www.cgal.org)
//
2020-10-13 12:44:25 +00:00
// $URL: https://github.com/CGAL/cgal/blob/v5.1/Polynomial/include/CGAL/Polynomial/Degree.h $
// $Id: Degree.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
2020-10-13 12:44:25 +00:00
// Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de>
//
// ============================================================================
#ifndef CGAL_POLYNOMIAL_DEGREE_H
#define CGAL_POLYNOMIAL_DEGREE_H
#include <CGAL/Exponent_vector.h>
#include <CGAL/Polynomial/misc.h>
namespace CGAL {
namespace internal{
template <typename Polynomial > struct Degree;
2020-10-13 12:44:25 +00:00
// Polynomial musst be at least univariate !
template <typename Coeff_ >
struct Degree<Polynomial<Coeff_> >
: public CGAL::cpp98::unary_function< Polynomial<Coeff_> , int >{
2020-10-13 12:44:25 +00:00
private:
typedef Polynomial<Coeff_> Polynomial_d;
2020-10-13 12:44:25 +00:00
// for univariate polynomials
template <typename Coeff>
int degree(const Polynomial<Coeff>& p, int i) const {
2020-10-13 12:44:25 +00:00
(void) i;
CGAL_assertion(i == 0);
return p.degree();
}
2020-10-13 12:44:25 +00:00
// for multivariate polynomials
template <typename Coeff>
int degree(const Polynomial<Polynomial<Coeff> >& p, int i) const {
typedef Polynomial<Polynomial<Coeff> > Poly;
2020-10-13 12:44:25 +00:00
if(i == (Dimension<Poly>::value-1))
return p.degree();
2020-10-13 12:44:25 +00:00
int result = 0;
for(typename Poly::const_iterator it = p.begin(); it != p.end(); it++){
result = (std::max)(result,degree(*it,i));
}
2020-10-13 12:44:25 +00:00
return result;
}
public:
int operator()(
2020-10-13 12:44:25 +00:00
const Polynomial_d& p,
int i = (Dimension<Polynomial_d>::value-1)) const {
CGAL_assertion(i < Dimension<Polynomial_d>::value);
CGAL_assertion(i >= 0);
return this->degree(p,i);
2020-10-13 12:44:25 +00:00
}
};
} // namespace internal
} //namespace CGAL
#endif //CGAL_POLYNOMIAL_DEGREE_H