/*  $Id: outline_triangulator_generic.h,v 1.3 2004/04/11 15:37:31 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

#ifndef header_outline_triangulator_generic
#define header_outline_triangulator_generic

#if _MSC_VER > 1000
#pragma once
#endif

class CL_DelauneyTriangulator;
class CL_DelauneyTriangulator_Triangle;

struct CL_OutlineTriangulator_Vertex
{
	void *data;
	double x, y;
	int num_triangles;
	int extra;
	CL_DelauneyTriangulator_Triangle const **triangles;
};

struct CL_OutlineTriangulator_Contour
{
	std::vector<CL_OutlineTriangulator_Vertex> vertices;
};

struct CL_OutlineTriangulator_Polygon
{
	std::vector<CL_OutlineTriangulator_Contour> contours;
};

struct CL_OutlineTriangulator_Collision
{
	std::vector<CL_OutlineTriangulator_Vertex *> first;
	std::vector<CL_OutlineTriangulator_Vertex *> second;
	std::vector<CL_DelauneyTriangulator_Triangle const *> triangles;
};

class CL_OutlineTriangulator_Generic
{
//! Construction:
public:
	CL_OutlineTriangulator_Generic();

	~CL_OutlineTriangulator_Generic();

//! Attributes:
public:
	CL_OutlineTriangulator_Polygon current_polygon;

	CL_OutlineTriangulator_Contour current_contour;

	std::vector<CL_OutlineTriangulator_Polygon> polygons;

//	std::vector<CL_OutlineTriangulator_Triangle> triangles;

//! Operations:
public:
	void insert_points();

	void triangulate();

	void create_ordered_vertex_list(
		std::vector<CL_OutlineTriangulator_Vertex *> &vertices);

	CL_OutlineTriangulator_Collision find_colliding_triangles(
		CL_OutlineTriangulator_Vertex *v1,
		CL_OutlineTriangulator_Vertex *v2);

	void remove_triangle(CL_DelauneyTriangulator_Triangle const *t);

	CL_DelauneyTriangulator_Triangle const **add_triangles(
		CL_DelauneyTriangulator &d1,
		CL_DelauneyTriangulator &d2);

	bool intersects(
		double Ax,
		double Ay,
		double Bx,
		double By,
		double Cx,
		double Cy,
		double Dx,
		double Dy);
};

#endif
