A repository of code for the book Computational Geometry in C, 2nd edition.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
1.9 KiB

#ifndef _CGC_VERTEX_H
#define _CGC_VERTEX_H
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct Vertex {
int number;
int coordinates[2];
bool ear;
struct Vertex *next;
struct Vertex *prev;
};
/**
* Initializes a new vertex struct.
* @param number The number of the vertex for identification.
* @param x X coordinate.
* @param y Y coordinate.
* @return An initialized Vertex struct.
*/
struct Vertex *new_vertex(int number, int x, int y);
/**
* Adds a vertex to a parent vertex under the assumption the parent vertex
* is the LAST vertex in the list. The reason this is necessary is because
* the list of vertices is circular, and as such the last element points
* back to the head of the list. The list will be modified in place.
*
* @param head The head of the polygon's vertex list.
* @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);
/**
* Frees a single vertex. This does not free it's next and previous pointers.
* @param vertex The vertex to free.
*/
void free_vertex(struct Vertex *vertex);
/**
* Frees an entire polygon given it's head (first) vertex.
* @param head The start of the counter-clockwise ordered polygon.
*/
void free_polygon(struct Vertex **head);
/**
* Pretty prints a vertex.
* @param vertex The vertex.
*/
void print_vertex(const struct Vertex *vertex);
/**
* Pretty prints a polygon.
* @param head The first point in the polygon.
*/
void print_polygon(const struct Vertex *head);
/**
* Traverses the polygon represented by the starting point `head` and
* sets the ear parameter correctly.
*
* @param head
*/
void init_ear(struct Vertex *head);
/**
* Counts the number of vertices in a polygon.
* @param head The start vertex of the polygon.
* @return The count of vertices.
*/
int vertex_count(const struct Vertex *head);
#endif // _CGC_VERTEX_H