-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod_utils.c
63 lines (57 loc) · 1.59 KB
/
pod_utils.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
#include <stdlib.h>
#include "navigation.h"
#include "sighting.h"
#include "individual.h"
#include "pod.h"
/*
* Takes in a linked list of individuals and removes any duplicates
*/
void tidy_pods(pod_list *list) {
pod_list *current;
for (current = list; current != NULL; current = current->next) {
pod_list *test;
pod_list *last = current;
for (test = current->next; test != NULL; test = test->next) {
if (pod_contains(current, test)) {
last->next = test->next;
free(test);
}
else {
last = test;
}
}
}
}
/*
* Returns 1 if main contains other, or 0 if not.
*/
int pod_contains(pod_list *main, pod_list *other) {
individual_list *current = main->content->individuals;
individual_list *test = other->content->individuals;
while ((current = current->next) != NULL) {
if (current->content->position.lat == test->content->position.lat &&
current->content->position.lng == test->content->position.lng) {
return 1;
}
}
return 0;
}
/*
* Recursively find if mammal is close enough to any others to be in pod
*/
int is_close(individual *to_test, individual_list *list) {
if (list->next == NULL) {
if (great_circle(to_test->position, list->content->position) < 0.1) {
return 1;
}
else {
return 0;
}
}
if (great_circle(to_test->position, list->content->position) < 0.1) {
return 1;
}
else {
return is_close(to_test, list->next);
}
}