diff --git a/components/joystick/include/joystick.hpp b/components/joystick/include/joystick.hpp index dbd1d47a2..327131405 100644 --- a/components/joystick/include/joystick.hpp +++ b/components/joystick/include/joystick.hpp @@ -202,8 +202,9 @@ class Joystick : public BaseComponent { /** * @brief Get the most recently updated calibrated position. * @return The most recent position (from when update() was last called). + * @note The returned reference is valid as long as the Joystick object is alive. */ - espp::Vector2f position() const; + const espp::Vector2f &position() const; /** * @brief Get the most recently updated raw / uncalibrated readings. This @@ -212,8 +213,9 @@ class Joystick : public BaseComponent { * structures. * @return The most recent raw measurements (from when update() was last * called). + * @note The returned reference is valid as long as the Joystick object is alive. */ - espp::Vector2f raw() const; + const espp::Vector2f &raw() const; friend struct fmt::formatter; diff --git a/components/joystick/src/joystick.cpp b/components/joystick/src/joystick.cpp index 64cd02f48..42ba06048 100644 --- a/components/joystick/src/joystick.cpp +++ b/components/joystick/src/joystick.cpp @@ -74,9 +74,9 @@ float espp::Joystick::x() const { return position_.x(); } float espp::Joystick::y() const { return position_.y(); } -espp::Vector2f espp::Joystick::position() const { return position_; } +const espp::Vector2f &espp::Joystick::position() const { return position_; } -espp::Vector2f espp::Joystick::raw() const { return raw_; } +const espp::Vector2f &espp::Joystick::raw() const { return raw_; } void espp::Joystick::recalculate(float raw_x, float raw_y) { raw_.x(raw_x); diff --git a/components/math/include/vector2d.hpp b/components/math/include/vector2d.hpp index bb99f906b..acbe9dde8 100644 --- a/components/math/include/vector2d.hpp +++ b/components/math/include/vector2d.hpp @@ -76,7 +76,7 @@ template class Vector2d { * @brief Getter for the x value. * @return The current x value. */ - T x() const { return x_; } + const T &x() const { return x_; } /** * @brief Setter for the x value. @@ -88,7 +88,7 @@ template class Vector2d { * @brief Getter for the y value. * @return The current y value. */ - T y() const { return y_; } + const T &y() const { return y_; } /** * @brief Setter for the y value.