OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
Point3D.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8namespace ot {
9
12 template <class T> class Point3D {
13 public:
18 Point3D(T _x, T _y, T _z);
19
22 Point3D(const Point3D<T> & _other);
23
24 Point3D<T> & operator = (const Point3D<T> & _other);
25 Point3D<T> operator + (const Point3D<T> & _other) const;
26 Point3D<T> operator - (const Point3D<T> & _other) const;
27 Point3D<T> operator * (const Point3D<T> & _other) const;
28 Point3D<T> operator / (const Point3D<T> & _other) const;
29 Point3D<T> & operator += (const Point3D<T> & _other);
30 Point3D<T> & operator -= (const Point3D<T> & _other);
31 Point3D<T> & operator *= (const Point3D<T> & _other);
32 Point3D<T> & operator /= (const Point3D<T> & _other);
33 bool operator == (const Point3D<T> & _other);
34 bool operator != (const Point3D<T> & _other);
35
37 inline T x(void) const { return m_x; }
38
40 inline T y(void) const { return m_y; }
41
43 inline T z(void) const { return m_z; }
44
47 void setX(T _x) { m_x = _x; }
48
51 void setY(T _y) { m_y = _y; }
52
55 void setZ(T _z) { m_z = _z; }
56
59 T addX(T _v);
60
63 T addY(T _v);
64
67 T addZ(T _z);
68
71 T subX(T _v);
72
75 T subY(T _v);
76
79 T subZ(T _v);
80
81 private:
82 // Block default constructor
83 Point3D() = delete;
84
85 T m_x;
86 T m_y;
87 T m_z;
88
89 }; // class Point3D
90
91 template <class T> Point3D<T>::Point3D(T _x, T _y, T _z) { m_x = _x; m_y = _y; m_z = _z; }
92
93 template <class T> Point3D<T>::Point3D(const Point3D<T> & _other) { m_x = _other.x(); m_y = _other.y(); m_z = _other.z(); }
94
95 template <class T> Point3D<T> & Point3D<T>::operator = (const Point3D<T> & _other) {
96 m_x = _other.x(); m_y = _other.y(); m_z = _other.z();
97 return *this;
98 }
99
100 template <class T> Point3D<T> Point3D<T>::operator + (const Point3D<T> & _other) const {
101 Point3D<T> ret(m_x + _other.m_x, m_y + _other.m_y, m_z + _other.m_z);
102 return ret;
103 }
104
105 template <class T> Point3D<T> Point3D<T>::operator - (const Point3D<T> & _other) const {
106 Point3D<T> ret(m_x - _other.m_x, m_y - _other.m_y, m_z - _other.m_z);
107 return ret;
108 }
109
110 template <class T> Point3D<T> Point3D<T>::operator * (const Point3D<T> & _other) const {
111 Point3D<T> ret(m_x * _other.m_x, m_y * _other.m_y, m_z * _other.m_z);
112 return ret;
113 }
114
115 template <class T> Point3D<T> Point3D<T>::operator / (const Point3D<T> & _other) const {
116 T x = m_x;
117 T y = m_y;
118 T z = m_z;
119 if (_other.m_x != 0) { x /= _other.m_x; }
120 if (_other.m_y != 0) { y /= _other.m_y; }
121 if (_other.m_z != 0) { z /= _other.m_z; }
122 Point3D<T> ret(x, y, z);
123 return ret;
124 }
125
126 template <class T> Point3D<T> & Point3D<T>::operator += (const Point3D<T> & _other) {
127 m_x = m_x + _other.m_x;
128 m_y = m_y + _other.m_y;
129 m_z = m_z + _other.m_z;
130 return *this;
131 }
132
133 template <class T> Point3D<T> & Point3D<T>::operator -= (const Point3D<T> & _other) {
134 m_x = m_x - _other.m_x;
135 m_y = m_y - _other.m_y;
136 m_z = m_z - _other.m_z;
137 return *this;
138 }
139
140 template <class T> Point3D<T> & Point3D<T>::operator *= (const Point3D<T> & _other) {
141 m_x = m_x * _other.m_x;
142 m_y = m_y * _other.m_y;
143 m_z = m_z * _other.m_z;
144 return *this;
145 }
146
147 template <class T> Point3D<T> & Point3D<T>::operator /= (const Point3D<T> & _other) {
148 if (_other.m_x != 0) { m_x /= _other.m_x; }
149 if (_other.m_y != 0) { m_y /= _other.m_y; }
150 if (_other.m_z != 0) { m_z /= _other.m_z; }
151 return *this;
152 }
153
154 template <class T> bool Point3D<T>::operator == (const Point3D<T> & _other) {
155 if (m_x != _other.x()) { return false; }
156 if (m_y != _other.y()) { return false; }
157 if (m_z != _other.z()) { return false; }
158 return true;
159 }
160
161 template <class T> bool Point3D<T>::operator != (const Point3D<T> & _other) { return !(*this == _other); }
162
163 template <class T> T Point3D<T>::addX(T _v) { m_x = m_x + _v; return m_x; }
164
165 template <class T> T Point3D<T>::addY(T _v) { m_y = m_y + _v; return m_y; }
166
167 template <class T> T Point3D<T>::addZ(T _v) { m_z = m_z + _v; return m_z; }
168
169 template <class T> T Point3D<T>::subX(T _v) { m_x = m_x - _v; return m_x; }
170
171 template <class T> T Point3D<T>::subY(T _v) { m_y = m_y - _v; return m_y; }
172
173 template <class T> T Point3D<T>::subZ(T _v) { m_z = m_z - _v; return m_z; }
174
175}
Three dimensional point.
Definition Point3D.h:12
Point3D< T > operator-(const Point3D< T > &_other) const
Definition Point3D.h:105
T x(void) const
Returns the current X value.
Definition Point3D.h:37
Point3D< T > & operator-=(const Point3D< T > &_other)
Definition Point3D.h:133
T addX(T _v)
Will add the provided value to the X value and return the new X value.
Definition Point3D.h:163
Point3D< T > operator+(const Point3D< T > &_other) const
Definition Point3D.h:100
Point3D< T > & operator*=(const Point3D< T > &_other)
Definition Point3D.h:140
Point3D< T > operator/(const Point3D< T > &_other) const
Definition Point3D.h:115
Point3D< T > & operator+=(const Point3D< T > &_other)
Definition Point3D.h:126
Point3D< T > operator*(const Point3D< T > &_other) const
Definition Point3D.h:110
bool operator!=(const Point3D< T > &_other)
Definition Point3D.h:161
T addY(T _v)
Will add the provided value to the Y value and return the new Y value.
Definition Point3D.h:165
void setZ(T _z)
Will set the Z value.
Definition Point3D.h:55
T subY(T _v)
Will subtract the provided value from the Y value and return the new Y value.
Definition Point3D.h:171
bool operator==(const Point3D< T > &_other)
Definition Point3D.h:154
T y(void) const
Returns the current Y value.
Definition Point3D.h:40
T subZ(T _v)
Will subtract the provided value from the Z value and return the new Z value.
Definition Point3D.h:173
Point3D< T > & operator/=(const Point3D< T > &_other)
Definition Point3D.h:147
void setY(T _y)
Will set the Y value.
Definition Point3D.h:51
T subX(T _v)
Will subtract the provided value from the X value and return the new X value.
Definition Point3D.h:169
void setX(T _x)
Will set the X value.
Definition Point3D.h:47
T addZ(T _z)
Will add the provided value to the Z value and return the new Z value.
Definition Point3D.h:167
T z(void) const
Returns the current Z value.
Definition Point3D.h:43
Point3D< T > & operator=(const Point3D< T > &_other)
Definition Point3D.h:95
Definition Connector.h:8