2021-09-08 21:48:00 +10:00
|
|
|
/* main.c
|
|
|
|
*
|
|
|
|
* Created by Rory Healy (healyr@student.unimelb.edu.au)
|
|
|
|
* Created on 25th August 2021
|
2021-09-15 00:06:04 +10:00
|
|
|
* Last modified 14th September 2021
|
2021-09-08 21:48:00 +10:00
|
|
|
*
|
2021-09-15 00:06:04 +10:00
|
|
|
* Stage 1: Computes and outputs equations for the bisectors of points
|
|
|
|
* Stage 2: Computes and outputs intersection points for bisectors against a
|
|
|
|
* given polygon
|
|
|
|
* Stage 3: Computes a Voronoi diagram using watchtowers as points and a
|
|
|
|
* polygon as the outer boundary. Outputs diameters of each Voronoi
|
|
|
|
* cell along with information about each watchtower.
|
|
|
|
* Stage 4: Same as Stage 4, but the watchtowers are sorted by ascending order
|
|
|
|
* by diameter.
|
2021-09-08 21:48:00 +10:00
|
|
|
*
|
2021-09-08 22:22:48 +10:00
|
|
|
* To see valid input arguments, run ./voronoi2
|
2021-09-15 00:06:04 +10:00
|
|
|
*
|
2021-09-08 21:48:00 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VORONOI_HEADER
|
|
|
|
#include "voronoi.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INPUT_HEADER
|
|
|
|
#include "input.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
/* Ensure input arguments are correct */
|
2021-09-08 22:22:48 +10:00
|
|
|
if (argc == 1) {
|
|
|
|
printArgError(STAGE_ERROR, "Incorrect usage.");
|
|
|
|
}
|
2021-09-15 00:06:04 +10:00
|
|
|
|
|
|
|
/* Get stage, ensure correct input args */
|
2021-09-08 21:48:00 +10:00
|
|
|
enum stages stage = getStage(argv[1]);
|
|
|
|
int expectedArgs = getExpectedArgs(stage);
|
|
|
|
if (expectedArgs != argc) {
|
|
|
|
printArgError(stage, "Incorrect number of inputs.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then run the program according to the stage given */
|
|
|
|
switch(stage) {
|
|
|
|
/* Expected usage: ./voronoi2 1 pointsFile outputFile */
|
2021-09-09 17:10:24 +10:00
|
|
|
case STAGE_1:
|
|
|
|
stage1(argv[2], argv[3]);
|
2021-09-08 21:48:00 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Expected usage: ./voronoi2 2 pointsFile polygonFile outputFile */
|
2021-09-09 17:10:24 +10:00
|
|
|
case STAGE_2:
|
|
|
|
stage2(argv[2], argv[3], argv[4]);
|
2021-09-08 21:48:00 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Expected usage: ./voronoi2 3 dataFile polygonFile outputFile */
|
2021-09-09 17:10:24 +10:00
|
|
|
case STAGE_3:
|
|
|
|
stage3(argv[2], argv[3], argv[4]);
|
2021-09-08 21:48:00 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Expected usage: /voronoi2 4 dataFile polygonFile outputFile */
|
2021-09-09 17:10:24 +10:00
|
|
|
case STAGE_4:
|
|
|
|
stage4(argv[2], argv[3], argv[4]);
|
2021-09-08 21:48:00 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Return error if stage number isn't defined. */
|
|
|
|
case STAGE_ERROR:
|
|
|
|
default:
|
2021-09-13 12:27:17 +10:00
|
|
|
printArgError(stage, "Invalid stage entered.");
|
2021-09-08 21:48:00 +10:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|