mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpimath] Merge .inc files into headers (#7209)
Splitting the files didn't help readability or save compilation time and it confused contributors. Merging them is also in line with how C++ modules will be written.
This commit is contained in:
@@ -24,13 +24,28 @@ struct wpi::Struct<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>> {
|
||||
static constexpr std::string_view GetSchema() { return kSchema; }
|
||||
|
||||
static frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> Unpack(
|
||||
std::span<const uint8_t> data);
|
||||
std::span<const uint8_t> data) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Rows * Cols> mat_data =
|
||||
wpi::UnpackStructArray<double, kDataOff, Rows * Cols>(data);
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> mat;
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
mat(i) = mat_data[i];
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
static void Pack(
|
||||
std::span<uint8_t> data,
|
||||
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value);
|
||||
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Rows * Cols> mat_data(wpi::empty_array);
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
mat_data[i] = value(i);
|
||||
}
|
||||
wpi::PackStructArray<kDataOff, Rows * Cols>(data, mat_data);
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(wpi::StructSerializable<frc::Matrixd<1, 2>>);
|
||||
static_assert(wpi::StructSerializable<frc::Matrixd<3, 3>>);
|
||||
|
||||
#include "frc/struct/MatrixStruct.inc"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/struct/MatrixStruct.h"
|
||||
|
||||
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||
requires(Cols != 1)
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>
|
||||
wpi::Struct<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Unpack(
|
||||
std::span<const uint8_t> data) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Rows * Cols> mat_data =
|
||||
wpi::UnpackStructArray<double, kDataOff, Rows * Cols>(data);
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> mat;
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
mat(i) = mat_data[i];
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||
requires(Cols != 1)
|
||||
void wpi::Struct<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Pack(
|
||||
std::span<uint8_t> data,
|
||||
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Rows * Cols> mat_data(wpi::empty_array);
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
mat_data[i] = value(i);
|
||||
}
|
||||
wpi::PackStructArray<kDataOff, Rows * Cols>(data, mat_data);
|
||||
}
|
||||
@@ -21,13 +21,28 @@ struct wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>> {
|
||||
static constexpr std::string_view GetSchema() { return kSchema; }
|
||||
|
||||
static frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> Unpack(
|
||||
std::span<const uint8_t> data);
|
||||
std::span<const uint8_t> data) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Size> vec_data =
|
||||
wpi::UnpackStructArray<double, kDataOff, Size>(data);
|
||||
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> vec;
|
||||
for (int i = 0; i < Size; i++) {
|
||||
vec(i) = vec_data[i];
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
static void Pack(
|
||||
std::span<uint8_t> data,
|
||||
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value);
|
||||
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Size> vec_data(wpi::empty_array);
|
||||
for (int i = 0; i < Size; i++) {
|
||||
vec_data[i] = value(i);
|
||||
}
|
||||
wpi::PackStructArray<kDataOff, Size>(data, vec_data);
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(wpi::StructSerializable<frc::Vectord<1>>);
|
||||
static_assert(wpi::StructSerializable<frc::Vectord<3>>);
|
||||
|
||||
#include "frc/struct/VectorStruct.inc"
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/struct/VectorStruct.h"
|
||||
|
||||
template <int Size, int Options, int MaxRows, int MaxCols>
|
||||
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>
|
||||
wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Unpack(
|
||||
std::span<const uint8_t> data) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Size> vec_data =
|
||||
wpi::UnpackStructArray<double, kDataOff, Size>(data);
|
||||
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> vec;
|
||||
for (int i = 0; i < Size; i++) {
|
||||
vec(i) = vec_data[i];
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
template <int Size, int Options, int MaxRows, int MaxCols>
|
||||
void wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Pack(
|
||||
std::span<uint8_t> data,
|
||||
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value) {
|
||||
constexpr size_t kDataOff = 0;
|
||||
wpi::array<double, Size> vec_data(wpi::empty_array);
|
||||
for (int i = 0; i < Size; i++) {
|
||||
vec_data[i] = value(i);
|
||||
}
|
||||
wpi::PackStructArray<kDataOff, Size>(data, vec_data);
|
||||
}
|
||||
Reference in New Issue
Block a user