[wpimath] Add geometry classes for Rectangle2d and Ellipse2d (#6555)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Brendan Raykoff
2024-06-04 21:27:32 -04:00
committed by GitHub
parent afaf7e2c3f
commit 8def7b2222
41 changed files with 3042 additions and 26 deletions

View File

@@ -13,6 +13,7 @@
#include "frc/geometry/Rotation2d.h"
#include "units/length.h"
#include "units/math.h"
namespace frc {
@@ -66,7 +67,9 @@ class WPILIB_DLLEXPORT Translation2d {
*
* @return The distance between the two translations.
*/
units::meter_t Distance(const Translation2d& other) const;
constexpr units::meter_t Distance(const Translation2d& other) const {
return units::math::hypot(other.m_x - m_x, other.m_y - m_y);
}
/**
* Returns the X component of the translation.
@@ -123,6 +126,21 @@ class WPILIB_DLLEXPORT Translation2d {
*/
constexpr Translation2d RotateBy(const Rotation2d& other) const;
/**
* Rotates this translation around another translation in 2D space.
*
* <pre>
* [x_new] [rot.cos, -rot.sin][x - other.x] [other.x]
* [y_new] = [rot.sin, rot.cos][y - other.y] + [other.y]
* </pre>
*
* @param other The other translation to rotate around.
* @param rot The rotation to rotate the translation by.
* @return The new rotated translation.
*/
constexpr Translation2d RotateAround(const Translation2d& other,
const Rotation2d& rot) const;
/**
* Returns the sum of two translations in 2D space.
*
@@ -184,7 +202,7 @@ class WPILIB_DLLEXPORT Translation2d {
* @param other The other object.
* @return Whether the two objects are equal.
*/
bool operator==(const Translation2d& other) const;
constexpr bool operator==(const Translation2d& other) const;
/**
* Returns the nearest Translation2d from a collection of translations