#  Copyright (c) 1997-2018
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  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.
#-------------------------------------------------------------------------------

#A hyperbolic surface (noncompact, finite area) is given by a triangulation [[DCEL_DATA]] (the topological data) and [[PENNER_COORDINATES]] (the metric data).
declare object HyperbolicSurface {

   # The triangulation of the surface is encoded by a half edge data structure.
   # For each edge i of the triangulation there are two half edges 2i and 2i+1, one for each orientation.
   # Each row reads as follows: [ 2i.head , (2i+1).head , 2i.next , (2i+1).next]
   # @example A triangulated sphere with three punctures can be given by the following [[DCEL_DATA]]:
   # > $S3 = new Array<Array<Int>>([ [1,0,2,5],[2,1,4,1],[0,2,0,3] ]);
   # > $s = new HyperbolicSurface(DCEL_DATA=>$S3);
   property DCEL_DATA : Array<Array<Int>>;
   
   # Penners lambda lenghts, sometimes called Penner coordinates, of the hyperbolic surface. 
   #     Robert C. Penner. Decorated Teichmüller Theory. QGM Master Class Series. European Mathematical Society, Zürich, 2012.
   # They are given by one positive rational for each edge of the triangulation, ordered in the sense of the triangulation [[DCEL_DATA]].
   property PENNER_COORDINATES : Vector<Rational>;

   # Each Delaunay triangulations of the surface can be obtained by successively flipping edges of the triangulation [[DCEL_DATA]].
   # The k-th flip word is a list of integers (the indices of the edges) that describe which edge flips produce the k-th Delaunay triangulation.
   # Note that the k-th Delaunay triangulation also corresponds to the k-th maximal cone of the [[SECONDARY_FAN]].
   property FLIP_WORDS : Array< List<Int> >;

   # In order to compute [[GKZ_VECTORS]] (or a [[secondary_polyhedron]]) one needs to specify a point on the surface, see 
   #     M. Joswig, R. Löwe, and B. Springborn. Secondary fans and secondary polyhedra of punctured Riemann surfaces. arXiv:1708.08714.
   # This point is specified by choosing a pair of rationals (p,x) that determine how the (decorated) 0th half edge is lifted to a geodesic in H^2.
   # The covering is chosen in such a way that the horocycle at infinity is the vertical line at height p^2 and 
   # the lifted 0th half edge goes from infinity to the point x at the ideal boundary.
   property SPECIAL_POINT : Pair<Rational, Rational>;

   #property SECONDARY_FAN defined in fan/rules/fan_properties.rules

   # @category Other 
   # Computes an approximation of the GKZ vectors of a hyperbolic surface.
   # The approximation depends on the parameter //depth// that restricts the depth of the (covering) triangles that are summed over in the definition of the GKZ vectors.
   # @param Int depth
   # @return Matrix<Rational>
   # @example
   # > $T = new Array<Array<Int>>([[0,0,6,5],[0,0,1,10],[0,0,8,2],[1,0,11,4],[1,0,7,3],[1,0,9,0]]);
   # > $s = new HyperbolicSurface(DCEL_DATA=>$T, PENNER_COORDINATES=>[1,1,1,1,1,1], SPECIAL_POINT=>[1,0]);
   # > print $s->GKZ_VECTORS(2);
   # | 1 240509/380250 517/1950
   # | 1 98473/694950 915006978873/1469257962050
   #
   user_method GKZ_VECTORS($){
      my $self = shift;
      my $depth = shift;
      gkz_vectors($self, $depth);
   }

   rule initial : {
      my $dd = $this->DCEL_DATA;
      my $pc = $this->PENNER_COORDINATES;
      die "incompatible DCEL_DATA and PENNER_COORDINATES"
         unless ($dd->size == $pc->dim);
   }
   precondition : exists(DCEL_DATA);
   precondition : exists(PENNER_COORDINATES);


}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
