Skip to content

Commit 541e65a

Browse files
committed
make vector and pose members accessible
1 parent c6c0979 commit 541e65a

File tree

3 files changed

+29
-103
lines changed

3 files changed

+29
-103
lines changed

include/units/Pose.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ template <typename derivatives> class AbstractPose
1818
using Len = Divided<Length, Exponentiated<Time, derivatives>>;
1919
using Vector = Vector2D<Len>;
2020
public:
21+
Divided<Angle, Exponentiated<Time, derivatives>> orientation; /** Orientation */
22+
2123
/**
2224
* @brief Construct a new Pose object
2325
*
@@ -78,8 +80,6 @@ template <typename derivatives> class AbstractPose
7880
void setOrientation(Divided<Angle, Exponentiated<Time, derivatives>> orientation) {
7981
this->orientation = orientation;
8082
}
81-
protected:
82-
Divided<Angle, Exponentiated<Time, derivatives>> orientation; /** Orientation */
8383
};
8484

8585
// Position Pose (Length, Angle)

include/units/Vector2D.hpp

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace units {
1212
* @tparam T the type of quantity to use for the vector components
1313
*/
1414
template <isQuantity T> class Vector2D {
15-
protected:
15+
public:
1616
T x; /** x component */
1717
T y; /** y component */
18-
public:
18+
1919
/**
2020
* @brief Construct a new Vector2D object
2121
*
@@ -56,34 +56,6 @@ template <isQuantity T> class Vector2D {
5656
*/
5757
static Vector2D unitVector(Angle t) { return fromPolar(t, (T)1.0); }
5858

59-
/**
60-
* @brief get the x component
61-
*
62-
* @return T x component
63-
*/
64-
T getX() { return x; }
65-
66-
/**
67-
* @brief get the y component
68-
*
69-
* @return T y component
70-
*/
71-
T getY() { return y; }
72-
73-
/**
74-
* @brief set the x component
75-
*
76-
* @param nx x component
77-
*/
78-
void setX(T nx) { x = nx; }
79-
80-
/**
81-
* @brief set the y component
82-
*
83-
* @param ny y component
84-
*/
85-
void setY(T ny) { y = ny; }
86-
8759
/**
8860
* @brief + operator overload
8961
*
@@ -93,7 +65,7 @@ template <isQuantity T> class Vector2D {
9365
* @param other vector to add
9466
* @return Vector2D<T>
9567
*/
96-
Vector2D<T> operator+(Vector2D<T>& other) { return Vector2D<T>(x + other.getX(), y + other.getY()); }
68+
Vector2D<T> operator+(Vector2D<T>& other) { return Vector2D<T>(x + other.x, y + other.y); }
9769

9870
/**
9971
* @brief - operator overload
@@ -104,7 +76,7 @@ template <isQuantity T> class Vector2D {
10476
* @param other vector to subtract
10577
* @return Vector2D<T>
10678
*/
107-
Vector2D<T> operator-(Vector2D<T>& other) { return Vector2D<T>(x - other.getX(), y - other.getY()); }
79+
Vector2D<T> operator-(Vector2D<T>& other) { return Vector2D<T>(x - other.x, y - other.y); }
10880

10981
/**
11082
* @brief * operator overload
@@ -138,8 +110,8 @@ template <isQuantity T> class Vector2D {
138110
* @return Vector2D<T>&
139111
*/
140112
Vector2D<T>& operator+=(Vector2D<T>& other) {
141-
x += other.getX();
142-
y += other.getY();
113+
x += other.x;
114+
y += other.y;
143115
return (*this);
144116
}
145117

@@ -153,8 +125,8 @@ template <isQuantity T> class Vector2D {
153125
* @return Vector2D<T>&
154126
*/
155127
Vector2D<T>& operator-=(Vector2D<T>& other) {
156-
x -= other.getX();
157-
y -= other.getY();
128+
x -= other.x;
129+
y -= other.y;
158130
return (*this);
159131
}
160132

@@ -202,7 +174,7 @@ template <isQuantity T> class Vector2D {
202174
* @return R the dot product
203175
*/
204176
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector2D<Q>& other) {
205-
return (x * other.getX()) + (y * other.getY());
177+
return (x * other.x) + (y * other.y);
206178
}
207179

208180
/**
@@ -217,7 +189,7 @@ template <isQuantity T> class Vector2D {
217189
* @return R the cross product
218190
*/
219191
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R cross(Vector2D<Q>& other) {
220-
return (x * other.getY()) - (y * other.getX());
192+
return (x * other.y) - (y * other.x);
221193
}
222194

223195
/**
@@ -243,23 +215,23 @@ template <isQuantity T> class Vector2D {
243215
* @param other the other vector
244216
* @return Vector2D<T>
245217
*/
246-
Vector2D<T> vectorTo(Vector2D<T>& other) { return Vector2D<T>(other.getX() - x, other.getY() - y); }
218+
Vector2D<T> vectorTo(Vector2D<T>& other) { return Vector2D<T>(other.x - x, other.y - y); }
247219

248220
/**
249221
* @brief the angle between two vectors
250222
*
251223
* @param other the other vector
252224
* @return Angle
253225
*/
254-
Angle angleTo(Vector2D<T>& other) { return atan2(other.getY() - y, other.getX() - x); }
226+
Angle angleTo(Vector2D<T>& other) { return atan2(other.y - y, other.x - x); }
255227

256228
/**
257229
* @brief get the distance between two vectors
258230
*
259231
* @param other the other vector
260232
* @return T
261233
*/
262-
T distanceTo(Vector2D<T>& other) { return sqrt(square(x - other.getX(), 2) + square(y - other.getY(), 2)); }
234+
T distanceTo(Vector2D<T>& other) { return sqrt(square(x - other.x, 2) + square(y - other.y, 2)); }
263235

264236
/**
265237
* @brief normalize the vector

include/units/Vector3D.hpp

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace units {
1111
* @tparam T the type of quantity to use for the vector components
1212
*/
1313
template <isQuantity T> class Vector3D {
14-
protected:
14+
public:
1515
T x; /** x component */
1616
T y; /** y component */
1717
T z; /** z component */
18-
public:
18+
1919
/**
2020
* @brief Construct a new Vector2D object
2121
*
@@ -35,7 +35,7 @@ template <isQuantity T> class Vector3D {
3535
Vector3D(T nx, T ny, T nz) : x(nx), y(ny), z(nz) {}
3636

3737
/**
38-
* @brief Create a new Vector3D object from polar coordinates
38+
* @brief Create a new Vector3D object from spherical coordinates
3939
*
4040
* This constructor takes polar coordinates and converts them to cartesian coordinates
4141
*
@@ -44,7 +44,7 @@ template <isQuantity T> class Vector3D {
4444
*/
4545
static Vector3D fromPolar(Vector3D<Angle>& t, T m) {
4646
m = m.abs();
47-
return Vector2D<T>(m * cos(t.x), m * cos(t.y), m * cos(t.z));
47+
return Vector3D<T>(m * cos(t.x), m * cos(t.y), m * cos(t.z));
4848
}
4949

5050
/**
@@ -55,48 +55,6 @@ template <isQuantity T> class Vector3D {
5555
*/
5656
static Vector3D unitVector(Vector3D<Angle> t) { return fromPolar(t, (T)1.0); }
5757

58-
/**
59-
* @brief get the x component
60-
*
61-
* @return T x component
62-
*/
63-
T getX() { return x; }
64-
65-
/**
66-
* @brief get the y component
67-
*
68-
* @return T y component
69-
*/
70-
T getY() { return y; }
71-
72-
/**
73-
* @brief get the z component
74-
*
75-
* @return T z component
76-
*/
77-
T getZ() { return z; }
78-
79-
/**
80-
* @brief set the x component
81-
*
82-
* @param nx x component
83-
*/
84-
void setX(T nx) { x = nx; }
85-
86-
/**
87-
* @brief set the y component
88-
*
89-
* @param ny y component
90-
*/
91-
void setY(T ny) { y = ny; }
92-
93-
/**
94-
* @brief set the z component
95-
*
96-
* @param nz z component
97-
*/
98-
void setZ(T nz) { z = nz; }
99-
10058
/**
10159
* @brief + operator overload
10260
*
@@ -106,9 +64,7 @@ template <isQuantity T> class Vector3D {
10664
* @param other vector to add
10765
* @return Vector3D<T>
10866
*/
109-
Vector3D<T> operator+(Vector3D<T>& other) {
110-
return Vector3D<T>(x + other.getX(), y + other.getY(), z + getZ());
111-
}
67+
Vector3D<T> operator+(Vector3D<T>& other) { return Vector3D<T>(x + other.x, y + other.y, z + other.z); }
11268

11369
/**
11470
* @brief - operator overload
@@ -119,7 +75,7 @@ template <isQuantity T> class Vector3D {
11975
* @param other vector to subtract
12076
* @return Vector3D<T>
12177
*/
122-
Vector3D<T> operator-(Vector3D<T>& other) { return Vector3D<T>(x - other.getX(), y - other.getY()); }
78+
Vector3D<T> operator-(Vector3D<T>& other) { return Vector3D<T>(x - other.x, y - other.y, z - other.z); }
12379

12480
/**
12581
* @brief * operator overload
@@ -153,9 +109,9 @@ template <isQuantity T> class Vector3D {
153109
* @return Vector3D<T>&
154110
*/
155111
Vector3D<T>& operator+=(Vector3D<T>& other) {
156-
x += other.getX();
157-
y += other.getY();
158-
z += other.getZ();
112+
x += other.x;
113+
y += other.y;
114+
z += other.z;
159115
return (*this);
160116
}
161117

@@ -169,9 +125,9 @@ template <isQuantity T> class Vector3D {
169125
* @return Vector3D<T>&
170126
*/
171127
Vector3D<T>& operator-=(Vector3D<T>& other) {
172-
x -= other.getX();
173-
y -= other.getY();
174-
z -= other.getZ();
128+
x -= other.x;
129+
y -= other.y;
130+
z -= other.z;
175131
return (*this);
176132
}
177133

@@ -221,7 +177,7 @@ template <isQuantity T> class Vector3D {
221177
* @return R the dot product
222178
*/
223179
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector3D<Q>& other) {
224-
return (x * other.getX()) + (y * other.getY()) + (z * other.getZ());
180+
return (x * other.x) + (y * other.y) + (z * other.z);
225181
}
226182

227183
/**
@@ -269,9 +225,7 @@ template <isQuantity T> class Vector3D {
269225
* @param other the other vector
270226
* @return Vector3D<T>
271227
*/
272-
Vector3D<T> vectorTo(Vector3D<T>& other) {
273-
return Vector2D<T>(other.getX() - x, other.getY() - y, other.getZ() - z);
274-
}
228+
Vector3D<T> vectorTo(Vector3D<T>& other) { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }
275229

276230
/**
277231
* @brief the angle between two vectors

0 commit comments

Comments
 (0)