#include "face.h"


FaceList *newFaceList(size)
int size;
{
	FaceList *f;
	int i;
	
	f = Malloc(FaceList,1);
	f->n = 0;
	f->size = size;
	f->face = Malloc(FacePtr,size);
	for(i=0;i<size;++i) *(f->face+i) = NOFACE;
	return(f);
}


Face *atFaceList(f,i)
FaceList *f;
int i;
{
	return(*(f->face+i));
}


void setNextFreeFaceList(f)
FaceList *f;
{
	int i;
	
	i = f->n;
	while(atFaceList(f,i) != NOFACE) ++i;
	f->n = i;
}


void atPutFaceList(f,i,poly)
FaceList *f;
int i;
FacePtr poly;
{
	if(f->n == f->size){
		printf("Out of space in facelist\n");
		EXIT;
	}
	*(f->face+i) = poly;
	setNextFreeFaceList(f);
}

/*
Index *makeSetFromFaceList(f)
FaceList *f;
{
	Index *ind,*last;
	register int i;
	
	ind = newIndex(0);
	last = ind;
	for(i=1; i<NEXTFreeFaceList(f); ++i)
		if(atFaceList(f,i) != NOFACE) last = addToBackIndex(last,i);
	return(ind);
}
*/

Index *makeSetFromFaceList(f)
FaceList *f;
{
	Index *ind,*last;
	register int i;
	
	ind = last = NOINDEX;
	for(i=0; i<NEXTFreeFaceList(f); ++i)
		if(atFaceList(f,i) != NOFACE) appendToIndex(&ind,i,&last);
	return(ind);
}