BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polynomial/Chinese_remainder_traits.h
Go to the documentation of this file.
00001 // Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany)
00002 //
00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public License as
00005 // published by the Free Software Foundation; version 2.1 of the License.
00006 // See the file LICENSE.LGPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Polynomial/include/CGAL/Polynomial/Chinese_remainder_traits.h $
00015 // $Id: Chinese_remainder_traits.h 47254 2008-12-06 21:18:27Z afabri $
00016 //
00017 //
00018 // Author(s)     :  Michael Hemmer <hemmer@mpi-inf.mpg.de>
00019 
00020 #ifndef CGAL_POLYNOMIAL_CHINESE_REMAINDER_TRAITS
00021 #define CGAL_POLYNOMIAL_CHINESE_REMAINDER_TRAITS
00022 
00023 #include <CGAL/basic.h>
00024 #include <CGAL/Chinese_remainder_traits.h>
00025 #include <CGAL/Polynomial/Polynomial_type.h>
00026 
00027 namespace CGAL {
00028 
00029 template <class NT> 
00030 class Chinese_remainder_traits<Polynomial<NT> >{
00031 public:
00032     typedef Polynomial<NT> Type;
00033     typedef Chinese_remainder_traits<NT> CRT_NT;
00034    
00035     typedef typename CRT_NT::Scalar_type Scalar_type;
00036     
00037     struct Chinese_remainder{
00038         void operator()(
00039                 const Scalar_type& m1, const Scalar_type& m2, 
00040                 const Scalar_type& m, 
00041                 const Scalar_type& s,  const Scalar_type& t,  
00042                 const Type& u1, const Type& u2, 
00043                 Type& u) const {
00044             
00045             typename CRT_NT::Chinese_remainder chinese_remainder_nt;
00046             
00047             CGAL_precondition(u1.degree() == u2.degree());
00048             
00049             std::vector<NT> coeffs(u1.degree()+1);
00050             for(int i = 0; i <= u1.degree(); i++){
00051                 NT c; 
00052                 chinese_remainder_nt(m1,m2,m,s,t,u1[i],u2[i],c);
00053                 coeffs[i] = c;  
00054             }
00055             u = Polynomial<NT>(coeffs.begin(),coeffs.end());
00056         }
00057 
00058         void operator()(
00059                 const Scalar_type& m1, const Type& u1,
00060                 const Scalar_type& m2, const Type& u2,
00061                 Scalar_type& m, Type& u) const {
00062             Scalar_type s,t; 
00063             
00064             CGAL::extended_euclidean_algorithm(m1,m2,s,t);
00065             m = m1 * m2;
00066             this->operator()(m1,m2,m,s,t,u1,u2,u);
00067         }
00068     };
00069 };
00070 
00071 
00072 } // namespace CGAL 
00073 
00074 #endif // CGAL_POLYNOMIAL_CHINESE_REMAINDER_TRAITS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines