示例#1
0
文件: sys.c 项目: ilyak/vimol
void
sys_add_atom(struct sys *sys, const char *name, vec_t xyz)
{
	struct atoms *atoms = sys_get_atoms(sys, sys->current_frame);

	assert(sys_single_frame(sys));

	atoms_add(atoms, name, xyz);
	graph_vertex_add(sys->graph);
	sel_expand(sys->sel);
	sel_expand(sys->visible);
	sel_add(sys->visible, sel_get_size(sys->visible) - 1);

	sys->is_modified = TRUE;
}
示例#2
0
文件: graph.c 项目: ilyak/vimol
struct graph *
graph_copy(struct graph *graph)
{
    struct graph *copy;
    struct edge *edge;
    int i;

    copy = graph_create();

    for (i = 0; i < graph_get_vertex_count(graph); i++)
        graph_vertex_add(copy);

    for (i = 0; i < graph_get_vertex_count(graph); i++)
        for (edge = graph->edges[i]; edge; edge = edge->next)
            graph_edge_create(copy, edge->i, edge->j, edge->type);

    return (copy);
}
示例#3
0
int main() {
    struct graph *g = graph_create();
    if (g == NULL) {
        printf("malloc error\n");
        return 1;
    }
    int values[] = {0, 1, 2, 3, 4, 5, 6, 7};
    int len = sizeof(values)/sizeof(values[0]);
    struct vertex *vertices[len];
    for (int i = 0; i < len; ++i) {
        vertices[i] = graph_vertex_add(g, values[i]);
        assert(vertices[i]);
        printf("Added vertex %p\n", vertices[i]);
    }
    graph_edge_add(g, vertices[0], vertices[7], 7);
    graph_edge_add(g, vertices[0], vertices[5], 5);
    graph_edge_add(g, vertices[0], vertices[3], 3);
    graph_edge_add(g, vertices[2], vertices[6], 8);
    graph_edge_add(g, vertices[5], vertices[4], 9);
    graph_edge_remove(g, vertices[0], vertices[7]);
    graph_edge_remove(g, vertices[0], vertices[5]);
    graph_edge_remove(g, vertices[2], vertices[6]);
    graph_edge_remove(g, vertices[5], vertices[4]);
    graph_edge_add(g, vertices[0], vertices[7], 7);
    graph_vertex_remove(g, vertices[0]);
    graph_print(g);

    graph_vertex_remove(g, vertices[1]);
    graph_vertex_remove(g, vertices[2]);
    graph_vertex_remove(g, vertices[3]);
    graph_vertex_remove(g, vertices[4]);
    graph_vertex_remove(g, vertices[5]);
    graph_vertex_remove(g, vertices[6]);
    graph_vertex_remove(g, vertices[7]);

    assert(graph_vertex_num(g) == 0);

    graph_destroy(g);

    return 0;
}