-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharea.cpp
60 lines (46 loc) · 1.4 KB
/
area.cpp
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
#include "headers/area.h"
ostream& operator<<(ostream& os, const Area& a)
{
os << "{ ";
for (int j = 0; j < a.size(); ++j)
{
os << "Con:" << *(a[j]->line);
if (j+1 != a.size())
os << ",";
os << " ";
}
os << "}";
return os;
}
/*
* Until we test this, we shouldn't define it since when we use the standard
* libraries it will call this equality operator.
*/
bool operator==(const Area& a,const Area& b)
{
int i = 0;
bool clockWise = true;
bool countWise = true;
if (a.size() != b.size()) return false;
if (a.size() == 0) return true;
//find the point a common point between the two areas
for (; i < b.size() && a[0]->line != b[i]->line; i++);
//if we've reached the end and there are no matches
if (i == b.size()-1 && a[0]->line != b[i]->line) return false;
//run find the first element in clockwise roation that is not equal,
//then do the same for counterclockwise.
for (int j=0;j<a.size()&& clockWise;j++)
{
if (a[j]->line!=b[(i+j)%a.size()]->line) clockWise = false;
}
for (int j=0;j<(a.size())&& countWise;j++)
{
if (a[j]->line!=b[abs(i-j)%(a.size())]->line) countWise = false;
}
// the areas match if at least one of the checks didnt find any differences
return (clockWise || countWise);
}
bool operator!=(const Area& a,const Area& b)
{
return !(a==b);
}