Skip to content

feat(joystick/vector): Update to return const ref where possible #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/joystick/include/joystick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Joystick : public BaseComponent {
* @brief Get the most recently updated calibrated position.
* @return The most recent position (from when update() was last called).
*/
espp::Vector2f position() const;
const espp::Vector2f &position() const;

/**
* @brief Get the most recently updated raw / uncalibrated readings. This
Expand All @@ -213,7 +213,7 @@ class Joystick : public BaseComponent {
* @return The most recent raw measurements (from when update() was last
* called).
*/
espp::Vector2f raw() const;
const espp::Vector2f &raw() const;

friend struct fmt::formatter<Joystick>;

Expand Down
4 changes: 2 additions & 2 deletions components/joystick/src/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/math/include/vector2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ template <typename T> 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.
Expand Down