mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpimath] Increase constexpr support in geometry data types (#4231)
This uses std::is_constant_evaluated() to conditionally use the gcem library for constexpr calculations.
This commit is contained in:
@@ -31,7 +31,7 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
* @param translation Translational component of the transform.
|
||||
* @param rotation Rotational component of the transform.
|
||||
*/
|
||||
Transform2d(Translation2d translation, Rotation2d rotation);
|
||||
constexpr Transform2d(Translation2d translation, Rotation2d rotation);
|
||||
|
||||
/**
|
||||
* Constructs the identity transform -- maps an initial pose to itself.
|
||||
@@ -43,35 +43,35 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
*
|
||||
* @return Reference to the translational component of the transform.
|
||||
*/
|
||||
const Translation2d& Translation() const { return m_translation; }
|
||||
constexpr const Translation2d& Translation() const { return m_translation; }
|
||||
|
||||
/**
|
||||
* Returns the X component of the transformation's translation.
|
||||
*
|
||||
* @return The x component of the transformation's translation.
|
||||
*/
|
||||
units::meter_t X() const { return m_translation.X(); }
|
||||
constexpr units::meter_t X() const { return m_translation.X(); }
|
||||
|
||||
/**
|
||||
* Returns the Y component of the transformation's translation.
|
||||
*
|
||||
* @return The y component of the transformation's translation.
|
||||
*/
|
||||
units::meter_t Y() const { return m_translation.Y(); }
|
||||
constexpr units::meter_t Y() const { return m_translation.Y(); }
|
||||
|
||||
/**
|
||||
* Returns the rotational component of the transformation.
|
||||
*
|
||||
* @return Reference to the rotational component of the transform.
|
||||
*/
|
||||
const Rotation2d& Rotation() const { return m_rotation; }
|
||||
constexpr const Rotation2d& Rotation() const { return m_rotation; }
|
||||
|
||||
/**
|
||||
* Invert the transformation. This is useful for undoing a transformation.
|
||||
*
|
||||
* @return The inverted transformation.
|
||||
*/
|
||||
Transform2d Inverse() const;
|
||||
constexpr Transform2d Inverse() const;
|
||||
|
||||
/**
|
||||
* Multiplies the transform by the scalar.
|
||||
@@ -79,7 +79,7 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform2d.
|
||||
*/
|
||||
Transform2d operator*(double scalar) const {
|
||||
constexpr Transform2d operator*(double scalar) const {
|
||||
return Transform2d(m_translation * scalar, m_rotation * scalar);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,9 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
* @param scalar The scalar.
|
||||
* @return The scaled Transform2d.
|
||||
*/
|
||||
Transform2d operator/(double scalar) const { return *this * (1.0 / scalar); }
|
||||
constexpr Transform2d operator/(double scalar) const {
|
||||
return *this * (1.0 / scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes two transformations.
|
||||
@@ -120,3 +122,5 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
Rotation2d m_rotation;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
#include "Transform2d.inc"
|
||||
|
||||
Reference in New Issue
Block a user