/* 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: facet_to_infinity.cc 9991 2010-12-12 23:36:28Z gawrilow $
*/

#include "polymake/client.h"
#include "polymake/Rational.h"
#include "polymake/Matrix.h"
#include "polymake/polytope/transform.h"

namespace polymake { namespace polytope {

template <typename Scalar>
perl::Object facet_to_infinity(perl::Object p_in, const int inf_facet)
{

  perl::Object p_out(perl::ObjectType::construct<Scalar>("Polytope"));

  const Matrix<Scalar> facets=p_in.give("FACETS");

  const Vector<Scalar> inf_f= facets.row(inf_facet);
  const Matrix<Scalar> tau=null_space(inf_f);
  transform_section(p_out, p_in, "FACETS | INEQUALITIES", T(inf_f/tau));
  transform_section(p_out, p_in, "AFFINE_HULL | EQUATIONS", T(inf_f/tau));
  transform_section(p_out, p_in, "VERTICES", inv(inf_f/tau));
  
  p_out.take("BOUNDED") << false;

  return p_out;
}

  UserFunctionTemplate4perl("# @category Producing a new polyhedron from others"
                            "# Make an affine transformation such that the i-th facet is transformed to infinity"
                            "# @param Int i the facet index"
                            "# @return Polytope"
                            "# @author Sven Herrmann",
                            "facet_to_infinity<Scalar>(Polytope<Scalar> $)");
} }

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