#ifndef POLYGON_H
#define POLYGON_H

/*
** Convex-Simple polygons, tested using the separating axis theorem.
** Points are stored in a clockwise direction
*/

#include "Shape.h"

namespace Salamander
{

class Polygon : public Shape
{
public:
	/*
	** Constructor.
	*/
	registerShape();
	Polygon();

	/*
	** Destructor.
	*/
	virtual ~Polygon();

	/*
	** Project the vertices of the shape onto an arbritrary vector, updating the maximum
	** and minumum values of the 1d result that is passed in for 'overlap.
	*/
	void projectPoints(Vec2 axis, Vec2& overlap);

	/*
	** Basic inclusion test for a point. The point must be in the local frame of reference.
	*/
	virtual bool isPointInside(Vec2 point);

private:
	/*
	** A generic update method that calls the superclass update, then any class specific updates. In
	** this case, we generate the Area and the Moment of Inertia.
	*/
	void generateProperties();

	/*
	** Polygons can be dynamic, so we must generate the moment of inertia.
	*/
	void generateMomentOfInertia();

	/*
	** Generates the area of the polygon by adding the cross-products of the component triangles.
	*/
	void generateArea();

	/*
	** The area is used in several real-time calculations, so this is cached by calling 'generateArea'.
	*/
	double area_;

};

}

#endif

