#  Copyright (c) 1997-2006
#  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.
#-----------------------------------------------------------------------------
#  $Project: polymake $$Id: qhull.rules 7044 2006-02-21 19:34:28Z gawrilow $


# path to the qhull executable
custom $qhull;

CONFIGURE {
   $qhull=find_via_path("qhull")
   or die "'qhull' program not found\n";
}

object FloatPolytope;

# Category: Convex hull computation
# Use the @see external.qhull program for convex hull computation.
label qhull

qhull.convex_hull.primal: FACETS, N_FACETS : AMBIENT_DIM, VERTICES | POINTS
WEIGHT 4.10
PRECONDITION: BOUNDED
   $this->BOUNDED
PRECONDITION: DIM, AMBIENT_DIM
   $this->DIM==$this->AMBIENT_DIM;
BODY:
   my $Q=new Poly::ProgramPipe($qhull);
   my @coordinates=$this->dehomogenize($this->VERTICES | POINTS);
   print $Q $this->AMBIENT_DIM, "\n", $#coordinates+1, "\n", @coordinates;

#  skip the dimension
   $_=<$Q>;

#  number of facets
   my $n=<$Q>;
   my @FACETS;
#  toggle the signs and move the facet offset in the first position
   while (<$Q>) {
      $_=negative($_);
      /(\S+)\s*$/;
      push @FACETS, "$1 $`";
   }
   if (@FACETS != $n) {
      die "unexpected end of file";
   }
   $this->FACETS=\@FACETS;
   $this->N_FACETS=$n;


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
