//header file are used in this program 
#include "createGeometry.h"
#include <iostream>
#include <geos/geom/LinearRing.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/CoordinateArraySequence.h>
#include<geos/geom/Point.h>
#include<geos/geom/Geometry.h>
#include <geos/util/IllegalArgumentException.h>



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


createGeometry::createGeometry() //Using constructor we are initializing the Precision model
{
	vector<Geometry*>* geoms = new vector<Geometry*>;
	//Creating the Vector object for Geometry
	PrecisionModel* pm = new PrecisionModel(2.0, 0, 0);
	// Define a precision model using 0,0 as the reference origin
	// and 2.0 as coordinates scale.
	global_factory = GeometryFactory::create(pm, -1);
	// Initialize global factory with defined PrecisionModel
	// and a SRID of -1 (undefined).
}

Polygon* createGeometry::createPolygon(double xmin, double ymin, double xmax, double ymax)
{
	CoordinateSequence* temp = global_factory->getCoordinateSequenceFactory()->create((size_t)0, 0);
	temp->add(Coordinate(xmin, ymin));
	temp->add(Coordinate(xmax, ymin));
	temp->add(Coordinate(xmax, ymax));
	temp->add(Coordinate(xmin, ymax));

	temp->add(Coordinate(xmin, ymin));

	LinearRing* shell = global_factory->createLinearRing(temp);
	return global_factory->createPolygon(shell, NULL);
}

LineString* createGeometry::makeLine(double xmin, double ymin, double xmax, double ymax)
{
	unique_ptr<PrecisionModel> pm(new PrecisionModel());
	CoordinateSequence* temp = global_factory->getCoordinateSequenceFactory()->create((size_t)0, 0);

	temp->add(Coordinate(xmin, ymin));
	temp->add(Coordinate(xmax, ymax));

	LineString* shell = global_factory->createLineString(temp);

	return shell;
}


createGeometry::~createGeometry()//Deconstructor Definition 
{
	//Automatically deallocate the memory of class object
}