From 2551efe8eddeac26ad837e25797138e79e9fa652 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Sun, 26 Jan 2020 16:56:29 -0800 Subject: [PATCH] Small pointer improvements (removed some double pointers that weren't needed) --- include/vertex.h | 4 ++-- src/main.c | 40 +++++++++++++++++----------------------- src/vertex.c | 13 ++++++------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/include/vertex.h b/include/vertex.h index cbd56ff..989a9d0 100644 --- a/include/vertex.h +++ b/include/vertex.h @@ -32,8 +32,8 @@ struct Vertex *new_vertex(int number, int x, int y); * @param parent The parent vertex to add the new one to. * @param child The child vertex. */ -void add_vertex(struct Vertex **head, struct Vertex **parent, - struct Vertex **child); +void add_vertex(struct Vertex *head, struct Vertex *parent, + struct Vertex *child); /** * Frees a single vertex. This does not free it's next and previous pointers. diff --git a/src/main.c b/src/main.c index 3330750..db3d3c2 100644 --- a/src/main.c +++ b/src/main.c @@ -24,27 +24,23 @@ void chapter1() { struct Vertex *v16 = new_vertex(16, -2, 9); struct Vertex *v17 = new_vertex(17, 5, 5); - // TODO: You may be able to change this back to normal as long as you're - // using -> to set the value on the struct. This is interpreted - // as (*thing).xyz so you are doing too much work on pointers - // in this. - add_vertex(&v0, &v0, &v1); - add_vertex(&v0, &v1, &v2); - add_vertex(&v0, &v2, &v3); - add_vertex(&v0, &v3, &v4); - add_vertex(&v0, &v4, &v5); - add_vertex(&v0, &v5, &v6); - add_vertex(&v0, &v6, &v7); - add_vertex(&v0, &v7, &v8); - add_vertex(&v0, &v8, &v9); - add_vertex(&v0, &v9, &v10); - add_vertex(&v0, &v10, &v11); - add_vertex(&v0, &v11, &v12); - add_vertex(&v0, &v12, &v13); - add_vertex(&v0, &v13, &v14); - add_vertex(&v0, &v14, &v15); - add_vertex(&v0, &v15, &v16); - add_vertex(&v0, &v16, &v17); + add_vertex(v0, v0, v1); + add_vertex(v0, v1, v2); + add_vertex(v0, v2, v3); + add_vertex(v0, v3, v4); + add_vertex(v0, v4, v5); + add_vertex(v0, v5, v6); + add_vertex(v0, v6, v7); + add_vertex(v0, v7, v8); + add_vertex(v0, v8, v9); + add_vertex(v0, v9, v10); + add_vertex(v0, v10, v11); + add_vertex(v0, v11, v12); + add_vertex(v0, v12, v13); + add_vertex(v0, v13, v14); + add_vertex(v0, v14, v15); + add_vertex(v0, v15, v16); + add_vertex(v0, v16, v17); init_ear(v0); @@ -52,8 +48,6 @@ void chapter1() { triangulate(v0); - //print_polygon(v0); - free_polygon(&v0); } diff --git a/src/vertex.c b/src/vertex.c index 01fb98f..61e8472 100644 --- a/src/vertex.c +++ b/src/vertex.c @@ -18,13 +18,13 @@ struct Vertex *new_vertex(int number, int x, int y) return newv; } -void add_vertex(struct Vertex **head, struct Vertex **parent, - struct Vertex **child) +void add_vertex(struct Vertex *head, struct Vertex *parent, + struct Vertex *child) { - (*parent)->next = *child; - (*child)->prev = *parent; - (*child)->next = *head; - (*head)->prev = *child; + parent->next = child; + child->prev = parent; + child->next = head; + head->prev = child; }; void free_vertex(struct Vertex *vertex) @@ -57,7 +57,6 @@ void print_vertex(const struct Vertex *vertex) void print_polygon(const struct Vertex *head) { const struct Vertex *v = head->next; - printf("-------"); while(v != head) { print_vertex(v); v = v->next;