#include <iostream>
#include <fstream>
using namespace std;

#include "polygon.h"
#include "triangulation.h"
#include "convex_partition.h"


int main(int argc, char ** argv)
{
	if(argc!=2){
		cerr<<"Usage: "<<argv[0]<<" *.poly"<<endl;
		return 1;
	}
	
	//open file
	ifstream fin(argv[1]);
	if(fin.good()==false)
	{
		cerr<<"! Error: Cannot open file: "<<argv[1]<<endl;
	}
	
	//create polygon
	c_polygon poly;
	fin>>poly;
	fin.close();
	
	//triangulate the polygon
	vector<diagonal> diagonals;
	triangulate(poly,diagonals);
	
	// Call Hertel and Mehlhorn Algorithm
	list<c_polygon> convex_parts;
	HertelMehlhorn(poly,diagonals,convex_parts);

	// save each convex component to a file
	// If the input filename is "polygon.poly" and if there are 3 convex components in your 
	// decomposition, then the output files should be named "polygon_cc_000001.poly", "polygon_cc_000002.poly", 
	/// and "polygon_cc_000003.poly". There are six digits between "polygon_cc_" and ".poly"
	for(list<c_polygon>::iterator i=convex_parts.begin();i!=convex_parts.end();i++)
	{
		c_polygon& convex_poly = *i;

		// open a file stream and save convex_poly
		// Note: Check out the function "operator<<"" in polygon.h
	}
 	
	return 0;
}
