// COTD Entry submitted by John W. Ratcliff [jratcliff@verant.com]

// ** THIS IS A CODE SNIPPET WHICH WILL EFFICIEINTLY TRIANGULATE ANY
// ** POLYGON/CONTOUR (without holes) AS A STATIC CLASS.  THIS SNIPPET
// ** IS COMPRISED OF 3 FILES, TRIANGULATE.H, THE HEADER FILE FOR THE
// ** TRIANGULATE BASE CLASS, TRIANGULATE.CPP, THE IMPLEMENTATION OF
// ** THE TRIANGULATE BASE CLASS, AND TEST.CPP, A SMALL TEST PROGRAM
// ** DEMONSTRATING THE USAGE OF THE TRIANGULATOR.  THE TRIANGULATE
// ** BASE CLASS ALSO PROVIDES TWO USEFUL HELPER METHODS, ONE WHICH
// ** COMPUTES THE AREA OF A POLYGON, AND ANOTHER WHICH DOES AN EFFICENT
// ** POINT IN A TRIANGLE TEST.
// ** SUBMITTED BY JOHN W. RATCLIFF (jratcliff@verant.com) July 22, 2000

/**********************************************************************/
/************ HEADER FILE FOR TRIANGULATE.H ***************************/
/**********************************************************************/

#ifndef __UTIL_TRIANGULATE_HPP__
#define __UTIL_TRIANGULATE_HPP__

// Source: http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml

#include "pragma/networkdefinitions.h"
#include <vector>
#include <cinttypes>
#include <mathutil/glmutil.h>

namespace Geometry {
	DLLNETWORK bool triangulate(const std::vector<Vector2> &contour, std::vector<uint16_t> &result);
	DLLNETWORK float calc_area(const std::vector<Vector2> &contour);

	// decide if point Px/Py is inside triangle defined by
	// (Ax,Ay) (Bx,By) (Cx,Cy)
	DLLNETWORK bool inside_triangle(float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py);
};

#endif
