diff --git a/.gitignore b/.gitignore index 94e8588..2cb0994 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ toto tools/*.obj ! tools/minimal.obj +! tools/cube.obj tools/read_obj tools/*.xyz tools/*.asc diff --git a/edges.c b/edges.c index 209bf59..7e0ba49 100644 --- a/edges.c +++ b/edges.c @@ -65,6 +65,26 @@ return 0; } /* --------------------------------------------------------------------- */ /* + * with this func, you can search for duplicates, but + * it is going to be SLOW with huges object. + */ +static int is_edge_in_list(EdgeList *list, int p0, int p1) +{ +int idx; + +for (idx=0; idx < list->fidx; idx++) { + if ( (list->edges[idx].A == p0) && + (list->edges[idx].B == p1) ) return 1; + + if ( (list->edges[idx].A == p1) && + (list->edges[idx].B == p0) ) return 2; + } + +return 0; /* NOT FOUND */ +} +/* --------------------------------------------------------------------- */ +/* + * * we have two functions for adding an edge to a list * the first one add unconditionnaly the edge to the * (non full) list... @@ -88,6 +108,7 @@ list->edges[list->fidx].B = p1; list->fidx ++; return 0; } + /* * and the second only insert an edge if it was missing * from the currently know list. @@ -114,24 +135,6 @@ if ( ! is_edge_in_list(list, p0, p1) ) { return 0; } /* --------------------------------------------------------------------- */ -/* - * with this func, you can search for duplicates - */ -int is_edge_in_list(EdgeList *list, int p0, int p1) -{ -int idx; - -for (idx=0; idx < list->fidx; idx++) { - if ( (list->edges[idx].A == p0) && - (list->edges[idx].B == p1) ) return 1; - - if ( (list->edges[idx].A == p1) && - (list->edges[idx].B == p0) ) return 2; - } - -return 0; /* NOT FOUND */ -} -/* --------------------------------------------------------------------- */ int print_edgelist_desc(EdgeList *list, int k) { @@ -147,12 +150,43 @@ fprintf(stderr, "\tsize %8d\n", list->size); fprintf(stderr, "\tnext free %8d\n", list->fidx); fprintf(stderr, "\tmagic 0x%08lX\n", list->magic); +return 0; +} +/* --------------------------------------------------------------------- */ +/* + * /!\ the output format is subject to changes in + * a near futur. + */ +int edges_to_data(char *fname, EdgeList *list, int k) +{ +FILE *fp; +int idx, foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, list, k); +#endif + +if (NULL==(fp=fopen(fname, "w"))) { + perror(fname); + return -1; + } +for (idx=0; idxfidx; idx++) { + foo = fprintf(fp, "%d %d\n", list->edges[idx].A, list->edges[idx].B); + /* + * error check + */ + if (foo < 0) { + perror(fname); + exit(1); /* be violent ! */ + } + } +fclose(fp); return 0; } /* --------------------------------------------------------------------- */ int print_the_edges(FILE *fp, EdgeList *list, int k) { -int foo; +int idx; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k); @@ -165,9 +199,9 @@ if (k) { fprintf(stderr, " list.fidx = %d\n", list->fidx); -for (foo=0; foofidx; foo++) { - fprintf(fp, "%6d\t\t%5d %5d\n", foo, - list->edges[foo].A, list->edges[foo].B); +for (idx=0; idxfidx; idx++) { + fprintf(fp, "%6d\t\t%5d %5d\n", idx, + list->edges[idx].A, list->edges[idx].B); } return -1; diff --git a/edges.h b/edges.h index 109a5d3..ea47a50 100644 --- a/edges.h +++ b/edges.h @@ -1,13 +1,15 @@ /* * edges.h * a part of libbubulle from tTh + * + * https://git.tetalab.org/tTh/libbubulle */ /* --------------------------------------------------------------------- */ typedef struct { int A, B; - short burz; + short burz; /* for what usage ??? */ } AnEdge; typedef struct { @@ -26,9 +28,10 @@ int free_edgelist(EdgeList *list, int k); int push_an_edge(EdgeList *list, int p0, int p1); int push_a_missing_edge(EdgeList *list, int p0, int p1); -int is_edge_in_list(EdgeList *list, int p0, int p1); +// int is_edge_in_list(EdgeList *list, int p0, int p1); int print_edgelist_desc(EdgeList *list, int k); +int edges_to_data(char *fname, EdgeList *list, int k); int print_the_edges(FILE *file, EdgeList *list, int k); /* --------------------------------------------------------------------- */