mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
wpilibc: Add unit-safety to C++ geometry classes (#1811)
This commit is contained in:
committed by
Peter Johnson
parent
c07ac23532
commit
8f386f6bb3
@@ -7,17 +7,18 @@
|
||||
|
||||
#include "frc/geometry/Translation2d.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Translation2d::Translation2d(double x, double y) : m_x(x), m_y(y) {}
|
||||
Translation2d::Translation2d(units::meter_t x, units::meter_t y)
|
||||
: m_x(x), m_y(y) {}
|
||||
|
||||
double Translation2d::Distance(const Translation2d& other) const {
|
||||
return std::hypot(other.m_x - m_x, other.m_y - m_y);
|
||||
units::meter_t Translation2d::Distance(const Translation2d& other) const {
|
||||
return units::math::hypot(other.m_x - m_x, other.m_y - m_y);
|
||||
}
|
||||
|
||||
double Translation2d::Norm() const { return std::hypot(m_x, m_y); }
|
||||
units::meter_t Translation2d::Norm() const {
|
||||
return units::math::hypot(m_x, m_y);
|
||||
}
|
||||
|
||||
Translation2d Translation2d::RotateBy(const Rotation2d& other) const {
|
||||
return {m_x * other.Cos() - m_y * other.Sin(),
|
||||
|
||||
Reference in New Issue
Block a user