Skip to content

Commit

Permalink
make vector and pose members accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Dec 26, 2024
1 parent c6c0979 commit 541e65a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 103 deletions.
4 changes: 2 additions & 2 deletions include/units/Pose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ template <typename derivatives> class AbstractPose
using Len = Divided<Length, Exponentiated<Time, derivatives>>;
using Vector = Vector2D<Len>;
public:
Divided<Angle, Exponentiated<Time, derivatives>> orientation; /** Orientation */

/**
* @brief Construct a new Pose object
*
Expand Down Expand Up @@ -78,8 +80,6 @@ template <typename derivatives> class AbstractPose
void setOrientation(Divided<Angle, Exponentiated<Time, derivatives>> orientation) {
this->orientation = orientation;
}
protected:
Divided<Angle, Exponentiated<Time, derivatives>> orientation; /** Orientation */
};

// Position Pose (Length, Angle)
Expand Down
54 changes: 13 additions & 41 deletions include/units/Vector2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace units {
* @tparam T the type of quantity to use for the vector components
*/
template <isQuantity T> class Vector2D {
protected:
public:
T x; /** x component */
T y; /** y component */
public:

/**
* @brief Construct a new Vector2D object
*
Expand Down Expand Up @@ -56,34 +56,6 @@ template <isQuantity T> class Vector2D {
*/
static Vector2D unitVector(Angle t) { return fromPolar(t, (T)1.0); }

/**
* @brief get the x component
*
* @return T x component
*/
T getX() { return x; }

/**
* @brief get the y component
*
* @return T y component
*/
T getY() { return y; }

/**
* @brief set the x component
*
* @param nx x component
*/
void setX(T nx) { x = nx; }

/**
* @brief set the y component
*
* @param ny y component
*/
void setY(T ny) { y = ny; }

/**
* @brief + operator overload
*
Expand All @@ -93,7 +65,7 @@ template <isQuantity T> class Vector2D {
* @param other vector to add
* @return Vector2D<T>
*/
Vector2D<T> operator+(Vector2D<T>& other) { return Vector2D<T>(x + other.getX(), y + other.getY()); }
Vector2D<T> operator+(Vector2D<T>& other) { return Vector2D<T>(x + other.x, y + other.y); }

/**
* @brief - operator overload
Expand All @@ -104,7 +76,7 @@ template <isQuantity T> class Vector2D {
* @param other vector to subtract
* @return Vector2D<T>
*/
Vector2D<T> operator-(Vector2D<T>& other) { return Vector2D<T>(x - other.getX(), y - other.getY()); }
Vector2D<T> operator-(Vector2D<T>& other) { return Vector2D<T>(x - other.x, y - other.y); }

/**
* @brief * operator overload
Expand Down Expand Up @@ -138,8 +110,8 @@ template <isQuantity T> class Vector2D {
* @return Vector2D<T>&
*/
Vector2D<T>& operator+=(Vector2D<T>& other) {
x += other.getX();
y += other.getY();
x += other.x;
y += other.y;
return (*this);
}

Expand All @@ -153,8 +125,8 @@ template <isQuantity T> class Vector2D {
* @return Vector2D<T>&
*/
Vector2D<T>& operator-=(Vector2D<T>& other) {
x -= other.getX();
y -= other.getY();
x -= other.x;
y -= other.y;
return (*this);
}

Expand Down Expand Up @@ -202,7 +174,7 @@ template <isQuantity T> class Vector2D {
* @return R the dot product
*/
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector2D<Q>& other) {
return (x * other.getX()) + (y * other.getY());
return (x * other.x) + (y * other.y);
}

/**
Expand All @@ -217,7 +189,7 @@ template <isQuantity T> class Vector2D {
* @return R the cross product
*/
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R cross(Vector2D<Q>& other) {
return (x * other.getY()) - (y * other.getX());
return (x * other.y) - (y * other.x);
}

/**
Expand All @@ -243,23 +215,23 @@ template <isQuantity T> class Vector2D {
* @param other the other vector
* @return Vector2D<T>
*/
Vector2D<T> vectorTo(Vector2D<T>& other) { return Vector2D<T>(other.getX() - x, other.getY() - y); }
Vector2D<T> vectorTo(Vector2D<T>& other) { return Vector2D<T>(other.x - x, other.y - y); }

/**
* @brief the angle between two vectors
*
* @param other the other vector
* @return Angle
*/
Angle angleTo(Vector2D<T>& other) { return atan2(other.getY() - y, other.getX() - x); }
Angle angleTo(Vector2D<T>& other) { return atan2(other.y - y, other.x - x); }

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

/**
* @brief normalize the vector
Expand Down
74 changes: 14 additions & 60 deletions include/units/Vector3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace units {
* @tparam T the type of quantity to use for the vector components
*/
template <isQuantity T> class Vector3D {
protected:
public:
T x; /** x component */
T y; /** y component */
T z; /** z component */
public:

/**
* @brief Construct a new Vector2D object
*
Expand All @@ -35,7 +35,7 @@ template <isQuantity T> class Vector3D {
Vector3D(T nx, T ny, T nz) : x(nx), y(ny), z(nz) {}

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

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

/**
* @brief get the x component
*
* @return T x component
*/
T getX() { return x; }

/**
* @brief get the y component
*
* @return T y component
*/
T getY() { return y; }

/**
* @brief get the z component
*
* @return T z component
*/
T getZ() { return z; }

/**
* @brief set the x component
*
* @param nx x component
*/
void setX(T nx) { x = nx; }

/**
* @brief set the y component
*
* @param ny y component
*/
void setY(T ny) { y = ny; }

/**
* @brief set the z component
*
* @param nz z component
*/
void setZ(T nz) { z = nz; }

/**
* @brief + operator overload
*
Expand All @@ -106,9 +64,7 @@ template <isQuantity T> class Vector3D {
* @param other vector to add
* @return Vector3D<T>
*/
Vector3D<T> operator+(Vector3D<T>& other) {
return Vector3D<T>(x + other.getX(), y + other.getY(), z + getZ());
}
Vector3D<T> operator+(Vector3D<T>& other) { return Vector3D<T>(x + other.x, y + other.y, z + other.z); }

/**
* @brief - operator overload
Expand All @@ -119,7 +75,7 @@ template <isQuantity T> class Vector3D {
* @param other vector to subtract
* @return Vector3D<T>
*/
Vector3D<T> operator-(Vector3D<T>& other) { return Vector3D<T>(x - other.getX(), y - other.getY()); }
Vector3D<T> operator-(Vector3D<T>& other) { return Vector3D<T>(x - other.x, y - other.y, z - other.z); }

/**
* @brief * operator overload
Expand Down Expand Up @@ -153,9 +109,9 @@ template <isQuantity T> class Vector3D {
* @return Vector3D<T>&
*/
Vector3D<T>& operator+=(Vector3D<T>& other) {
x += other.getX();
y += other.getY();
z += other.getZ();
x += other.x;
y += other.y;
z += other.z;
return (*this);
}

Expand All @@ -169,9 +125,9 @@ template <isQuantity T> class Vector3D {
* @return Vector3D<T>&
*/
Vector3D<T>& operator-=(Vector3D<T>& other) {
x -= other.getX();
y -= other.getY();
z -= other.getZ();
x -= other.x;
y -= other.y;
z -= other.z;
return (*this);
}

Expand Down Expand Up @@ -221,7 +177,7 @@ template <isQuantity T> class Vector3D {
* @return R the dot product
*/
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector3D<Q>& other) {
return (x * other.getX()) + (y * other.getY()) + (z * other.getZ());
return (x * other.x) + (y * other.y) + (z * other.z);
}

/**
Expand Down Expand Up @@ -269,9 +225,7 @@ template <isQuantity T> class Vector3D {
* @param other the other vector
* @return Vector3D<T>
*/
Vector3D<T> vectorTo(Vector3D<T>& other) {
return Vector2D<T>(other.getX() - x, other.getY() - y, other.getZ() - z);
}
Vector3D<T> vectorTo(Vector3D<T>& other) { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }

/**
* @brief the angle between two vectors
Expand Down

0 comments on commit 541e65a

Please sign in to comment.