/*------------------------------------------------------------------------------*/
GW_Face* GW_VoronoiMesh::FindMaxFace( GW_GeodesicVertex& Vert )
{
	GW_Float rBestDistance = -GW_INFINITE;
	GW_Face* pCurFace_ = NULL;
	for( GW_VertexIterator it = Vert.BeginVertexIterator(); it!=Vert.EndVertexIterator(); ++it )
	{
		GW_GeodesicVertex* pVert = (GW_GeodesicVertex*)  *it;
		if( pVert->GetDistance()>rBestDistance )
		{
			rBestDistance = pVert->GetDistance();
			GW_GeodesicVertex* pVert1 = (GW_GeodesicVertex*) it.GetLeftVertex();
			GW_GeodesicVertex* pVert2 = (GW_GeodesicVertex*) it.GetRightVertex();
			if( pVert1!=NULL && pVert2!=NULL )
			{
				if( pVert1->GetDistance()<pVert2->GetDistance() )
					pCurFace_ = it.GetLeftFace();
				else
					pCurFace_ = it.GetRightFace();
			}
			else if( pVert1!=NULL )
			{
				pCurFace_ = it.GetLeftFace();
			}
			else
			{
				GW_ASSERT( pVert2!=NULL );
				pCurFace_ = it.GetRightFace();
			}
		}
	}	
	return pCurFace_;
}
/*------------------------------------------------------------------------------*/
GW_Bool GW_Vertex::IsBoundaryVertex()
{
	for( GW_VertexIterator it = this->BeginVertexIterator(); it!=this->EndVertexIterator(); ++it )
	{
		if( it.GetLeftFace()==NULL || it.GetRightFace()==NULL )
			return GW_True;
	}
	return GW_False;
}
/*------------------------------------------------------------------------------*/
void GW_GeodesicPath::AddVertexToPath( GW_GeodesicVertex& Vert )
{
	pPrevFace_ = pCurFace_;
	GW_Float rBestDistance = GW_INFINITE;
	pCurFace_ = NULL;
	GW_GeodesicVertex* pSelectedVert = NULL;
	for( GW_VertexIterator it = Vert.BeginVertexIterator(); it!=Vert.EndVertexIterator(); ++it )
	{
		GW_GeodesicVertex* pVert = (GW_GeodesicVertex*)  *it;
		if( pVert->GetDistance()<rBestDistance )
		{
			rBestDistance = pVert->GetDistance();
			pSelectedVert = pVert;
			GW_GeodesicVertex* pVert1 = (GW_GeodesicVertex*) it.GetLeftVertex();
			GW_GeodesicVertex* pVert2 = (GW_GeodesicVertex*) it.GetRightVertex();
			if( pVert1!=NULL && pVert2!=NULL )
			{
				if( pVert1->GetDistance()<pVert2->GetDistance() )
					pCurFace_ = (GW_GeodesicFace*) it.GetLeftFace();
				else
					pCurFace_ = (GW_GeodesicFace*) it.GetRightFace();
			}
			else if( pVert1!=NULL )
			{
				pCurFace_ = (GW_GeodesicFace*) it.GetLeftFace();
			}
			else
			{
				GW_ASSERT( pVert2!=NULL );
				pCurFace_ = (GW_GeodesicFace*) it.GetRightFace();
			}
		}
	}
	GW_ASSERT( pCurFace_!=NULL );
	GW_ASSERT( pSelectedVert!=NULL );

	GW_GeodesicPoint* pPoint = new GW_GeodesicPoint;
	Path_.push_back( pPoint );
	pPoint->SetVertex1( Vert );
	pPoint->SetVertex2( *pSelectedVert );
	pPoint->SetCoord(1);
	pPoint->SetCurFace( *pCurFace_ );
}