-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDamonsDirection.h
204 lines (166 loc) · 5.04 KB
/
DamonsDirection.h
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#ifndef _DAMONS_DIRECTION_H_
#define _DAMONS_DIRECTION_H_
#include "DamonsObject.h"
#include "DamonsPoint.h"
#include "DamonsLine.h"
#include "DamonsRay.h"
namespace DGraphic {
/// class DDirection
/// @breif direction with 3 normalized elements with type T
/// DDirection stores <b>3</b> elements of data of type T
/// @tparam T type of data.
template<class T = double>
class DDirection:public DObject
{
public:
/// @brief Create an uninitialized DDirection.
DDirection() {
}
/// @brief create a direction with a DLine
/// @param l DLine
DDirection(DLine<T> &l) {
DVector<T, 3> d = l.to_vector();
dir_ = DPoint<T>(d.Normalized());
}
/// @brief create a direction with a Ray
/// @param l DRay
DDirection(DRay<T> &l) {
DDirection<T> d = l.Direction();
dir_.x() = d.x();
dir_.y() = d.y();
dir_.z() = d.z();
}
/// @brief create a direction with another direction
/// @param l direction
DDirection(DDirection<T> &l) {
dir_ = l.dir_;
}
/// @brief create a direction from two point
/// @param p1 start point of direction
/// @param p2 end point of direction
DDirection(DPoint<T> &p1, DPoint<T> &p2) {
dir_ = p2 - p1;
dir_.Normalize();
}
/// @brief create a direction from a vector
/// @param v vector need to create direction
DDirection(DVector<T,3> &v) {
DVector<T, 3> d = v.Normalized();
dir_ = DPoint<T>(d);
}
/// @brief Create a direction from three values.
///
/// @param s1 Scalar value for the first element of the direction.
/// @param s2 Scalar value for the second element of the direction.
/// @param s3 Scalar value for the third element of the direction.
inline DDirection(const T& s1, const T& s2, const T& s3) {
dir_ = DPoint<T>(s1,s2,s3);
dir_.Normalize();
}
/// @brief Create a direction from three diffent type values.
///
/// @note This method convert T1,T2,T3 to Type T,using static_cast
///
/// @param s1 of Type T1 Scalar value for the first element of the point.
/// @param s2 of Type T2 Scalar value for the second element of the point.
/// @param s3 of Type T3 Scalar value for the third element of the point.
template<typename T1, typename T2, typename T3>
inline DDirection(const T1& s1, const T2& s2, const T3& s3){
dir_ = DPoint<T>(s1, s2, s3);
dir_.Normalize();
}
~DDirection() {
}
public:
/// @brief get the first value of direction.
///
/// @return A reference to the first data that can be modified by the caller.
inline T& x() {
return dir_.x();
}
/// @brief get the second value of direction.
///
/// @return A reference to the second data that can be modified by the caller..
inline T& y() {
return dir_.y();
}
/// @brief get the third value of direction.
///
/// @return A reference to the third data that can be modified by the caller.
inline T& z() {
return dir_.z();
}
/// @brief get the first value of direction.
///
/// @return the first value of direction.
inline const T& x() const {
return dir_.x();
}
/// @brief get the second value of direction.
///
/// @return the second value of direction.
inline const T& y() const {
return dir_.y();
}
/// @brief get the third value of direction.
///
/// @return the third value of direction.
inline const T& z() const {
return dir_.z();
}
///@breif compare if two direction is equal
/// direction is equal if their elements is equal
///
///@param the direction need to compare with
///@return true if they are equal otherwise false
inline bool operator ==(const DDirection<T> & l) const {
return (l.dir_ == dir_);
}
///@breif compare if two direction is not equal
/// direction is equal if their elements is equal
///
///@param the direction need to compare with
///@return true if they are not equal otherwise false
inline bool operator !=(const DDirection<T> & l) const {
return !(*this == l);
}
/// @brief Access values of a direction.
///
/// @param i Index of the element to access.
/// @return the accessed data
inline const T& operator[](const int i) const{
assert(i < 3);
return dir_[i];
}
/// @brief Negate all elements of the Direction.
///
/// @return A new Direction containing the result.
inline DDirection<T> operator-() const{
return DDirection<T>(-dir_[0], -dir_[1], -dir_[2]);
}
/// @brief convert the direction to vector.
///
/// @return the vector equal with direction.
inline DVector<T, 3> to_vector() const {
return DVector<T, 3>(dir_[0], dir_[1], dir_[2]);
}
/// @brief get string of direction data seperate by space.
/// direction data must be basic type like :float int double
///
/// @return string of direction data.
inline std::string ToString() const {
return dir_.ToString();
}
/// @brief get wstring of direction data seperate by space.
/// direction data must be basic type like :float int double
///
/// @return wstring of direction data.
inline std::wstring ToWString() const {
return dir_.ToWString();
}
public:
///direction data
DPoint<T> dir_;
};
};
#endif