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

86 lines
2.7 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/Monomial_representation.h $
// $Id: Monomial_representation.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_MONOMIAL_REPRESENTAION_H
#define CGAL_POLYNOMIAL_MONOMIAL_REPRESENTAION_H
#include <CGAL/Exponent_vector.h>
#include <CGAL/Polynomial/misc.h>
namespace CGAL {
namespace internal{
2020-10-13 12:44:25 +00:00
template <typename Polynomial> struct Monomial_representation;
2020-10-13 12:44:25 +00:00
// Polynomial muss be at least univariate !
template <typename Coeff_ >
struct Monomial_representation<Polynomial<Coeff_> >{
private:
2020-10-13 12:44:25 +00:00
typedef typename Innermost_coefficient_type<Polynomial<Coeff_> >::Type
Innermost_coefficient;
2020-10-13 12:44:25 +00:00
// Polynomial is univariate
// final creation of pair<Exponent_vector,Innermost_coefficient>
template <typename Polynomial, typename OutputIterator>
2020-10-13 12:44:25 +00:00
OutputIterator
create_mrep(const Polynomial& p, OutputIterator oit , Exponent_vector& ivec, Tag_true) const {
2020-10-13 12:44:25 +00:00
int degree = 0;
for(typename Polynomial::const_iterator it = p.begin(); it != p.end(); it++){
2020-10-13 12:44:25 +00:00
ivec[0] = degree;
if(!CGAL::is_zero(*it))
*oit++ = std::make_pair(ivec,*it);
2020-10-13 12:44:25 +00:00
degree++;
}
ivec[0]=0;
2020-10-13 12:44:25 +00:00
return oit;
}
2020-10-13 12:44:25 +00:00
// polynomial is multivariate
// define correct exponent for dimension and recurse
template <typename Polynomial, typename OutputIterator>
2020-10-13 12:44:25 +00:00
OutputIterator
create_mrep(const Polynomial& p, OutputIterator oit , Exponent_vector& ivec, Tag_false) const {
2020-10-13 12:44:25 +00:00
if(CGAL::is_zero(p)) return oit;
static const int dim = Dimension<Polynomial>::value ;
2020-10-13 12:44:25 +00:00
int degree = 0;
for(typename Polynomial::const_iterator it = p.begin(); it != p.end(); it++){
2020-10-13 12:44:25 +00:00
ivec[dim-1] = degree;
oit = create_mrep(*it,oit,ivec,CGAL::Boolean_tag<1 == dim-1>());
2020-10-13 12:44:25 +00:00
degree++;
}
ivec[dim-1] = 0;
2020-10-13 12:44:25 +00:00
return oit;
}
2020-10-13 12:44:25 +00:00
public:
template <typename OutputIterator>
OutputIterator operator()(const Polynomial<Coeff_>& p, OutputIterator oit) const {
2020-10-13 12:44:25 +00:00
typedef Polynomial<Coeff_> Polynomial;
typedef CGAL::Boolean_tag<1 == Dimension<Polynomial>::value> Is_univariate;
CGAL::Exponent_vector ivec((std::vector<int>)(Dimension<Polynomial>::value));
if(p.is_zero()){
*oit++ = std::make_pair(ivec,Innermost_coefficient(0));
2020-10-13 12:44:25 +00:00
return oit;
}
return create_mrep(p, oit, ivec, Is_univariate());
2020-10-13 12:44:25 +00:00
}
};
} // namespace internal
} //namespace CGAL
#endif //CGAL_POLYNOMIAL_MONOMIAL_REPRESENTAION_H