2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-07-24 02:57:39 -04:00
|
|
|
|
|
|
|
|
#include "frc/geometry/Translation2d.h"
|
|
|
|
|
|
2019-11-02 13:35:03 -05:00
|
|
|
#include <wpi/json.h>
|
|
|
|
|
|
2020-08-06 23:57:39 -07:00
|
|
|
#include "units/math.h"
|
|
|
|
|
|
2019-07-24 02:57:39 -04:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2019-08-17 01:00:33 -04:00
|
|
|
units::meter_t Translation2d::Distance(const Translation2d& other) const {
|
|
|
|
|
return units::math::hypot(other.m_x - m_x, other.m_y - m_y);
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-17 01:00:33 -04:00
|
|
|
units::meter_t Translation2d::Norm() const {
|
|
|
|
|
return units::math::hypot(m_x, m_y);
|
|
|
|
|
}
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2019-09-08 14:20:26 -04:00
|
|
|
bool Translation2d::operator==(const Translation2d& other) const {
|
|
|
|
|
return units::math::abs(m_x - other.m_x) < 1E-9_m &&
|
|
|
|
|
units::math::abs(m_y - other.m_y) < 1E-9_m;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 13:35:03 -05:00
|
|
|
void frc::to_json(wpi::json& json, const Translation2d& translation) {
|
2021-10-25 08:58:12 -07:00
|
|
|
json =
|
|
|
|
|
wpi::json{{"x", translation.X().value()}, {"y", translation.Y().value()}};
|
2019-11-02 13:35:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void frc::from_json(const wpi::json& json, Translation2d& translation) {
|
|
|
|
|
translation = Translation2d{units::meter_t{json.at("x").get<double>()},
|
|
|
|
|
units::meter_t{json.at("y").get<double>()}};
|
|
|
|
|
}
|