2024-06-04 21:27:32 -04: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.
|
|
|
|
|
|
|
|
|
|
#include "frc/geometry/proto/Ellipse2dProto.h"
|
|
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
#include <wpi/protobuf/ProtobufCallbacks.h>
|
2024-06-28 09:28:39 -04:00
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
#include "wpimath/protobuf/geometry2d.npb.h"
|
2024-06-04 21:27:32 -04:00
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
std::optional<frc::Ellipse2d> wpi::Protobuf<frc::Ellipse2d>::Unpack(
|
|
|
|
|
InputStream& stream) {
|
|
|
|
|
wpi::UnpackCallback<frc::Pose2d> pose;
|
|
|
|
|
wpi_proto_ProtobufEllipse2d msg{
|
|
|
|
|
.center = pose.Callback(),
|
|
|
|
|
.xSemiAxis = 0,
|
|
|
|
|
.ySemiAxis = 0,
|
|
|
|
|
};
|
|
|
|
|
if (!stream.Decode(msg)) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto ipose = pose.Items();
|
|
|
|
|
|
|
|
|
|
if (ipose.empty()) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2024-06-04 21:27:32 -04:00
|
|
|
|
|
|
|
|
return frc::Ellipse2d{
|
2024-11-07 22:42:50 -08:00
|
|
|
ipose[0],
|
|
|
|
|
units::meter_t{msg.xSemiAxis},
|
|
|
|
|
units::meter_t{msg.ySemiAxis},
|
2024-06-04 21:27:32 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
bool wpi::Protobuf<frc::Ellipse2d>::Pack(OutputStream& stream,
|
2024-06-04 21:27:32 -04:00
|
|
|
const frc::Ellipse2d& value) {
|
2024-11-07 22:42:50 -08:00
|
|
|
wpi::PackCallback pose{&value.Center()};
|
|
|
|
|
wpi_proto_ProtobufEllipse2d msg{
|
|
|
|
|
.center = pose.Callback(),
|
|
|
|
|
.xSemiAxis = value.XSemiAxis().value(),
|
|
|
|
|
.ySemiAxis = value.YSemiAxis().value(),
|
|
|
|
|
};
|
|
|
|
|
return stream.Encode(msg);
|
2024-06-04 21:27:32 -04:00
|
|
|
}
|