This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
83 lines (64 loc) · 2.34 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Daniel Carvalho Dantas 10685702
Lucas Viana Vilela 10748409
*/
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "./ADTs/stack.h"
#include "./ADTs/list.h"
#include "monotone-chain.h"
// #include "./time/tempo.h"
int main(){
int noPoints; // Total number of points
char outputStart; // In which element the output must start
int outputOrientation; // Clockwise x Counter-Clockwise
float pointsPercentage; // Fraction between points on the hull and the whole
// Gets quantity
scanf("%d", &noPoints);
list* allPoints = list_create(noPoints);
point auxPoint; // Auxiliar variable
// Gets points and appends them to the allPoints list
for(int i = 0; i < noPoints; i++){
scanf("%lf", &auxPoint.x);
scanf("%lf", &auxPoint.y);
list_append(allPoints,auxPoint);
}
// Gets output info
scanf(" %c", &outputStart);
scanf("%d", &outputOrientation);
// // Start timer
// double interval = seconds();
// Gets this group of points' convex hull
list* hull = convexHull(allPoints);
// // Time interval used to calculate the hull
// interval = seconds() - interval;
// If the hull is null, it means the algorithm wasn't able
// to determine the hull (because all points are collinear)
if(hull == NULL){
printf("ERRO\n");
}
// If a convex hull weas successfully determined
else{
// Calculates the percentage
pointsPercentage = 100*((float) list_getLength(hull) / (float) noPoints);
// Sorts the list accordingly to input specifications
list_orientate(hull, outputOrientation, list_searchExtreme(hull, outputStart));
// Prints the hull according to designated output format (starting point and orientation)
list_print(hull);
// Prints the percentage
printf("%.2f\n", pointsPercentage);
// Frees allocated memory
list_delete(&hull);
}
// Frees allocated memory
list_delete(&allPoints);
// // Opens file in which the time interval measured'll be written
// FILE* f = fopen("./results/time-intervals.out", "a");
// if(f == NULL) { return 1; }
// // Writes time interval to file
// fprintf(f,"Input size: %15d | Time interval: %15lfs\n", noPoints, interval);
// // Closes the file
// fclose(f);
return 0;
}