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; }
static void do_graph_bfs(Graph g, Vertex v, Visitor visit) { uint8_t vert_state[MAX_VERTS] = {1}; QueueResult res; uint8_t u = v.id, w; Queue queue = queue_new(0); Queue *q = &queue; queue_add(q, u, &res); while (!queue_empty(q)) { queue_remove(q, &res); assert(res.status == QUEUE_OK); u = res.data; if (!VISITED_VERTEX(vert_state[u])) { vert_state[u] = MARK_VISITED_VERTEX(vert_state[u]); /* call the function that is interested in the visited vertex */ visit(vertex_new(u, g.labels[u], 0)); /* push each neighbors of vertex u on the stack */ for (w = 0; w < g.vc; ++w) { if (w != u && g.adj[u][w]) { queue_add(q, w, &res); assert(res.status == QUEUE_OK); } } } } }
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; }
static void graph_nEWvERTEXlIST (Graph g, int numberOfVertices) { int i; Vertex v; assert (!element_null (g)); /* New vertex list. */ list_init (&(g->vertices)); for (i = 0; i < numberOfVertices; i++) list_append (vertex_new (&v, i), &(g->vertices)); }
/** Create a new graph with given vertex count */ graph_t* graph_new_with_count(size_t vertex_count) { graph_t* ret = (graph_t*)malloc(sizeof(graph_t)); size_t i; assert(ret != NULL); if (vertex_count == 0) ret->v = NULL; else ret->v = (vertex_t**)malloc(sizeof(vertex_t**) * vertex_count); for (i = 0; i < vertex_count; ++i) ret->v[i] = vertex_new(); ret->size = ret->capacity = vertex_count; return ret; }
void graph_bfs(Graph g, Visitor visit) { Vertex root = vertex_new(0, g.labels[g.vc-1], 0); do_graph_bfs(g, root, visit); }
void gui_add_vertex (gui *g, int x, int y) { poly_add (g->poly, vertex_new (x, y)); gui_draw_all (g); }
static INLINE struct vertex *polyfill_add(struct vertex **top, struct array *a, int arg, char* what) { struct vertex *first,*last,*cur = NULL; int n; if( (a->type_field & ~(BIT_INT|BIT_FLOAT)) && (array_fix_type_field(a) & ~(BIT_INT|BIT_FLOAT)) ) { polyfill_free(*top); Pike_error("Illegal argument %d to %s. %d Expected array(float|int).\n",arg,what, a->type_field); return NULL; } if (a->size<6) { return *top; #if 0 polyfill_free(*top); Pike_error("Illegal argument %d to %s, too few vertices (min 3)\n", arg, what); return NULL; /* no polygon with less then tree corners */ #endif } #define POINT(A,N) (((A)->item[N].type==T_FLOAT)?((A)->item[N].u.float_number):((FLOAT_TYPE)((A)->item[N].u.integer))) last = first = vertex_new(DO_NOT_WARN(POINT(a,0)), DO_NOT_WARN(POINT(a,1)), top); if (!last) { return NULL; } for (n=2; n+1<a->size; n+=2) { cur = vertex_new(DO_NOT_WARN(POINT(a,n)), DO_NOT_WARN(POINT(a,n+1)), top); if (!cur) { return NULL; } if (cur->y<last->y) vertex_connect(cur,last); else if (cur->y>last->y) vertex_connect(last,cur); else if (cur->x<last->x) vertex_connect(cur,last); else vertex_connect(last,cur); last=cur; } if (cur->y<first->y) vertex_connect(cur,first); else if (cur->y>first->y) vertex_connect(first,cur); else if (cur->x<first->x) vertex_connect(cur,first); else vertex_connect(first,cur); return *top; }