/******************************
 *
 * Demonstration program for GEOS bug.
 *
 ******************************/

#include <geos/geom/Geometry.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/util/GEOSException.h>
#include <geos/util/IllegalArgumentException.h>

using namespace std;
using namespace geos;
using namespace geos::geom;

static string wkt1 = "POLYGON((413.4 243.1,607.3 244.2,607 294.9,697.9 295.4,699.2 241.8,416.9 240.9,416.7 162.3,413.2 162.3,413.4 243.1))";
static string wkt2 = "POLYGON((513.4 343.1,707.3 344.2,707 394.9,797.9 395.4,799.2 341.8,516.9 340.9,516.7 262.3,513.2 262.3,513.4 343.1))";

void do_buffer()
{
	io::WKTReader wktReader;
	io::WKTWriter wktWriter;
	Geometry *geom1;
	Geometry *geom2;

	cout << endl << "======= Polygon 1, original:" << endl;
	geom1 = wktReader.read(wkt1);
	cout << wktWriter.write(geom1) << endl;

	cout << endl << "======= Polygon 1, buffered:" << endl;
	geom2 = geom1->buffer(-2);
	cout << wktWriter.write(geom2) << endl;

	delete geom1;
	delete geom2;

	cout << endl << "======= Polygon 2, original:" << endl;
	geom1 = wktReader.read(wkt2);
	cout << wktWriter.write(geom1) << endl;

	cout << endl << "======= Polygon 2, buffered:" << endl;
	geom2 = geom1->buffer(-2);
	cout << wktWriter.write(geom2) << endl;

	delete geom1;
	delete geom2;

}

void do_sir()
{
	cout << "Nothing to do";
}

int main()
{
	cout << "using GEOS " << geosversion() << endl;
	try
	{
		do_buffer();
	}
	// All exceptions thrown by GEOS are subclasses of this
	// one, so this is a catch-all 
	catch (const util::GEOSException& exc)
	{
		cerr << "GEOS exception thrown: " << exc.what() << endl;
		exit(1);
	}
	catch (const exception &e)
	{
		cerr << "Standard exception thrown: " << e.what() << endl;
		exit(1);
	}
	catch (...)
	{
		cerr << "Unknown exception thrown!\n";
		exit(1);
	}

	exit(0);
}


