From 582bc2d5e06d0541029bafcb38d962dcb63af4dd Mon Sep 17 00:00:00 2001 From: Luc Girod Date: Mon, 5 May 2014 09:06:49 +0200 Subject: [PATCH] Bug: uniqueness of vertices with big mesh. --- sweet_geometry.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sweet_geometry.c b/sweet_geometry.c index b1e5e1e..afdfc35 100644 --- a/sweet_geometry.c +++ b/sweet_geometry.c @@ -98,7 +98,8 @@ face_free (struct face_item * root) struct item { struct item * next; - unsigned int hash; + unsigned int a; + unsigned int b; unsigned int id; }; @@ -139,25 +140,26 @@ map_free (struct map * map) } static struct item * -map_get_item (struct map * map, unsigned int hash) +map_get_item (struct map * map, unsigned int hash, unsigned int a, unsigned int b) { struct item * item = map->items[hash % MAP_SIZE]; - while (item != NULL && item->hash != hash) { item = item->next; } + while (item != NULL && item->a != a && item->b != b) { item = item->next; } return item; } static int -map_add_item (struct map * map, unsigned int hash, int id) +map_add_item (struct map * map, unsigned int hash, unsigned int a, unsigned int b, int id) { struct item * next; struct item * item; - if (map_get_item (map, hash) != NULL) { return 0; } + if (map_get_item (map, hash, a, b) != NULL) { return 0; } next = map->items[hash % MAP_SIZE]; item = malloc (sizeof (struct item)); if (item == NULL) { return -1; } - item->hash = hash; + item->a = a; + item->b = b; item->next = next; item->id = id; @@ -202,12 +204,12 @@ middle_point_v (struct map * map, int * state, vec3 middle; hash = hash_2_int (a, b); - item = map_get_item (map, hash); + item = map_get_item (map, hash, a, b); id = v->nb_vertices; if (item != NULL) { *state = 0; return item->id; } - if (map_add_item (map, hash, id) == -1) { *state = -1; return 0; } + if (map_add_item (map, hash, a, b, id) == -1) { *state = -1; return 0; } *state = 1; middle = sweet_vector_middle3 (v->vertices[a], v->vertices[b]);