/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.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.
*/

#ident "$Project: polymake $$Id: prism-coord.cc,v 1.4 2004/06/22 16:23:09 gawrilow Exp $"

/* The only reason for extracting this portion code in a separate file is
   the exorbitant memory consumption by gcc. When it becomes more economical one nice day,
   this file should be merged back into prism.cc */

#include <Rational.h>
#include <Matrix.h>
#include <GenericVector.h>
#include <Set.h>

namespace polymake { namespace polytope {

Matrix<Rational>
prism_coord(const Matrix<Rational>& V,
	    int& n_vertices, int& n_vertices_out,
	    const Set<int>& rays,
	    const Rational& z, const Rational& z_prime)
{

   if (n_vertices==0) {
      n_vertices=V.rows();
      n_vertices_out=2*n_vertices-rays.size();
   }
   return rays.empty()
          ? Matrix<Rational>( ( V | same_element_vector(z, n_vertices) ) /
			      ( V | same_element_vector(z_prime, n_vertices)) )
          : Matrix<Rational>( ( V | same_element_sparse_vector(~rays, z, n_vertices) ) /
			      ( V.minor(~rays,All) | same_element_vector(z_prime, n_vertices-rays.size()) ) );
}

} }
