one more little step

This commit is contained in:
tTh 2023-04-02 22:44:35 +02:00
parent 398a5d3957
commit 6a5d00fa10
3 changed files with 62 additions and 24 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ toto
tools/*.obj tools/*.obj
! tools/minimal.obj ! tools/minimal.obj
! tools/cube.obj
tools/read_obj tools/read_obj
tools/*.xyz tools/*.xyz
tools/*.asc tools/*.asc

78
edges.c
View File

@ -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 * we have two functions for adding an edge to a list
* the first one add unconditionnaly the edge to the * the first one add unconditionnaly the edge to the
* (non full) list... * (non full) list...
@ -88,6 +108,7 @@ list->edges[list->fidx].B = p1;
list->fidx ++; list->fidx ++;
return 0; return 0;
} }
/* /*
* and the second only insert an edge if it was missing * and the second only insert an edge if it was missing
* from the currently know list. * from the currently know list.
@ -114,24 +135,6 @@ if ( ! is_edge_in_list(list, p0, p1) ) {
return 0; 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) 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, "\tnext free %8d\n", list->fidx);
fprintf(stderr, "\tmagic 0x%08lX\n", list->magic); 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; idx<list->fidx; 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; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int print_the_edges(FILE *fp, EdgeList *list, int k) int print_the_edges(FILE *fp, EdgeList *list, int k)
{ {
int foo; int idx;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k); fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k);
@ -165,9 +199,9 @@ if (k) {
fprintf(stderr, " list.fidx = %d\n", list->fidx); fprintf(stderr, " list.fidx = %d\n", list->fidx);
for (foo=0; foo<list->fidx; foo++) { for (idx=0; idx<list->fidx; idx++) {
fprintf(fp, "%6d\t\t%5d %5d\n", foo, fprintf(fp, "%6d\t\t%5d %5d\n", idx,
list->edges[foo].A, list->edges[foo].B); list->edges[idx].A, list->edges[idx].B);
} }
return -1; return -1;

View File

@ -1,13 +1,15 @@
/* /*
* edges.h * edges.h
* a part of libbubulle from tTh * a part of libbubulle from tTh
*
* https://git.tetalab.org/tTh/libbubulle
*/ */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
typedef struct { typedef struct {
int A, B; int A, B;
short burz; short burz; /* for what usage ??? */
} AnEdge; } AnEdge;
typedef struct { 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_an_edge(EdgeList *list, int p0, int p1);
int push_a_missing_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 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); int print_the_edges(FILE *file, EdgeList *list, int k);
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */