-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriple.h
90 lines (74 loc) · 2.05 KB
/
Triple.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
#ifndef INCLUDED_MATH_TRIPLE
#define INCLUDED_MATH_TRIPLE
#include "Utils.h"
#include <ostream>
namespace Dubious {
namespace Math {
/// @brief Three floats
///
/// There are a fair number of Vector and 3D point types in a physics
/// engine. They all need a basic, underlying type of 3 floats. This
/// triple is meant to handle the really basic stuff, like addition,
/// copying, and equality. I'm making the data public because it's
/// not a real class, but a collection of helper functions wrapper
/// around three floats
struct Triple {
/// @brief Default Constructor
///
/// Initializes a Triple to 0,0,0
Triple() = default;
/// @brief Constructor
///
/// Creates a triple with the passed in values
/// @param x - [in] X component
/// @param y - [in] Y component
/// @param z - [in] Z component
Triple(float x, float y, float z) : m_x(x), m_y(y), m_z(z) {}
Triple operator-() const { return Triple(-m_x, -m_y, -m_z); }
Triple& operator+=(const Triple& b)
{
m_x += b.m_x;
m_y += b.m_y;
m_z += b.m_z;
return *this;
}
Triple& operator-=(const Triple& b)
{
m_x -= b.m_x;
m_y -= b.m_y;
m_z -= b.m_z;
return *this;
}
float m_x = 0;
float m_y = 0;
float m_z = 0;
};
inline bool
operator==(const Triple& a, const Triple& b)
{
return equals(a.m_x, b.m_x) && equals(a.m_y, b.m_y) && equals(a.m_z, b.m_z);
}
inline bool
operator!=(const Triple& a, const Triple& b)
{
return !(a == b);
}
inline Triple
operator+(const Triple& a, const Triple& b)
{
return Triple(a.m_x + b.m_x, a.m_y + b.m_y, a.m_z + b.m_z);
}
inline Triple
operator-(const Triple& a, const Triple& b)
{
return Triple(a.m_x - b.m_x, a.m_y - b.m_y, a.m_z - b.m_z);
}
inline std::ostream&
operator<<(std::ostream& o, const Triple& a)
{
o << "(" << a.m_x << ", " << a.m_y << ", " << a.m_z << ")";
return o;
}
} // namespace Math
} // namespace Dubious
#endif