#include "stdAfx.h"
#include "face.h"

Face::Face(int iInMaxNumVertex)
{
	pVertexIndexList = new int[iInMaxNumVertex];
	iMaxNumVertex = iInMaxNumVertex;
	iNumVertex = 0;

	setLockMem( 0 );
}

Face::~Face()
{
	freeMem();
}

void Face::addVertexIndex(int index)
{
	if(iNumVertex < iMaxNumVertex) {
		pVertexIndexList[iNumVertex] = index;
		iNumVertex++;
	}
	else {
		MessageBox( NULL, "adsfface","too many verticies", MB_OK );//throw ("too many verticies!");
	}
}

void Face::assign(Face &inFace)
{
	setLockMem( inFace.getLockMem() );

	freeMem();

	iMaxNumVertex = inFace.getMaxNumVertex();
	pVertexIndexList = new int[iMaxNumVertex];
	iNumVertex = 0;

	for(int i = 0; i < inFace.getNumVertex(); i++) {
		addVertexIndex( inFace.getVertexIndexAt(i) );
	}
}

int Face::getMaxNumVertex()
{
	return iMaxNumVertex;
}

int Face::getNumVertex()
{
	return iNumVertex;
}

int Face::getVertexIndexAt(int index)
{
	return pVertexIndexList[index];
}

void Face::setLockMem( int iNewLockMem )
{
	iLockMem = iNewLockMem;
}

int Face::getLockMem()
{
	return iLockMem;
}

void Face::freeMem()
{
//	if ( ! getLockMem() )
//	{
		delete pVertexIndexList;
//	}
}

