// Copyright (c) 2009 Max-Planck-Institute Saarbruecken (Germany). // All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $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 // // // Author(s) : Michael Hemmer // // ============================================================================ #ifndef CGAL_POLYNOMIAL_MONOMIAL_REPRESENTAION_H #define CGAL_POLYNOMIAL_MONOMIAL_REPRESENTAION_H #include #include namespace CGAL { namespace internal{ template struct Monomial_representation; // Polynomial muss be at least univariate ! template struct Monomial_representation >{ private: typedef typename Innermost_coefficient_type >::Type Innermost_coefficient; // Polynomial is univariate // final creation of pair template OutputIterator create_mrep(const Polynomial& p, OutputIterator oit , Exponent_vector& ivec, Tag_true) const { int degree = 0; for(typename Polynomial::const_iterator it = p.begin(); it != p.end(); it++){ ivec[0] = degree; if(!CGAL::is_zero(*it)) *oit++ = std::make_pair(ivec,*it); degree++; } ivec[0]=0; return oit; } // polynomial is multivariate // define correct exponent for dimension and recurse template OutputIterator create_mrep(const Polynomial& p, OutputIterator oit , Exponent_vector& ivec, Tag_false) const { if(CGAL::is_zero(p)) return oit; static const int dim = Dimension::value ; int degree = 0; for(typename Polynomial::const_iterator it = p.begin(); it != p.end(); it++){ ivec[dim-1] = degree; oit = create_mrep(*it,oit,ivec,CGAL::Boolean_tag<1 == dim-1>()); degree++; } ivec[dim-1] = 0; return oit; } public: template OutputIterator operator()(const Polynomial& p, OutputIterator oit) const { typedef Polynomial Polynomial; typedef CGAL::Boolean_tag<1 == Dimension::value> Is_univariate; CGAL::Exponent_vector ivec((std::vector)(Dimension::value)); if(p.is_zero()){ *oit++ = std::make_pair(ivec,Innermost_coefficient(0)); return oit; } return create_mrep(p, oit, ivec, Is_univariate()); } }; } // namespace internal } //namespace CGAL #endif //CGAL_POLYNOMIAL_MONOMIAL_REPRESENTAION_H