#include "view.h"


Vertex *newVertex(size)
int size;
{
	Vertex *v;
	int i;

	v = Malloc(Vertex,1);
	v->n = 0;
	v->size = size;
	v->vertex = Malloc(Point3DPtr,size);
	for(i=0;i<size;++i) *(v->vertex+i) = NOPOINT;
	return(v);
}

void reinitialiseVertex(v)
Vertex *v;
{
	register int i;
	v->n = 0;
	for(i=0;i<v->size;++i) *(v->vertex+i) = NOPOINT;
}

/*
Point3D *atVertex(v,i)
Vertex *v;
int i;
{
	return(*(v->vertex+i));
};
*/

void setNextFreeVertex(v)
Vertex *v;
{
	int i;

	i = v->n;
	while(atVertex(v,i) != NOPOINT) ++i;
	v->n = i;
}

void atPutVertex(v,i,p)
Vertex *v;
int i;
Point3DPtr p;
{
	if(v->n >= v->size){
		printf("Run out of vertex space\n");
		printf("The size max size for this vertex is %d\n",v->size);
		EXIT;
	}
	*(v->vertex+i) = p;
	setNextFreeVertex(v);
}


void atPutCoordVertex(v,i,x,y,z)
Vertex *v;
int i;
REAL x,y,z;
{
	Point3D *p;
	p = newPoint3D(x,y,z);
	atPutVertex(v,i,p);
}


Point3D *getPointFromIndex(vertex,ind)
Vertex *vertex;
Index *ind;
{
	return(atVertex(vertex,ind->i));
}


void transformVertex(vertex,i,m)
/*changes the point at vertex i to be multiplied by m*/
Vertex *vertex;
int i;
TMatrix *m;
{
	transformPoint3D(atVertex(vertex,i),m);
}

