/*  $Id: outline_triangulator.cpp,v 1.2 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
**
*/

#include "Core/precomp.h"
#include "API/Core/Math/outline_triangulator.h"
#include "outline_triangulator_generic.h"

/////////////////////////////////////////////////////////////////////////////
// CL_OutlineTriangulator construction:

CL_OutlineTriangulator::CL_OutlineTriangulator() : impl(new CL_OutlineTriangulator_Generic)
{
}

CL_OutlineTriangulator::~CL_OutlineTriangulator()
{
}

/////////////////////////////////////////////////////////////////////////////
// CL_OutlineTriangulator attributes:

/////////////////////////////////////////////////////////////////////////////
// CL_OutlineTriangulator operations:

void CL_OutlineTriangulator::next_contour()
{
	if (impl->current_contour.vertices.empty()) return;
	impl->current_polygon.contours.push_back(impl->current_contour);
	impl->current_contour = CL_OutlineTriangulator_Contour();
}

void CL_OutlineTriangulator::next_polygon()
{
	next_contour();
	if (impl->current_polygon.contours.empty()) return;
	impl->polygons.push_back(impl->current_polygon);
	impl->current_polygon = CL_OutlineTriangulator_Polygon();
}

void CL_OutlineTriangulator::add_vertex(double x, double y, void *data)
{
	CL_OutlineTriangulator_Vertex vertex;
	vertex.x = x;
	vertex.y = y;
	vertex.data = data;
	impl->current_contour.vertices.push_back(vertex);
}

void CL_OutlineTriangulator::generate()
{
	next_polygon();
	if (impl->polygons.empty()) return;
	impl->triangulate();
}

/////////////////////////////////////////////////////////////////////////////
// CL_OutlineTriangulator implementation:
