########################################################################
#  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
#  of the License, or (at your option) any later version.
#  
#  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.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
#  Boston, MA  02110-1301, USA.
#  
#  ---
#  Copyright (C) 2011-2015, Simon Hampe <simon.hampe@googlemail.com>
#
#
#	Functions in this file deal with comparing tropical additions of objects
#	and converting an object to another tropical addition.
#
########################################################################


package Visual::RationalCurve;


options %Visual::RationalCurve::decorations=(
	%Visual::Graph::decorations,
	
	# String if set to "hidden", the labels indicating the lengths are hidden
	LengthLabels => enum("hidden"),
);


object RationalCurve {

	# @category Visualization
	# Visualizes a RationalCurve object. This visualization uses the VISUAL method of its GRAPH, so 
	# it accepts all the options of Visual::Graph::decorations. In addition it has another option
	# @options
	# @option String LengthLabels If "hidden", the edges are not labelled with their lengths. Any other text is ignored. Not set to "hidden" by default.
	user_method VISUAL(%Visual::RationalCurve::decorations) {
		my ($this,$decor) = @_;
		# Find out if edge labelling is turned off
		my $showLengths = 1;
		if(defined($$decor{"LengthLabels"})) {
			if($$decor{"LengthLabels"} eq "hidden") {
				$showLengths = 0;
			}
		}
		if($showLengths) {
			# We only need to compute the edge lengths for labelling the edges
			# The edges with nodes in (0,..,n-1) get no label
			# The other edges get the COEFFS as labels in the order they appear
			my @labels = ();
			my $coeffIndex = 0;
			for my $i (0 .. ($this->GRAPH->EDGES->size()-1)) {
				my $edge = $this->GRAPH->EDGES->[$i];
				if($edge->[0] < $this->N_LEAVES) {
					@labels = (@labels,"");
				}
				else {
					my $length = $this->GRAPH_EDGE_LENGTHS->[$coeffIndex];
					@labels = (@labels,"<$length>");
					$coeffIndex++;
				}
			}
			$$decor{"EdgeLabels"} = \@labels;
		}
		delete($$decor{"LengthLabels"});
		$this->GRAPH->VISUAL($decor);
	}

}
