/* 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: simplex.cc 10061 2011-03-16 12:46:53Z herr $
*/

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

namespace polymake { namespace polytope {

perl::Object simplex(int d, const Rational& s)
{
   if (d < 2)
      throw std::runtime_error("dimension must be at least 2");
   if (!s)
      throw std::runtime_error("scale must be non-zero");

   perl::Object p("Polytope<Rational>");
   p.set_description() << "simplex of dimension " << d << endl;

   p.take("CONE_AMBIENT_DIM") << d+1;
   p.take("CONE_DIM") << d+1;

   Matrix<Rational> V(d+1,d+1);
   V.col(0).fill(1);
   V.minor(range(1,d), range(1,d)).diagonal().fill(s);
   p.take("VERTICES") << V;

   p.take("N_VERTICES") << d+1;
   p.take("SIMPLICIALITY") << d;
   p.take("BOUNDED") << true;
   p.take("CENTERED") << false;

   return p;
}

UserFunction4perl("# @category Producing from scratch"
                  "# Produce the standard //d//-simplex."
                  "# Combinatorially equivalent to a regular polytope corresponding to the Coxeter group of type A<sub>//d//-1</sub>."
                  "# Optionally, the simplex can be scaled by the parameter //scale//."
                  "# @param Int d the dimension"
                  "# @param Rational scale default value: 1"
                  "# @return Polytope",
                  &simplex, "simplex($;$=1)");
} }

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