-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge.cpp
105 lines (86 loc) · 1.99 KB
/
edge.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
#include "edge.h"
Edge::Edge(vec4 a, vec4 b) :
boundary_(true)
{
vertices_.push_back(a);
vertices_.push_back(b);
double size_a = magnitude(a);
double size_b = magnitude(b);
hash_key_ = new std::vector<vec4>();
size_a < size_b ? hash_key_->push_back(a) : hash_key_->push_back(b);
size_b > size_a ? hash_key_->push_back(b) : hash_key_->push_back(a);
}
bool Edge::Compare(const Edge* e) const
{
if (hash_key_->size() != 2) {
return false;
}
if (hash_key_->at(0).x != e->hash_key_->at(0).x) {
return false;
}
if (hash_key_->at(0).y != e->hash_key_->at(0).y) {
return false;
}
if (hash_key_->at(0).z != e->hash_key_->at(0).z) {
return false;
}
if (hash_key_->at(0).w != e->hash_key_->at(0).w) {
return false;
}
if (hash_key_->at(1).x != e->hash_key_->at(1).x) {
return false;
}
if (hash_key_->at(1).y != e->hash_key_->at(1).y) {
return false;
}
if (hash_key_->at(1).z != e->hash_key_->at(1).z) {
return false;
}
if (hash_key_->at(1).w != e->hash_key_->at(1).w) {
return false;
}
return true;
}
vec4 Edge::GetA()
{
return vertices_.at(0);
}
vec4 Edge::GetB()
{
return vertices_.at(1);
}
// Ignores divide by 0 error
std::vector <vec3> Edge::GetEdgeDividedByW()
{
std::vector<vec3> new_edge;
vec3 a;
a.x = vertices_.at(0).x / vertices_.at(0).w;
a.y = vertices_.at(0).y / vertices_.at(0).w;
a.z = vertices_.at(0).z / vertices_.at(0).w;
new_edge.push_back(a);
vec3 b;
b.x = vertices_.at(1).x / vertices_.at(1).w;
b.y = vertices_.at(1).y / vertices_.at(1).w;
b.z = vertices_.at(1).z / vertices_.at(1).w;
new_edge.push_back(b);
return new_edge;
}
void Edge::PrintEdge()
{
std::cout << "(";
std::cout << vertices_.at(0).x;
std::cout << ", ";
std::cout << vertices_.at(0).y;
std::cout << ", ";
std::cout << vertices_.at(0).z;
std::cout << ")";
std::cout << " -> ";
std::cout << "(";
std::cout << vertices_.at(1).x;
std::cout << ", ";
std::cout << vertices_.at(1).y;
std::cout << ", ";
std::cout << vertices_.at(1).z;
std::cout << ")";
std::cout << std::endl;
}