-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathTSVector3D.h
823 lines (637 loc) · 20.2 KB
/
TSVector3D.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
//
// This file is part of the Terathon Math Library, by Eric Lengyel.
// Copyright 1999-2024, Terathon Software LLC
//
// This software is distributed under the MIT License.
// Separate proprietary licenses are available from Terathon Software.
//
#ifndef TSVector3D_h
#define TSVector3D_h
#include "TSVector2D.h"
#define TERATHON_VECTOR3D 1
#define TERATHON_POINT3D 1
namespace Terathon
{
class Vector3D;
class Bivector3D;
class Origin3D;
struct ConstVector3D;
// ==============================================
// Vector3D
// ==============================================
struct TypeVector3D
{
typedef float component_type;
typedef Vector2D vector2D_type;
typedef Vector3D vector3D_type;
};
/// @brief Encapsulates a 3D vector.
///
/// The \c Vector3D class is used to store a three-dimensional direction vector having floating-point
/// components <i>x</i>, <i>y</i>, and <i>z</i>. A direction vector stored in this class is assumed to
/// have a <i>w</i> coordinate of 0 whenever it needs to be converted to a four-dimensional representation.
/// Three-dimensional points (for which the <i>w</i> coordinate is 1) should be stored using the \c Point3D class.
///
/// @sa Point3D
/// @sa Vector2D
/// @sa Vector4D
class Vector3D : public Vec3D<TypeVector3D>
{
public:
TERATHON_API static const ConstVector3D zero;
TERATHON_API static const ConstVector3D x_unit;
TERATHON_API static const ConstVector3D y_unit;
TERATHON_API static const ConstVector3D z_unit;
TERATHON_API static const ConstVector3D minus_x_unit;
TERATHON_API static const ConstVector3D minus_y_unit;
TERATHON_API static const ConstVector3D minus_z_unit;
/// @brief Default constructor that leaves the components uninitialized.
inline Vector3D() = default;
/// @brief Constructor that sets components explicitly.
/// @param a,b,c The components of the vector.
Vector3D(float a, float b, float c) : Vec3D<TypeVector3D>(a, b, c) {}
template <typename type>
explicit Vector3D(const Vec3D<type>& v) : Vec3D<TypeVector3D>(float(v.x), float(v.y), float(v.z)) {}
Vector3D(const Vector2D& v)
{
xy = v.xy;
z = 0.0F;
}
Vector3D(const Vector2D& v, float c)
{
xy = v.xy;
z = c;
}
/// @brief Sets all three components of a 3D vector.
/// @param a,b,c The new components of the vector.
Vector3D& Set(float a, float b, float c)
{
xyz.Set(a, b, c);
return (*this);
}
void Set(float a, float b, float c) volatile
{
xyz.Set(a, b, c);
}
Vector3D& Set(const Vector2D& v, float c)
{
xyz.Set(v.x, v.y, c);
return (*this);
}
void Set(const Vector2D& v, float c) volatile
{
xyz.Set(v.x, v.y, c);
}
Point2D& GetPoint2D(void)
{
Vector2D& v = xy;
return (static_cast<Point2D&>(v));
}
const Point2D& GetPoint2D(void) const
{
const Vector2D& v = xy;
return (static_cast<const Point2D&>(v));
}
Vector3D& operator =(const Vector3D& v)
{
xyz = v.xyz;
return (*this);
}
void operator =(const Vector3D& v) volatile
{
xyz = v.xyz;
}
Vector3D& operator =(const Vector2D& v)
{
xy = v.xy;
z = 0.0F;
return (*this);
}
void operator =(const Vector2D& v) volatile
{
xy = v.xy;
z = 0.0F;
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
Vector3D& operator =(const Subvec3D<type_struct, false, count, index_x, index_y, index_z>& v)
{
xyz = v;
return (*this);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
void operator =(const Subvec3D<type_struct, false, count, index_x, index_y, index_z>& v) volatile
{
xyz = v;
}
template <typename type>
Vector3D& operator =(const Vec3D<type>& v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
return (*this);
}
Vector3D& operator +=(const Vector3D& v)
{
xyz += v.xyz;
return (*this);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
Vector3D& operator +=(const Subvec3D<type_struct, false, count, index_x, index_y, index_z>& v)
{
xyz += v;
return (*this);
}
Vector3D& operator -=(const Vector3D& v)
{
xyz -= v.xyz;
return (*this);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
Vector3D& operator -=(const Subvec3D<type_struct, false, count, index_x, index_y, index_z>& v)
{
xyz -= v;
return (*this);
}
Vector3D& operator *=(const Vector3D& v)
{
xyz *= v.xyz;
return (*this);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
Vector3D& operator *=(const Subvec3D<type_struct, false, count, index_x, index_y, index_z>& v)
{
xyz *= v;
return (*this);
}
Vector3D& operator *=(float n)
{
xyz *= n;
return (*this);
}
Vector3D& operator /=(float n)
{
xyz /= n;
return (*this);
}
Vector3D& Normalize(void)
{
return (static_cast<Vector3D&>(xyz.Normalize()));
}
Vector3D& Unitize(void)
{
xy /= z;
z = 1.0F;
return (*this);
}
/// @brief Rotates the vector about the <i>x</i> axis through the
/// angle, in radians, given by the \c angle parameter.
TERATHON_API Vector3D& RotateAboutX(float angle);
/// @brief Rotates the vector about the <i>y</i> axis through the
/// angle, in radians, given by the \c angle parameter.
TERATHON_API Vector3D& RotateAboutY(float angle);
/// @brief Rotates the vector about the <i>z</i> axis through the
/// angle, in radians, given by the \c angle parameter.
TERATHON_API Vector3D& RotateAboutZ(float angle);
/// @brief Rotates the vector about the axis given by the \c axis parameter
/// through the angle, in radians, given by the \c angle parameter.
TERATHON_API Vector3D& RotateAboutAxis(float angle, const Bivector3D& axis);
};
/// @brief Returns the negation of the 3D vector \c v.
/// @related Vector3D
inline Vector3D operator -(const Vector3D& v)
{
return (Vector3D(-v.x, -v.y, -v.z));
}
inline Vector3D operator +(const Vector3D& a, const Vector3D& b)
{
return (Vector3D(a.x + b.x, a.y + b.y, a.z + b.z));
}
inline Vector3D operator +(const Vector3D& a, const Vector2D& b)
{
return (Vector3D(a.x + b.x, a.y + b.y, a.z));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Vector3D operator +(const Vector3D& a, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& b)
{
return (Vector3D(a.x + b.data[index_x], a.y + b.data[index_y], a.z + b.data[index_z]));
}
inline Vector3D operator -(const Vector3D& a, const Vector3D& b)
{
return (Vector3D(a.x - b.x, a.y - b.y, a.z - b.z));
}
inline Vector3D operator -(const Vector3D& a, const Vector2D& b)
{
return (Vector3D(a.x - b.x, a.y - b.y, a.z));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Vector3D operator -(const Vector3D& a, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& b)
{
return (Vector3D(a.x - b.data[index_x], a.y - b.data[index_y], a.z - b.data[index_z]));
}
/// @brief Returns the product of the 3D vector \c v and the scalar \c n.
/// @related Vector3D
inline Vector3D operator *(const Vector3D& v, float n)
{
return (Vector3D(v.x * n, v.y * n, v.z * n));
}
/// @brief Returns the product of the 3D vector \c v and the scalar \c n.
/// @related Vector3D
inline Vector3D operator *(float n, const Vector3D& v)
{
return (Vector3D(n * v.x, n * v.y, n * v.z));
}
/// @brief Returns the product of the 3D vector \c v and the inverse of the scalar \c n.
/// @related Vector3D
inline Vector3D operator /(const Vector3D& v, float n)
{
n = 1.0F / n;
return (Vector3D(v.x * n, v.y * n, v.z * n));
}
/// @brief Returns the componentwise product of the 3D vectors \c a and \c b.
/// @related Vector3D
inline Vector3D operator *(const Vector3D& a, const Vector3D& b)
{
return (Vector3D(a.x * b.x, a.y * b.y, a.z * b.z));
}
template <typename type_struct, int count, int index_x, int index_y, int index_z>
inline float operator ^(const Subvec3D<type_struct, true, count, index_x, index_y, index_z>& a, const Vector3D& b)
{
return (a.data[index_x] * b.x + a.data[index_y] * b.y + a.data[index_z] * b.z);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z, int index_w>
inline float operator ^(const Subvec4D<type_struct, true, count, index_x, index_y, index_z, index_w>& a, const Vector3D& b)
{
return (a.data[index_x] * b.x + a.data[index_y] * b.y + a.data[index_z] * b.z);
}
// ==============================================
// Point3D
// ==============================================
/// @brief Encapsulates a 3D point.
///
/// The \c Point3D class is used to store a three-dimensional point having floating-point
/// coordinates <i>x</i>, <i>y</i>, and <i>z</i>. The difference between a point and a vector
/// is that a point is assumed to have a <i>w</i> coordinate of 1 whenever it needs to be
/// converted to a four-dimensional representation, whereas a vector is assumed to have a
/// <i>w</i> coordinate of 0. Such a conversion occurs when a vector or point is assigned
/// to a \c Vector4D object or is multiplied by a \c Transform3D object.
///
/// @sa Vector2D
/// @sa Vector3D
/// @sa Vector4D
class Point3D : public Vector3D
{
public:
TERATHON_API static const Origin3D origin;
/// @brief Default constructor that leaves the components uninitialized.
inline Point3D() = default;
/// @brief Constructor that sets components explicitly.
/// @param a,b,c The components of the point.
Point3D(float a, float b, float c) : Vector3D(a, b, c) {}
Point3D(const Vector2D& v) : Vector3D(v) {}
Point3D(const Vector2D& v, float c) : Vector3D(v, c) {}
explicit Point3D(const Vector3D& p) : Vector3D(p) {}
Point3D& operator =(const Vector3D& v)
{
xyz = v.xyz;
return (*this);
}
void operator =(const Vector3D& v) volatile
{
xyz = v.xyz;
}
Point3D& operator =(const Vector2D& v)
{
xy = v.xy;
z = 0.0F;
return (*this);
}
void operator =(const Vector2D& v) volatile
{
xy = v.xy;
z = 0.0F;
}
template <typename type>
Point3D& operator =(const Vec3D<type>& v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
return (*this);
}
Point3D& operator +=(const Vector3D& v)
{
xyz += v.xyz;
return (*this);
}
Point3D& operator -=(const Vector3D& v)
{
xyz -= v.xyz;
return (*this);
}
Point3D& operator *=(const Vector3D& v)
{
xyz *= v.xyz;
return (*this);
}
Point3D& operator *=(float n)
{
xyz *= n;
return (*this);
}
Point3D& operator /=(float n)
{
xyz /= n;
return (*this);
}
};
/// @brief Returns the negation of the 3D point \c p.
/// @related Point3D
inline Point3D operator -(const Point3D& p)
{
return (Point3D(-p.x, -p.y, -p.z));
}
inline Point3D operator +(const Point3D& a, const Point3D& b)
{
return (Point3D(a.x + b.x, a.y + b.y, a.z + b.z));
}
inline Point3D operator +(const Point3D& p, const Vector3D& v)
{
return (Point3D(p.x + v.x, p.y + v.y, p.z + v.z));
}
inline Point3D operator +(const Vector3D& v, const Point3D& p)
{
return (Point3D(v.x + p.x, v.y + p.y, v.z + p.z));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Point3D operator +(const Point3D& p, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& v)
{
return (Point3D(p.x + v.data[index_x], p.y + v.data[index_y], p.z + v.data[index_z]));
}
inline Vector3D operator -(const Point3D& a, const Point3D& b)
{
return (Vector3D(a.x - b.x, a.y - b.y, a.z - b.z));
}
inline Point3D operator -(const Point3D& p, const Vector3D& v)
{
return (Point3D(p.x - v.x, p.y - v.y, p.z - v.z));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Point3D operator -(const Point3D& p, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& v)
{
return (Point3D(p.x - v.data[index_x], p.y - v.data[index_y], p.z - v.data[index_z]));
}
inline Point3D operator -(const Vector3D& v, const Point3D& p)
{
return (Point3D(v.x - p.x, v.y - p.y, v.z - p.z));
}
/// @brief Returns the product of the 3D point \c p and the scalar \c n.
/// @related Point3D
inline Point3D operator *(const Point3D& p, float n)
{
return (Point3D(p.x * n, p.y * n, p.z * n));
}
/// @brief Returns the product of the 3D point \c p and the scalar \c n.
/// @related Point3D
inline Point3D operator *(float n, const Point3D& p)
{
return (Point3D(n * p.x, n * p.y, n * p.z));
}
/// @brief Returns the product of the 3D point \c p and the inverse of the scalar \c n.
/// @related Point3D
inline Point3D operator /(const Point3D& p, float n)
{
n = 1.0F / n;
return (Point3D(p.x * n, p.y * n, p.z * n));
}
/// @brief Returns the componentwise product of the 3D points \c a and \c b.
/// @related Point3D
inline Point3D operator *(const Point3D& a, const Point3D& b)
{
return (Point3D(a.x * b.x, a.y * b.y, a.z * b.z));
}
inline Point3D operator *(const Point3D& p, const Vector3D& v)
{
return (Point3D(p.x * v.x, p.y * v.y, p.z * v.z));
}
inline Point3D operator *(const Vector3D& v, const Point3D& p)
{
return (Point3D(v.x * p.x, v.y * p.y, v.z * p.z));
}
// ==============================================
// Magnitude
// ==============================================
/// @brief Returns the magnitude of the 3D vector \c v.
/// @relatedalso Vector3D
inline float Magnitude(const Vector3D& v)
{
return (Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));
}
/// @brief Returns the inverse magnitude of the 3D vector \c v.
/// @relatedalso Vector3D
inline float InverseMag(const Vector3D& v)
{
return (InverseSqrt(v.x * v.x + v.y * v.y + v.z * v.z));
}
/// @brief Returns the squared magnitude of the 3D vector \c v.
/// @relatedalso Vector3D
inline float SquaredMag(const Vector3D& v)
{
return (v.x * v.x + v.y * v.y + v.z * v.z);
}
/// @brief Calculates the normalized version of the 3D vector \c v.
///
/// Multiplies the 3D vector \c v by the inverse of its magnitude. The return value is a vector
/// having unit length that points in the same direction as \c v. If the magnitude of \c v is zero,
/// then the result is undefined.
///
/// @relatedalso Vector3D
inline Vector3D Normalize(const Vector3D& v)
{
return (v * InverseMag(v));
}
// ==============================================
// Dot
// ==============================================
/// @brief Calculates the dot product of the 3D vectors \c a and \c b.
/// @relatedalso Vector3D
inline float Dot(const Vector3D& a, const Vector3D& b)
{
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
inline float Dot(const Point3D& a, const Point3D& b)
{
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
inline float Dot(const Point3D& p, const Vector3D& v)
{
return (p.x * v.x + p.y * v.y + p.z * v.z);
}
inline float Dot(const Vector3D& v, const Point3D& p)
{
return (v.x * p.x + v.y * p.y + v.z * p.z);
}
template <typename type_struct, int count, int index_x, int index_y, int index_z, int index_w>
inline float operator ^(const Subvec4D<type_struct, true, count, index_x, index_y, index_z, index_w>& a, const Point3D& b)
{
return (a.data[index_x] * b.x + a.data[index_y] * b.y + a.data[index_z] * b.z + a.data[index_w]);
}
// ==============================================
// Cross
// ==============================================
/// @brief Calculates the cross product of the 3D vectors \c a and \c b.
/// @relatedalso Vector3D
inline Vector3D Cross(const Vector3D& a, const Vector3D& b)
{
return (Vector3D(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x));
}
// ==============================================
// Projection
// ==============================================
/// @brief Returns (<b>a</b> ⋅ <b>b</b>)<b>b</b>, which is the projection of \c a onto \c b under the assumption that the magnitude of \c b is one.
/// @relatedalso Vector3D
inline Vector3D Project(const Vector3D& a, const Vector3D& b)
{
return (b * Dot(a, b));
}
/// @brief Returns <b>a</b> − (<b>a</b> ⋅ <b>b</b>)<b>b</b>, which is the rejection of \c a from \c b under the assumption that the magnitude of \c b is one.
/// @relatedalso Vector3D
inline Vector3D Reject(const Vector3D& a, const Vector3D& b)
{
return (a - b * Dot(a, b));
}
// ==============================================
// Floor / ceiling
// ==============================================
/// @brief Returns the componentwise floor of the 3D vector \c v.
/// @related Vector3D
inline Vector3D Floor(const Vector3D& v)
{
return (Vector3D(Floor(v.x), Floor(v.y), Floor(v.z)));
}
/// @brief Returns the componentwise ceiling of the 3D vector \c v.
/// @related Vector3D
inline Vector3D Ceil(const Vector3D& v)
{
return (Vector3D(Ceil(v.x), Ceil(v.y), Ceil(v.z)));
}
// ==============================================
// POD Structures
// ==============================================
#ifndef TERATHON_NO_SIMD
class alignas(16) SimdVector3D : public Vector3D
{
public:
operator vec_float&(void)
{
return (reinterpret_cast<vec_float&>(x));
}
operator const vec_float&(void) const
{
return (reinterpret_cast<const vec_float&>(x));
}
SimdVector3D& operator =(vec_float v)
{
reinterpret_cast<vec_float&>(x) = v;
return (*this);
}
using Vector3D::operator =;
};
class alignas(16) SimdPoint3D : public Point3D
{
public:
operator vec_float&(void)
{
return (reinterpret_cast<vec_float&>(x));
}
operator const vec_float&(void) const
{
return (reinterpret_cast<const vec_float&>(x));
}
SimdPoint3D& operator =(vec_float v)
{
reinterpret_cast<vec_float&>(x) = v;
return (*this);
}
using Point3D::operator =;
};
#else
typedef Vector3D SimdVector3D;
typedef Point3D SimdPoint3D;
#endif
struct ConstVector3D
{
float x, y, z;
operator const Vector3D&(void) const
{
return (reinterpret_cast<const Vector3D&>(*this));
}
const Vector3D *operator &(void) const
{
return (reinterpret_cast<const Vector3D *>(this));
}
const Vector3D *operator ->(void) const
{
return (reinterpret_cast<const Vector3D *>(this));
}
};
struct ConstPoint3D
{
float x, y, z;
operator const Point3D&(void) const
{
return (reinterpret_cast<const Point3D&>(*this));
}
const Point3D *operator &(void) const
{
return (reinterpret_cast<const Point3D *>(this));
}
const Point3D *operator ->(void) const
{
return (reinterpret_cast<const Point3D *>(this));
}
};
class Origin3D
{
private:
TERATHON_API static const ConstPoint3D origin;
public:
operator const Point3D&(void) const
{
return (origin);
}
const Point3D *operator &(void) const
{
return (&origin);
}
};
inline const Point3D& operator +(const Origin3D&, const Vector3D& v)
{
return (static_cast<const Point3D&>(v));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Point3D operator +(const Origin3D&, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& v)
{
return (Point3D(v.data[index_x], v.data[index_y], v.data[index_z]));
}
template <typename type_struct, bool anti, int count>
inline const Point3D& operator +(const Origin3D&, const Subvec3D<type_struct, anti, count, 0, 1, 2>& v)
{
return (reinterpret_cast<const Point3D&>(v.data[0]));
}
template <typename type_struct, bool anti, int count>
inline const Point3D& operator +(const Origin3D&, const Subvec3D<type_struct, anti, count, 1, 2, 3>& v)
{
return (reinterpret_cast<const Point3D&>(v.data[1]));
}
inline Point3D operator -(const Origin3D&, const Vector3D& v)
{
return (Point3D(-v.x, -v.y, -v.z));
}
template <typename type_struct, bool anti, int count, int index_x, int index_y, int index_z>
inline Point3D operator -(const Origin3D&, const Subvec3D<type_struct, anti, count, index_x, index_y, index_z>& v)
{
return (Point3D(-v.data[index_x], -v.data[index_y], -v.data[index_z]));
}
}
#endif