mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpimath] Add geometry classes for Rectangle2d and Ellipse2d (#6555)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// 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/struct/Ellipse2dStruct.h"
|
||||
|
||||
namespace {
|
||||
constexpr size_t kCenterOff = 0;
|
||||
constexpr size_t kXSemiAxisOff = kCenterOff + wpi::GetStructSize<frc::Pose2d>();
|
||||
constexpr size_t kYSemiAxisOff = kXSemiAxisOff + 8;
|
||||
} // namespace
|
||||
|
||||
using StructType = wpi::Struct<frc::Ellipse2d>;
|
||||
|
||||
frc::Ellipse2d StructType::Unpack(std::span<const uint8_t> data) {
|
||||
return frc::Ellipse2d{
|
||||
wpi::UnpackStruct<frc::Pose2d, kCenterOff>(data),
|
||||
units::meter_t{wpi::UnpackStruct<double, kXSemiAxisOff>(data)},
|
||||
units::meter_t{wpi::UnpackStruct<double, kYSemiAxisOff>(data)},
|
||||
};
|
||||
}
|
||||
|
||||
void StructType::Pack(std::span<uint8_t> data, const frc::Ellipse2d& value) {
|
||||
wpi::PackStruct<kCenterOff>(data, value.Center());
|
||||
wpi::PackStruct<kXSemiAxisOff>(data, value.XSemiAxis().value());
|
||||
wpi::PackStruct<kYSemiAxisOff>(data, value.YSemiAxis().value());
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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/struct/Rectangle2dStruct.h"
|
||||
|
||||
namespace {
|
||||
constexpr size_t kCenterOff = 0;
|
||||
constexpr size_t kXWidthOff = kCenterOff + wpi::GetStructSize<frc::Pose2d>();
|
||||
constexpr size_t kYWidthOff = kXWidthOff + 8;
|
||||
} // namespace
|
||||
|
||||
using StructType = wpi::Struct<frc::Rectangle2d>;
|
||||
|
||||
frc::Rectangle2d StructType::Unpack(std::span<const uint8_t> data) {
|
||||
return frc::Rectangle2d{
|
||||
wpi::UnpackStruct<frc::Pose2d, kCenterOff>(data),
|
||||
units::meter_t{wpi::UnpackStruct<double, kXWidthOff>(data)},
|
||||
units::meter_t{wpi::UnpackStruct<double, kYWidthOff>(data)},
|
||||
};
|
||||
}
|
||||
|
||||
void StructType::Pack(std::span<uint8_t> data, const frc::Rectangle2d& value) {
|
||||
wpi::PackStruct<kCenterOff>(data, value.Center());
|
||||
wpi::PackStruct<kXWidthOff>(data, value.XWidth().value());
|
||||
wpi::PackStruct<kYWidthOff>(data, value.YWidth().value());
|
||||
}
|
||||
Reference in New Issue
Block a user