-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edge3D.cpp
138 lines (81 loc) · 2.64 KB
/
Edge3D.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Edge3D Class
// Damien MATTEI
#include "Edge3D.hpp"
// implementations
template <class T> Edge3D<T>::Edge3D() : a(), b() {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# Edge3D constructor #" << endl;
#endif
}
// create edge AB from point A and B
template <class T> Edge3D<T>::Edge3D(Point3D<T> & a,Point3D<T> & b) : a(&a), b(&b) {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# constructor "<< this->display() << " #" << endl;
#endif
}
// create edge AB from point A and B
// template <class T> Edge3D<T>::Edge3D(Point3D<T> & ref_a,Point3D<T> & ref_b) : a(ref_a), b(ref_b) {
// #ifdef DISPLAY_CONSTRUCTOR
// cout << "# Edge3D constructor by references#" << endl;
// #endif
// }
template <class T> Edge3D<T>::~Edge3D() {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# destructor " << this->display() << endl;
#endif
}
template <class T> string Edge3D<T>::display(void) {
std::stringstream stream;
Point3D<T> & ptEdgeA = *(this->a);
Point3D<T> & ptEdgeB = *(this->b);
stream << "Edge3D @" << " 0x" << std::hex << (long)this << " "
// << " [" << this->a->display() << " <--> " << this->b->display() << "]";
// << " [" << this->a << " <--> " << this->b << "]";
<< " [" << ptEdgeA << " <--> " << ptEdgeB << "]";
return stream.str();
}
template <class T> ostream& operator<< (ostream &out, Edge3D<T> &e)
{
Point3D<T> & ptEdgeA = *(e.a);
Point3D<T> & ptEdgeB = *(e.b);
//out << "[" << *(e.a) << "] <--> [" << *(e.b) << "]";
out << "[" << ptEdgeA << "] <--> [" << ptEdgeB << "]";
return out;
}
// copy constructor
// logically should not be used (Edge3D are unique)
template <class T> Edge3D<T>::Edge3D(const Edge3D<T> &oneEdge3D) {
a=oneEdge3D.a;
b=oneEdge3D.b;
#ifdef DISPLAY_CONSTRUCTOR
cout << "# Edge3D copy constructor #" << endl;
#endif
}
// assignation operator
template <class T> Edge3D<T> & Edge3D<T>::operator=(const Edge3D<T> &oneEdge3D)
{
#ifdef DISPLAY_ASSIGN
cout << "# Edge3D assignation operator #" << endl;
#endif
if (this != &oneEdge3D)
{
a=oneEdge3D.a;
b=oneEdge3D.b;
// delete [] tableau;
}
return *this;
}
// equality operator
template <class T> bool Edge3D<T>::operator== (const Edge3D<T> &e) {
Point3D<T> & ptEdgeA = *(e.a);
Point3D<T> & ptEdgeB = *(e.b);
Point3D<T> & ptThisEdgeA = *a;
Point3D<T> & ptThisEdgeB = *b;
return ((ptThisEdgeA==ptEdgeA) && (ptThisEdgeB==ptEdgeB))
|| ((ptThisEdgeA==ptEdgeB) && (ptThisEdgeB==ptEdgeA));
}
// template<class T> T Edge3D<T>::norm() {
// return ( sqrt(x * x + y * y + z * z) );
// }
template class Edge3D<float>;
template ostream& operator<< (ostream &out, Edge3D<float> &e);