-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconvertcoordinate.cpp
114 lines (89 loc) · 2.11 KB
/
convertcoordinate.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <sstream>
#include <stdlib.h>
#include "convertcoordinate.h"
std::string convertcoordinate::toString(char separator)
{
std::stringstream ss;
ss << values[0];
ss << separator;
ss << values[1];
ss << separator;
ss << values[2];
return ss.str();
}
convertcoordinate::convertcoordinate()
{
values.resize(3, LONG_MIN);
};
convertcoordinate::convertcoordinate(const convertcoordinate& other)
{
values.resize(3, LONG_MIN);
values[0] = other.values[0];
values[1] = other.values[1];
values[2] = other.values[2];
};
long& convertcoordinate::operator[](int i){return values[i];};
long& convertcoordinate::at(int i){return values[i];};
convertcoordinate& convertcoordinate::operator=(const convertcoordinate& other)
{
values.resize(3, LONG_MIN);
values[0] = other.values[0];
values[1] = other.values[1];
values[2] = other.values[2];
return *this;
};
bool convertcoordinate::operator==(const convertcoordinate& other)
{
bool equal = true;
equal = equal && (values[0] == other.values[0]);
equal = equal && (values[1] == other.values[1]);
equal = equal && (values[2] == other.values[2]);
return equal;
};
bool convertcoordinate::isPrimalCorner(int val)
{
int odd = 0;
for(int i=0; i<3; i++)
odd += ((values[0] - 1) % val);
return (odd == 0);//TODO
}
bool convertcoordinate::isDualCorner(int val)
{
return !isPrimalCorner(val);
}
bool convertcoordinate::isPrimalCenter(int val)
{
//tre sa clarific odata ce pula mea e DELTA
//si care este influenta lui asupra coordonatelor primare si duale
int odd = 0;
for(int i=0; i<3; i++)
odd += (values[0] % val);
return (odd == 3);//TODO
}
bool convertcoordinate::isDualCenter(int val)
{
return !isPrimalCenter(val);
}
long convertcoordinate::manhattanDistance(convertcoordinate& other)
{
long dist = 0;
for(int i=0; i<3; i++)
dist += abs(values[i] - other.values[i]);
return dist;
}
bool convertcoordinate::isColinear(convertcoordinate& other)
{
int eq = 0;
for(int i=0; i<3; i++)
{
if(other.values[i] == values[i])
eq++;
}
return (eq == 2);
}
void convertcoordinate::reset()
{
values[0] = LONG_MIN;
values[1] = LONG_MIN;
values[2] = LONG_MIN;
}