From 541e65a308deb7db1870f11dc773d84fa8e9c14d Mon Sep 17 00:00:00 2001 From: Liam Teale Date: Thu, 26 Dec 2024 15:12:56 -0800 Subject: [PATCH] make vector and pose members accessible --- include/units/Pose.hpp | 4 +-- include/units/Vector2D.hpp | 54 +++++++--------------------- include/units/Vector3D.hpp | 74 ++++++++------------------------------ 3 files changed, 29 insertions(+), 103 deletions(-) diff --git a/include/units/Pose.hpp b/include/units/Pose.hpp index 222f1e1..4c67fc7 100644 --- a/include/units/Pose.hpp +++ b/include/units/Pose.hpp @@ -18,6 +18,8 @@ template class AbstractPose using Len = Divided>; using Vector = Vector2D; public: + Divided> orientation; /** Orientation */ + /** * @brief Construct a new Pose object * @@ -78,8 +80,6 @@ template class AbstractPose void setOrientation(Divided> orientation) { this->orientation = orientation; } - protected: - Divided> orientation; /** Orientation */ }; // Position Pose (Length, Angle) diff --git a/include/units/Vector2D.hpp b/include/units/Vector2D.hpp index 8886c9b..a9c0fbf 100644 --- a/include/units/Vector2D.hpp +++ b/include/units/Vector2D.hpp @@ -12,10 +12,10 @@ namespace units { * @tparam T the type of quantity to use for the vector components */ template class Vector2D { - protected: + public: T x; /** x component */ T y; /** y component */ - public: + /** * @brief Construct a new Vector2D object * @@ -56,34 +56,6 @@ template 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 * @@ -93,7 +65,7 @@ template class Vector2D { * @param other vector to add * @return Vector2D */ - Vector2D operator+(Vector2D& other) { return Vector2D(x + other.getX(), y + other.getY()); } + Vector2D operator+(Vector2D& other) { return Vector2D(x + other.x, y + other.y); } /** * @brief - operator overload @@ -104,7 +76,7 @@ template class Vector2D { * @param other vector to subtract * @return Vector2D */ - Vector2D operator-(Vector2D& other) { return Vector2D(x - other.getX(), y - other.getY()); } + Vector2D operator-(Vector2D& other) { return Vector2D(x - other.x, y - other.y); } /** * @brief * operator overload @@ -138,8 +110,8 @@ template class Vector2D { * @return Vector2D& */ Vector2D& operator+=(Vector2D& other) { - x += other.getX(); - y += other.getY(); + x += other.x; + y += other.y; return (*this); } @@ -153,8 +125,8 @@ template class Vector2D { * @return Vector2D& */ Vector2D& operator-=(Vector2D& other) { - x -= other.getX(); - y -= other.getY(); + x -= other.x; + y -= other.y; return (*this); } @@ -202,7 +174,7 @@ template class Vector2D { * @return R the dot product */ template > R dot(Vector2D& other) { - return (x * other.getX()) + (y * other.getY()); + return (x * other.x) + (y * other.y); } /** @@ -217,7 +189,7 @@ template class Vector2D { * @return R the cross product */ template > R cross(Vector2D& other) { - return (x * other.getY()) - (y * other.getX()); + return (x * other.y) - (y * other.x); } /** @@ -243,7 +215,7 @@ template class Vector2D { * @param other the other vector * @return Vector2D */ - Vector2D vectorTo(Vector2D& other) { return Vector2D(other.getX() - x, other.getY() - y); } + Vector2D vectorTo(Vector2D& other) { return Vector2D(other.x - x, other.y - y); } /** * @brief the angle between two vectors @@ -251,7 +223,7 @@ template class Vector2D { * @param other the other vector * @return Angle */ - Angle angleTo(Vector2D& other) { return atan2(other.getY() - y, other.getX() - x); } + Angle angleTo(Vector2D& other) { return atan2(other.y - y, other.x - x); } /** * @brief get the distance between two vectors @@ -259,7 +231,7 @@ template class Vector2D { * @param other the other vector * @return T */ - T distanceTo(Vector2D& other) { return sqrt(square(x - other.getX(), 2) + square(y - other.getY(), 2)); } + T distanceTo(Vector2D& other) { return sqrt(square(x - other.x, 2) + square(y - other.y, 2)); } /** * @brief normalize the vector diff --git a/include/units/Vector3D.hpp b/include/units/Vector3D.hpp index c8a181c..1bae018 100644 --- a/include/units/Vector3D.hpp +++ b/include/units/Vector3D.hpp @@ -11,11 +11,11 @@ namespace units { * @tparam T the type of quantity to use for the vector components */ template class Vector3D { - protected: + public: T x; /** x component */ T y; /** y component */ T z; /** z component */ - public: + /** * @brief Construct a new Vector2D object * @@ -35,7 +35,7 @@ template 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 * @@ -44,7 +44,7 @@ template class Vector3D { */ static Vector3D fromPolar(Vector3D& t, T m) { m = m.abs(); - return Vector2D(m * cos(t.x), m * cos(t.y), m * cos(t.z)); + return Vector3D(m * cos(t.x), m * cos(t.y), m * cos(t.z)); } /** @@ -55,48 +55,6 @@ template class Vector3D { */ static Vector3D unitVector(Vector3D 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 * @@ -106,9 +64,7 @@ template class Vector3D { * @param other vector to add * @return Vector3D */ - Vector3D operator+(Vector3D& other) { - return Vector3D(x + other.getX(), y + other.getY(), z + getZ()); - } + Vector3D operator+(Vector3D& other) { return Vector3D(x + other.x, y + other.y, z + other.z); } /** * @brief - operator overload @@ -119,7 +75,7 @@ template class Vector3D { * @param other vector to subtract * @return Vector3D */ - Vector3D operator-(Vector3D& other) { return Vector3D(x - other.getX(), y - other.getY()); } + Vector3D operator-(Vector3D& other) { return Vector3D(x - other.x, y - other.y, z - other.z); } /** * @brief * operator overload @@ -153,9 +109,9 @@ template class Vector3D { * @return Vector3D& */ Vector3D& operator+=(Vector3D& other) { - x += other.getX(); - y += other.getY(); - z += other.getZ(); + x += other.x; + y += other.y; + z += other.z; return (*this); } @@ -169,9 +125,9 @@ template class Vector3D { * @return Vector3D& */ Vector3D& operator-=(Vector3D& other) { - x -= other.getX(); - y -= other.getY(); - z -= other.getZ(); + x -= other.x; + y -= other.y; + z -= other.z; return (*this); } @@ -221,7 +177,7 @@ template class Vector3D { * @return R the dot product */ template > R dot(Vector3D& other) { - return (x * other.getX()) + (y * other.getY()) + (z * other.getZ()); + return (x * other.x) + (y * other.y) + (z * other.z); } /** @@ -269,9 +225,7 @@ template class Vector3D { * @param other the other vector * @return Vector3D */ - Vector3D vectorTo(Vector3D& other) { - return Vector2D(other.getX() - x, other.getY() - y, other.getZ() - z); - } + Vector3D vectorTo(Vector3D& other) { return Vector2D(other.x - x, other.y - y, other.z - z); } /** * @brief the angle between two vectors