/* Copyright (c) 1997-2010
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
   http://www.polymake.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
   $Project: polymake $$Id: normal_fan.cc 10182 2011-05-04 17:46:48Z kulas $
*/

#include "polymake/client.h"
#include "polymake/Rational.h"
#include "polymake/Matrix.h"
#include "polymake/IncidenceMatrix.h"

namespace polymake { namespace fan {

template <typename Coord>
perl::Object normal_fan(perl::Object p)
{
   perl::ObjectType t=perl::ObjectType::construct<Coord>("PolyhedralFan");
   perl::Object f(t); 
   const Matrix<Coord> m=p.give("FACETS");
   const Matrix<Coord> mm=m.minor(All,~scalar2set(0));
   f.take("RAYS")<<mm;
   const IncidenceMatrix<> vfi=p.give("FACETS_THRU_VERTICES");
   f.take("MAXIMAL_CONES")<<vfi;
   f.take("REGULAR")<<true;
   const Matrix<Coord> ls=p.give("AFFINE_HULL");
   if (ls.rows()) f.take("LINEALITY_SPACE")<<ls.minor(All,~scalar2set(0));
   else f.take("LINEALITY_SPACE")<<Matrix<Coord>(0,mm.cols());
   const bool com=p.give("BOUNDED");
   f.take("COMPLETE")<<com;
   const int dim=p.CallPolymakeMethod("AMBIENT_DIM");
   f.take("FAN_DIM")<<dim;
   return f;
}

UserFunctionTemplate4perl("# @category Constructing a fan"
                          "# Computes the normal fan of //p//."
                          "# @param Polytope p"
                          "# @author Sven Herrmann",
                          "normal_fan<Coord>(polytope::Polytope<Coord>)");
} }

// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
