-
Notifications
You must be signed in to change notification settings - Fork 0
/
individual_util.c
58 lines (49 loc) · 1.5 KB
/
individual_util.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
#include <stdlib.h>
#include "navigation.h"
#include "sighting.h"
#include "individual.h"
/*
* Takes in two sightings, then returns the distance between the two of them.
*/
double get_distance(sighting *sighting1, sighting *sighting2) {
return great_circle(get_location(sighting1), get_location(sighting2));
}
/*
* Takes in two sightings and returns if they are the same creature.
*/
int is_individual (sighting *sighting1, sighting *sighting2) {
return (get_distance(sighting1, sighting2) < 0.02) &&
sighting1->species == sighting2->species;
}
/*
* Takes in a linked list of individuals and removes any duplicates
*/
void tidy_individuals(individual_list *list) {
individual_list *current;
for (current = list; current != NULL; current = current->next) {
individual_list *test;
individual_list *last = current;
for (test = current->next; test != NULL; test = test->next) {
if (ind_contains(current, test)) {
last->next = test->next;
free(test);
}
else {
last = test;
}
}
}
}
/*
* Returns 1 if main contains other, or 0 if not.
*/
int ind_contains(individual_list *main, individual_list *other) {
sighting_list *current = main->content->sightings;
sighting_list *test = other->content->sightings;
while ((current = current->next) != NULL) {
if (current->content == test->content) {
return 1;
}
}
return 0;
}