2021-09-08 21:48:00 +10:00
|
|
|
/* dcel.c
|
|
|
|
*
|
|
|
|
* Created by Rory Healy (healyr@student.unimelb.edu.au)
|
|
|
|
* Created on 25th August 2021
|
2021-09-09 17:10:24 +10:00
|
|
|
* Last modified 9th September 2021
|
2021-09-08 21:48:00 +10:00
|
|
|
*
|
|
|
|
* Contains functions for the DCEL data structure, including creating,
|
|
|
|
* splitting an edge, and identifying towers in faces.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DCEL_HEADER
|
|
|
|
#include "dcel.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef COMMON_HEADER
|
|
|
|
#include "common.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Reads the polygon file and stores the information in the vertices array. */
|
2021-09-09 17:10:24 +10:00
|
|
|
vertex_t **readPolygon(vertex_t **vertices, FILE *polygonFile, \
|
|
|
|
int *numVertices) {
|
2021-09-08 21:48:00 +10:00
|
|
|
double currentX, currentY;
|
|
|
|
int maxSizeVertices = 1;
|
|
|
|
while ((fscanf(polygonFile, "%lf %lf", ¤tX, ¤tY)) != EOF) {
|
|
|
|
/* Check if there enough space in the towers array */
|
|
|
|
if (*numVertices == maxSizeVertices) {
|
|
|
|
maxSizeVertices *= 2;
|
2021-09-09 17:10:24 +10:00
|
|
|
vertex_t **temp = realloc(vertices, \
|
|
|
|
maxSizeVertices * sizeof(*vertices));
|
2021-09-08 21:48:00 +10:00
|
|
|
checkNullPointer(temp);
|
|
|
|
vertices = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The current vertex being filled in with information */
|
|
|
|
vertices[*numVertices] = malloc(sizeof(*vertices[*numVertices]));
|
|
|
|
vertices[*numVertices]->x = currentX;
|
|
|
|
vertices[*numVertices]->y = currentY;
|
|
|
|
*numVertices += 1;
|
|
|
|
}
|
|
|
|
return vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freeVertices(vertex_t **vertices, int numVertices) {
|
|
|
|
for (int i = 0; i < numVertices; i++) {
|
|
|
|
free(vertices[i]);
|
|
|
|
}
|
|
|
|
free(vertices);
|
|
|
|
}
|