#include <TriangCommand.h>


TriangCommand :: TriangCommand(Projection * projection) :
	name("Triang")
{
}


string TriangCommand :: execute(Projection *projection, Profile *profile)
{
	Gnuplot * gplt = projection->projection();
	//float xmin_ = projection->xmin();
	//float xmax_ = projection->xmax();
	//float ymin_ = projection->ymin();
	//float ymax_ = projection->ymax();
	// Fixed size = 1
	float xmin_ = 0.;
	float xmax_ = 1.;
	float ymin_ = 0.;
	float ymax_ = 1.;
	float sqr_size = xmax_ - xmin_;
	float xtop_ = xmin_ + (sqr_size * .5);
	float ytop_ = xmin_ + (sqr_size * 0.8414709848);

// Set square domain
	gplt->cmd ("reset");
	gplt->cmd ("set key %s top title ' '", profile->legend().c_str());
	gplt->cmd ("set size square 1,1");
	gplt->cmd ("unset autoscale");
	gplt->cmd ("set xrange [%f:%f]", xmin_, xmax_);
	gplt->cmd ("set yrange [%f:%f]", ymin_, ymax_);

	if ( profile->decoration() )
	{
		gplt->cmd ("set title '%s - step %d';", profile->title().c_str(), profile->index());
		gplt->cmd ("set xtics");
		gplt->cmd ("set ytics");
		gplt->cmd ("set xlabel");
	}
	else
	{
		gplt->cmd ("unset xtics");
		gplt->cmd ("unset ytics");
		gplt->cmd ("unset xlabel");
	}



// Draw triangle
	string str = "";
	stringstream xmin, xmax, ymin, ymax, xtop, ytop;
	xmin << xmin_;
	xmax << xmax_;
	ymin << ymin_;
	ymax << ymax_;
	xtop << xtop_;
	ytop << ytop_;

	str += ",\\\n '-' u 1:2 w l lc '#000000' notitle\n";
	str += "   " +  xmin.str() + " " + ymin.str() + "\n";
	str += "   " +  xtop.str() + " " + ytop.str() + "\n";
	str += "   " +  xmax.str() + " " + ymin.str() + "\n";
	str += "   " +  xmin.str() + " " + ymin.str() + "\n";
	str += "e\n";

/*
Triangle size 1:

	str += ",\\\n '-' u 1:2 w l lc '#000000' notitle\n";
	str += "   0 0 \n";
	str += "   0.5 0.8414709848 \n";
	str += "   1 0 \n";
	str += "   0 0 \n";
*/


	//gplt->cmd (str);
	return str;
}



