Beispiel #1
0
void
triangle_edges(Triangle *t, Edge* e[])
{
	e[0] = edge_new(t->p1, t->p2);
	e[1] = edge_new(t->p2, t->p3);
	e[2] = edge_new(t->p3, t->p1);
}
Beispiel #2
0
static solid *solid_new(vector where)
{
    solid *s = (solid*)malloc(sizeof(solid));
    face *f1, *f2;
    edge *e;
    vertex *vtx;
    hedge *h1,*h2;

    s->faces = NULL;
    s->edges = NULL;
    s->vertices = NULL;

    h1 = (hedge*)malloc(sizeof(hedge));
    h2 = (hedge*)malloc(sizeof(hedge));
    h1->next = h1->prev = h1;
    h2->next = h2->prev = h2;

    vtx = vertex_new(s, where);
    vtx->h = h1;
    h1->vtx = vtx;
    h2->vtx = vtx;

    e = edge_new(s);
    e->left = h1;
    e->right = h2;
    h1->e = e;
    h2->e = e;

    f1 = face_new(s, h1);
    f2 = face_new(s, h2);
    h1->f = f1;
    h2->f = f2;

    return s;
}
Beispiel #3
0
static vertex *vertex_split(hedge *h, vector v)
{
    hedge *h2, *hn1, *hn2;
    vertex *vtxn;
    edge *en;
    face *f1;

    f1 = h->f;
    h2 = partner(h);

    vtxn = vertex_new(f1->s, v);
    hn1 = hedge_new(h, vtxn);
    vtxn->h = hn1;
    hn2 = hedge_new(h2, vtxn);
    hn2->e = h->e;

    if(h2->e->left == h2)
        h2->e->left = hn2;
    else
        h2->e->right = hn2;

    en = edge_new(f1->s);
    en->left = hn1;
    en->right = h2;
    hn1->e = en;
    h2->e = en;
    return vtxn;
}
Beispiel #4
0
/* Lee todo un edge de `input' hasta llegar a un fin de línea o de archivo*/
edge *parse_edge(Lexer *input){
	edge *result = NULL;
	u32 x = 0; /*nodo x*/
	u32 y = 0; /*nodo y*/
	u32 cap = 0; /*capacidad de xy*/
	
	/*Pre:*/
	assert(input != NULL);
	assert(!lexer_is_off(input));

	/*No se debe encontrar al comienzo ningun caracter distinto a 'DIGIT'*/
	if (!is_the_next_char(input, ALPHA BLANK)){
		/*asigno el 1er argumento parseado a 'x'*/
		its_ok = parse_argument(input, x);
		if (its_ok && is_the_next_char(input, WHITE_SPACE)){
			/*asigno el 2do argumento parseado a 'y'*/
			its_ok = parse_argument(input, y);
			if (its_ok && is_the_next_char(input, WHITE_SPACE)){
				/*asigno el 3er argumento parseado a 'cap'*/
				its_ok = parse_argument(input, cap);
			}
		}
		/* Si se parseo todo bien, creo el nuevo edge con los valores*/
		if (it_ok){
			result = edge_new(x, y, cap);
		}
	}
	
	return result;
}
Beispiel #5
0
edge * graph_edges(graph g){
	/*alloco il necessario, per non dover allocare di nuovo.*/
	int i, j, es;
	edge*e;
	if(g == NULL)
		return NULL;
	e = malloc(sizeof(edge) * g->e);
	for(i = es = 0; i < g->v; i++)
		for(j = 0; j < g->v; j++)
			if(g->adj[i][j]){
				e[es] = edge_new(i, j, g->adj[i][j]);
				es++;
			}
	return e;
}
Beispiel #6
0
static face *face_split(face *f, hedge *h1, hedge *h2)
{
    hedge *hn1, *hn2, *tmp;
    edge *en;
    face *fn;

    if(h1->f != f || h2->f != f) {
        /*	_DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n",NULL);*/
        exit(-1);
    }
    if(h1 == h2) {
        /*	_DEBUG("Trying to split a face at a single vertex\n",NULL);*/
        exit(-1);
    }
    /* close the loops */
    h1->prev->next = h2;
    h2->prev->next = h1;
    tmp = h1->prev;
    h1->prev = h2->prev;
    h2->prev = tmp;
    /* insert halfedges & create edge */
    hn1 = hedge_new(h2->prev, h1->vtx);
    hn2 = hedge_new(h1->prev, h2->vtx);
    en = edge_new(f->s);
    en->left = hn1;
    en->right = hn2;
    hn1->e = en;
    hn2->e = en;

    /* make the new face, first find out which hedge is contained
    * in the original face, then start the new face at the other */
    tmp = f->start;
    while(tmp != h1 && tmp != h2)
        tmp = tmp->next;
    tmp = (tmp == h1) ? h2 : h1 ;
    fn = face_new(f->s, tmp);
    do {
        tmp->f = fn;
        tmp = tmp->next;
    } while(tmp != fn->start);
    fn->color = f->color;
    return fn;
}