Skip to content

Commit

Permalink
Make appropriate pose methods const
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ committed Nov 19, 2023
1 parent eb3e37b commit dfbd688
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions include/lemlib/pose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Pose {
* @param other other pose
* @return Pose
*/
Pose operator+(const Pose& other);
Pose operator+(const Pose& other) const;
/**
* @brief Set the value of this pose to its value + the value of another pose
*
Expand All @@ -48,7 +48,7 @@ class Pose {
* @param other other pose
* @return Pose
*/
Pose operator-(const Pose& other);
Pose operator-(const Pose& other) const;
/**
* @brief Set the value of this pose to its value - the value of another pose
*
Expand All @@ -61,57 +61,57 @@ class Pose {
* @param other other pose
* @return Pose
*/
float operator*(const Pose& other);
float operator*(const Pose& other) const;
/**
* @brief Multiply a pose by a float
*
* @param other float
* @return Pose
*/
Pose operator*(const float& other);
Pose operator*(const float& other) const;
/**
* @brief Divide a pose by a float
*
* @param other float
* @return Pose
*/
Pose operator/(const float& other);
Pose operator/(const float& other) const;
/**
* @brief Check if two poses are equal
*
* @param other the other pose
* @return bool
*/
bool operator==(const Pose& other);
bool operator==(const Pose& other) const;
/**
* @brief Check if two poses are not equal
*
* @param other the other pose
* @return bool
*/
bool operator!=(const Pose& other);
bool operator!=(const Pose& other) const;
/**
* @brief Linearly interpolate between two poses
*
* @param other the other pose
* @param t t value
* @return Pose
*/
Pose lerp(Pose other, float t);
Pose lerp(const Pose other, float t) const;
/**
* @brief Get the distance between two poses
*
* @param other the other pose
* @return float
*/
float distance(Pose other);
float distance(const Pose other) const;
/**
* @brief Get the angle between two poses
*
* @param other the other pose
* @return float in radians
*/
float angle(Pose other);
float angle(const Pose other) const;
/**
* @brief Rotate a pose by an angle
*
Expand All @@ -120,7 +120,7 @@ class Pose {
* @param angle angle in radians
* @return Pose
*/
Pose rotate(float angle);
Pose rotate(float angle) const;
};

/**
Expand Down
22 changes: 11 additions & 11 deletions src/lemlib/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Pose::Pose(float x, float y, float theta)
* @param other other pose
* @return Pose
*/
Pose Pose::operator+(const Pose& other) { return Pose(x + other.x, y + other.y, theta); }
Pose Pose::operator+(const Pose& other) const { return Pose(x + other.x, y + other.y, theta); }

/**
* @brief Set the value of this pose to its value + the value of another pose
Expand All @@ -54,7 +54,7 @@ void Pose::operator+=(const Pose& other) {
* @param other other pose
* @return Pose
*/
Pose Pose::operator-(const Pose& other) { return Pose(x - other.x, y - other.y, theta); }
Pose Pose::operator-(const Pose& other) const { return Pose(x - other.x, y - other.y, theta); }

/**
* @brief Set the value of this pose to its value - the value of another pose
Expand All @@ -73,39 +73,39 @@ void Pose::operator-=(const Pose& other) {
* @param other other pose
* @return Pose
*/
float Pose::operator*(const Pose& other) { return x * other.x + y * other.y; }
float Pose::operator*(const Pose& other) const { return x * other.x + y * other.y; }

/**
* @brief Multiply a pose by a float
*
* @param other float
* @return Pose
*/
Pose Pose::operator*(const float& other) { return Pose(x * other, y * other, theta); }
Pose Pose::operator*(const float& other)const { return Pose(x * other, y * other, theta); }

/**
* @brief Divide a pose by a float
*
* @param other float
* @return Pose
*/
Pose Pose::operator/(const float& other) { return Pose(x / other, y / other, theta); }
Pose Pose::operator/(const float& other) const { return Pose(x / other, y / other, theta); }

/**
* @brief Check if two poses are equal
*
* @param other the other pose
* @return bool
*/
bool Pose::operator==(const Pose& other) { return x == other.x && y == other.y && theta == other.theta; }
bool Pose::operator==(const Pose& other) const { return x == other.x && y == other.y && theta == other.theta; }

/**
* @brief Check if two poses are not equal
*
* @param other the other pose
* @return bool
*/
bool Pose::operator!=(const Pose& other) { return x != other.x || y != other.y || theta != other.theta; }
bool Pose::operator!=(const Pose& other) const { return x != other.x || y != other.y || theta != other.theta; }

/**
* @brief Linearly interpolate between two poses
Expand All @@ -114,31 +114,31 @@ bool Pose::operator!=(const Pose& other) { return x != other.x || y != other.y |
* @param t t value
* @return Pose
*/
Pose Pose::lerp(Pose other, float t) { return Pose(x + (other.x - x) * t, y + (other.y - y) * t, theta); }
Pose Pose::lerp(Pose other, float t) const { return Pose(x + (other.x - x) * t, y + (other.y - y) * t, theta); }

/**
* @brief Get the distance between two poses
*
* @param other the other pose
* @return float
*/
float Pose::distance(Pose other) { return std::hypot(x - other.x, y - other.y); }
float Pose::distance(Pose other) const { return std::hypot(x - other.x, y - other.y); }

/**
* @brief Get the angle between two poses
*
* @param other the other pose
* @return float in radians
*/
float Pose::angle(Pose other) { return std::atan2(other.y - y, other.x - x); }
float Pose::angle(Pose other) const { return std::atan2(other.y - y, other.x - x); }

/**
* @brief Rotate a pose by an angle
*
* @param angle angle in radians
* @return Pose
*/
Pose Pose::rotate(float angle) {
Pose Pose::rotate(float angle) const {
const float cosAngle = std::cos(angle);
const float sinAngle = std::sin(angle);

Expand Down

0 comments on commit dfbd688

Please sign in to comment.