mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpimath] Add scalar multiply and divide operators to all geometry classes (#4438)
Closes #4435.
This commit is contained in:
@@ -33,6 +33,14 @@ bool Pose2d::operator!=(const Pose2d& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
Pose2d Pose2d::operator*(double scalar) const {
|
||||
return Pose2d{m_translation * scalar, m_rotation * scalar};
|
||||
}
|
||||
|
||||
Pose2d Pose2d::operator/(double scalar) const {
|
||||
return *this * (1.0 / scalar);
|
||||
}
|
||||
|
||||
Pose2d Pose2d::TransformBy(const Transform2d& other) const {
|
||||
return {m_translation + (other.Translation().RotateBy(m_rotation)),
|
||||
m_rotation + other.Rotation()};
|
||||
|
||||
@@ -54,6 +54,14 @@ bool Pose3d::operator!=(const Pose3d& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
Pose3d Pose3d::operator*(double scalar) const {
|
||||
return Pose3d{m_translation * scalar, m_rotation * scalar};
|
||||
}
|
||||
|
||||
Pose3d Pose3d::operator/(double scalar) const {
|
||||
return *this * (1.0 / scalar);
|
||||
}
|
||||
|
||||
Pose3d Pose3d::TransformBy(const Transform3d& other) const {
|
||||
return {m_translation + (other.Translation().RotateBy(m_rotation)),
|
||||
m_rotation + other.Rotation()};
|
||||
|
||||
@@ -50,6 +50,10 @@ Rotation2d Rotation2d::operator*(double scalar) const {
|
||||
return Rotation2d{m_value * scalar};
|
||||
}
|
||||
|
||||
Rotation2d Rotation2d::operator/(double scalar) const {
|
||||
return *this * (1.0 / scalar);
|
||||
}
|
||||
|
||||
bool Rotation2d::operator==(const Rotation2d& other) const {
|
||||
return std::hypot(m_cos - other.m_cos, m_sin - other.m_sin) < 1E-9;
|
||||
}
|
||||
|
||||
@@ -165,6 +165,10 @@ Rotation3d Rotation3d::operator*(double scalar) const {
|
||||
}
|
||||
}
|
||||
|
||||
Rotation3d Rotation3d::operator/(double scalar) const {
|
||||
return *this * (1.0 / scalar);
|
||||
}
|
||||
|
||||
bool Rotation3d::operator==(const Rotation3d& other) const {
|
||||
return m_q == other.m_q;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,24 @@ class WPILIB_DLLEXPORT Pose2d {
|
||||
*/
|
||||
const Rotation2d& Rotation() const { return m_rotation; }
|
||||
|
||||
/**
|
||||
* Multiplies the current pose by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Pose2d.
|
||||
*/
|
||||
Pose2d operator*(double scalar) const;
|
||||
|
||||
/**
|
||||
* Divides the current pose by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Pose2d.
|
||||
*/
|
||||
Pose2d operator/(double scalar) const;
|
||||
|
||||
/**
|
||||
* Transforms the pose by the given transformation and returns the new pose.
|
||||
* See + operator for the matrix multiplication performed.
|
||||
|
||||
@@ -112,6 +112,24 @@ class WPILIB_DLLEXPORT Pose3d {
|
||||
*/
|
||||
const Rotation3d& Rotation() const { return m_rotation; }
|
||||
|
||||
/**
|
||||
* Multiplies the current pose by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Pose2d.
|
||||
*/
|
||||
Pose3d operator*(double scalar) const;
|
||||
|
||||
/**
|
||||
* Divides the current pose by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Pose2d.
|
||||
*/
|
||||
Pose3d operator/(double scalar) const;
|
||||
|
||||
/**
|
||||
* Transforms the pose by the given transformation and returns the new pose.
|
||||
* See + operator for the matrix multiplication performed.
|
||||
|
||||
@@ -84,12 +84,22 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
|
||||
/**
|
||||
* Multiplies the current rotation by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Rotation2d.
|
||||
*/
|
||||
Rotation2d operator*(double scalar) const;
|
||||
|
||||
/**
|
||||
* Divides the current rotation by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Rotation2d.
|
||||
*/
|
||||
Rotation2d operator/(double scalar) const;
|
||||
|
||||
/**
|
||||
* Checks equality between this Rotation2d and another object.
|
||||
*
|
||||
|
||||
@@ -99,12 +99,22 @@ class WPILIB_DLLEXPORT Rotation3d {
|
||||
|
||||
/**
|
||||
* Multiplies the current rotation by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Rotation3d.
|
||||
*/
|
||||
Rotation3d operator*(double scalar) const;
|
||||
|
||||
/**
|
||||
* Divides the current rotation by a scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
*
|
||||
* @return The new scaled Rotation3d.
|
||||
*/
|
||||
Rotation3d operator/(double scalar) const;
|
||||
|
||||
/**
|
||||
* Checks equality between this Rotation3d and another object.
|
||||
*
|
||||
|
||||
@@ -74,7 +74,7 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
Transform2d Inverse() const;
|
||||
|
||||
/**
|
||||
* Scales the transform by the scalar.
|
||||
* Multiplies the transform by the scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform2d.
|
||||
@@ -83,6 +83,14 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
return Transform2d(m_translation * scalar, m_rotation * scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides the transform by the scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform2d.
|
||||
*/
|
||||
Transform2d operator/(double scalar) const { return *this * (1.0 / scalar); }
|
||||
|
||||
/**
|
||||
* Composes two transformations.
|
||||
*
|
||||
|
||||
@@ -81,7 +81,7 @@ class WPILIB_DLLEXPORT Transform3d {
|
||||
Transform3d Inverse() const;
|
||||
|
||||
/**
|
||||
* Scales the transform by the scalar.
|
||||
* Multiplies the transform by the scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform3d.
|
||||
@@ -90,6 +90,14 @@ class WPILIB_DLLEXPORT Transform3d {
|
||||
return Transform3d(m_translation * scalar, m_rotation * scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides the transform by the scalar.
|
||||
*
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform3d.
|
||||
*/
|
||||
Transform3d operator/(double scalar) const { return *this * (1.0 / scalar); }
|
||||
|
||||
/**
|
||||
* Composes two transformations.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user