Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DPoint.inl
1#pragma once
2
3BEGIN_MOOTOOLS_NAMESPACE
4
5template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint()
6{
7 x = (TYPE)0.0f;
8 y = (TYPE)0.0f;
9 z = (TYPE)0.0f;
10}
11
12template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(TYPE *val)
13{
14 x = val[0];
15 y = val[1];
16 z = val[2];
17}
18
19template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(int refx, int refy, int refz)
20{
21 x = (TYPE)refx;
22 y = (TYPE)refy;
23 z = (TYPE)refz;
24}
25
26template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(float refx, float refy, float refz)
27{
28 x = (TYPE)refx;
29 y = (TYPE)refy;
30 z = (TYPE)refz;
31}
32
33template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(double refx, double refy, double refz)
34{
35 x = (TYPE)refx;
36 y = (TYPE)refy;
37 z = (TYPE)refz;
38}
39
40template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(const C3DTPoint<TYPE>& pt)
41{
42 x = pt.x;
43 y = pt.y;
44 z = pt.z;
45}
46
47template <class TYPE> inline C3DTPoint<TYPE>::C3DTPoint(const C3DTPoint<TYPE>& pt, const C3DTVector<TYPE>& vect, bool add)
48{
49 if (add)
50 {
51 x = pt.x + vect.x;
52 y = pt.y + vect.y;
53 z = pt.z + vect.z;
54 }
55 else
56 {
57 x = pt.x - vect.x;
58 y = pt.y - vect.y;
59 z = pt.z - vect.z;
60 }
61}
62
63template <class TYPE> inline TYPE& C3DTPoint<TYPE>::operator[](int i)
64{
65 return (&x)[i];
66}
67
68template <class TYPE> inline const TYPE& C3DTPoint<TYPE>::operator[](int i) const
69{
70 return (&x)[i];
71}
72
73template <class TYPE> inline unsigned int C3DTPoint<TYPE>::SizeOf() const
74{
75 return static_cast<unsigned int>(sizeof(TYPE)*3);
76}
77
78template <class TYPE> inline TYPE* C3DTPoint<TYPE>::ValPtr()
79{
80 return(&x);
81}
82
83template <class TYPE> inline const TYPE* C3DTPoint<TYPE>::ValPtr() const
84{
85 return(&x);
86}
87
88template <class TYPE> inline void C3DTPoint<TYPE>::SetValues(const TYPE *val)
89{
90 x = val[0];
91 y = val[1];
92 z = val[2];
93}
94
97 CPt::operator=(src);
98 x = src.x;
99 y = src.y;
100 z = src.z;
101 return *this;
102}
103
105{
106 x = vect.x;
107 y = vect.y;
108 z = vect.z;
109 return *this;
110}
111
112// for a point t = 1.0
113// tV1 * V2
114template <class TYPE> inline double C3DTPoint<TYPE>::operator *(const C4DTVector<TYPE>& vect) const
115{
116 return (double(x)*vect.dir.x + double(y)*vect.dir.y + double(z)*vect.dir.z + double(vect.t));
117}
118
119template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator *(double value) const
120{
121 return C3DTPoint<TYPE>(x*value, y*value, z*value);
122}
123
124template <class TYPE> inline C3DTPoint<TYPE> operator *(double value, const C3DTPoint<TYPE>& pt)
125{
126 return C3DTPoint<TYPE>(pt.x*value, pt.y*value, pt.z*value);
127}
128
129template <class TYPE> inline double C3DTPoint<TYPE>::Mult(const double& xx, const double& yy, const double& zz) const
130{
131 return (x*xx + y*yy + z*zz);
132}
133
134template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator -(const C3DTVector<TYPE>& vect1) const
135{
136 return C3DTPoint(x - vect1.x, y - vect1.y, z - vect1.z);
137}
138
139template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator +(const C3DTVector<TYPE>& vect1) const
140{
141 return C3DTPoint(x + vect1.x, y + vect1.y, z + vect1.z);
142}
143
144template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator -=(const C3DTPoint<TYPE>& pt)
145{
146 x -= pt.x;
147 y -= pt.y;
148 z -= pt.z;
149
150 return *this;
151}
152
153template <class TYPE> inline void C3DTPoint<TYPE>::SubstractTo(const C3DTPoint<TYPE>& pt)
154{
155 x = pt.x - x;
156 y = pt.y - y;
157 z = pt.z - z;
158}
159
160template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator +=(const C3DTPoint<TYPE>& pt)
161{
162 x += pt.x;
163 y += pt.y;
164 z += pt.z;
165
166 return *this;
167}
168
169template <class TYPE> inline void C3DTPoint<TYPE>::Offset(TYPE value)
170{
171 x += value;
172 y += value;
173 z += value;
174}
175
176
177template <class TYPE> inline bool C3DTPoint<TYPE>::IsAnormal() const
178{
179 // Do not check fpclassify, and subnormal values
180 if (IsInfinite() || const_cast<C3DTPoint<TYPE> *>(this)->IsNan())
181 return true;
182
183 return false;
184}
185
186template <class TYPE> inline bool C3DTPoint<TYPE>::IsInfinite() const
187{
188 if (_finite(x) && _finite(y) && _finite(z))
189 return false;
190
191 return true;
192}
193
194template <class TYPE> inline bool C3DTPoint<TYPE>::IsNan(bool resetToZero)
195{
196 if (resetToZero)
197 {
198 bool nan = false;
199 if (_isnan(x))
200 {
201 x = 0.0f;
202 nan = true;
203 }
204
205 if (_isnan(y))
206 {
207 y = 0.0f;
208 nan = true;
209 }
210
211 if (_isnan(z))
212 {
213 z = 0.0f;
214 nan = true;
215 }
216
217 return nan;
218 }
219
220 if (_isnan(x) || _isnan(y) || _isnan(z))
221 return true;
222
223 return false;
224}
225
226template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator -=(const C3DTVector<TYPE>& vect)
227{
228 x -= vect.x;
229 y -= vect.y;
230 z -= vect.z;
231
232 return *this;
233}
234
235template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator +=(const C3DTVector<TYPE>& vect)
236{
237 x += vect.x;
238 y += vect.y;
239 z += vect.z;
240
241 return *this;
242}
243
244template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator +(const C3DTPoint<TYPE>& pt1) const
245{
246 return C3DTPoint(x + pt1.x, y + pt1.y, z + pt1.z);
247}
248
249template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator -(const C3DTPoint<TYPE>& pt1) const
250{
251 return C3DTPoint(x - pt1.x, y - pt1.y, z - pt1.z);
252}
253
254template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator +(const C4DTVector<TYPE>& pt1) const
255{
256 return C3DTPoint(x + pt1.dir.x, y + pt1.dir.y, z + pt1.dir.z);
257}
258
259template <class TYPE> inline C3DTPoint<TYPE> C3DTPoint<TYPE>::operator /(double weight) const
260{
261 return C3DTPoint(x/weight, y/weight, z/weight);
262}
263
264template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator /=(double weight)
265{
266 x = (TYPE)(x/weight);
267 y = (TYPE)(y/weight);
268 z = (TYPE)(z/weight);
269
270 return *this;
271}
272
273template <class TYPE> inline C3DTPoint<TYPE>& C3DTPoint<TYPE>::operator *=(double weight)
274{
275 x = (TYPE)(x * weight);
276 y = (TYPE)(y * weight);
277 z = (TYPE)(z * weight);
278
279 return *this;
280}
281
282template <class TYPE> bool C3DTPoint<TYPE>::operator==(const C3DTPoint<TYPE>& src) const
283{
284 if (x != src.x || y != src.y || z != src.z)
285 return false;
286
287 return true;
288}
289
290template <class TYPE> bool C3DTPoint<TYPE>::operator!=(const C3DTPoint<TYPE>& src) const
291{
292 if (x != src.x || y != src.y || z != src.z)
293 return true;
294
295 return false;
296}
297
298template <class TYPE> inline C3DPointI C3DTPoint<TYPE>::Floor() const
299{
300 return C3DPointI(floor(x), floor(y), floor(z));
301}
302
303template <class TYPE> inline C3DPointI C3DTPoint<TYPE>::Ceil() const
304{
305 return C3DPointI(ceil(x), ceil(y), ceil(z));
306}
307
308template <class TYPE> inline void GetNormal(const C3DTPoint<TYPE>& pt1, const C3DTPoint<TYPE>& pt2, const C3DTPoint<TYPE>& pt3, C3DTVector<TYPE>& normal)
309{
310 C3DTVector<TYPE> vector;
311
312 normal.InitFromPoints(pt1, pt2);
313 vector.InitFromPoints(pt1, pt3);
314 normal = (normal ^ vector);
315
316 if (normal.IsNull())
317 {
318 normal.x = 1.0f;
319 normal.y = 0.0f;
320 normal.z = 0.0f;
321 }
322 else
323 normal.Normalize();
324}
325
326template<class TYPE> inline double Area(const C3DTPoint<TYPE>& v0, const C3DTPoint<TYPE>& v1, const C3DTPoint<TYPE>& v2)
327{
328 return Area(C3DTVector<TYPE>(v0, v1), C3DTVector<TYPE>(v0, v2));
329}
330
331template <class TYPE> inline void Min(C3DTPoint<TYPE>& min, const C3DTPoint<TYPE>& point)
332{
333 if (min.x > point.x)
334 min.x = point.x;
335 if (min.y > point.y)
336 min.y = point.y;
337 if (min.z > point.z)
338 min.z = point.z;
339}
340
341template <class TYPE> inline void Max(C3DTPoint<TYPE>& max, const C3DTPoint<TYPE>& point)
342{
343 if (max.x < point.x)
344 max.x = point.x;
345 if (max.y < point.y)
346 max.y = point.y;
347 if (max.z < point.z)
348 max.z = point.z;
349}
350
351END_MOOTOOLS_NAMESPACE
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
void SetValues(const TYPE *values3t)
Set point from 3 TYPE.
Definition 3DPoint.inl:88
bool IsAnormal() const
either infinite or nan. Zero and denormalized value are allowed.
Definition 3DPoint.inl:177
void SubstractTo(const C3DTPoint &pt)
return this = pt-this, instead this = this-pt. This can be used for fast computation (using the stand...
Definition 3DPoint.inl:153
bool IsInfinite() const
Check if one of the coordinate has inf value.
Definition 3DPoint.inl:186
void Offset(TYPE value)
Add value to x, y, z.
Definition 3DPoint.inl:169
bool IsNan(bool resetToZero=false)
Check if one of the coordinate has nan value. resetToZero nan = true, reset coordinates to zero if an...
Definition 3DPoint.inl:194