mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// 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 <wpi/numbers>
|
||||
#include <numbers>
|
||||
|
||||
#include "frc/geometry/Quaternion.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <wpi/numbers>
|
||||
#include <numbers>
|
||||
|
||||
#include "frc/geometry/Rotation2d.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -12,8 +11,8 @@
|
||||
using namespace frc;
|
||||
|
||||
TEST(Rotation2dTest, RadiansToDegrees) {
|
||||
const Rotation2d rot1{units::radian_t{wpi::numbers::pi / 3.0}};
|
||||
const Rotation2d rot2{units::radian_t{wpi::numbers::pi / 4.0}};
|
||||
const Rotation2d rot1{units::radian_t{std::numbers::pi / 3.0}};
|
||||
const Rotation2d rot2{units::radian_t{std::numbers::pi / 4.0}};
|
||||
|
||||
EXPECT_DOUBLE_EQ(60.0, rot1.Degrees().value());
|
||||
EXPECT_DOUBLE_EQ(45.0, rot2.Degrees().value());
|
||||
@@ -23,15 +22,15 @@ TEST(Rotation2dTest, DegreesToRadians) {
|
||||
const auto rot1 = Rotation2d{45_deg};
|
||||
const auto rot2 = Rotation2d{30_deg};
|
||||
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 4.0, rot1.Radians().value());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 6.0, rot2.Radians().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 4.0, rot1.Radians().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 6.0, rot2.Radians().value());
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, RotateByFromZero) {
|
||||
const Rotation2d zero;
|
||||
auto rotated = zero + Rotation2d{90_deg};
|
||||
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 2.0, rotated.Radians().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 2.0, rotated.Radians().value());
|
||||
EXPECT_DOUBLE_EQ(90.0, rotated.Degrees().value());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
||||
#include <wpi/MathExtras.h>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/EigenCore.h"
|
||||
#include "frc/geometry/Rotation3d.h"
|
||||
@@ -15,18 +15,18 @@ using namespace frc;
|
||||
|
||||
TEST(Rotation3dTest, InitAxisAngleAndRollPitchYaw) {
|
||||
const Eigen::Vector3d xAxis{1.0, 0.0, 0.0};
|
||||
const Rotation3d rot1{xAxis, units::radian_t{wpi::numbers::pi / 3}};
|
||||
const Rotation3d rot2{units::radian_t{wpi::numbers::pi / 3}, 0_rad, 0_rad};
|
||||
const Rotation3d rot1{xAxis, units::radian_t{std::numbers::pi / 3}};
|
||||
const Rotation3d rot2{units::radian_t{std::numbers::pi / 3}, 0_rad, 0_rad};
|
||||
EXPECT_EQ(rot1, rot2);
|
||||
|
||||
const Eigen::Vector3d yAxis{0.0, 1.0, 0.0};
|
||||
const Rotation3d rot3{yAxis, units::radian_t{wpi::numbers::pi / 3}};
|
||||
const Rotation3d rot4{0_rad, units::radian_t{wpi::numbers::pi / 3}, 0_rad};
|
||||
const Rotation3d rot3{yAxis, units::radian_t{std::numbers::pi / 3}};
|
||||
const Rotation3d rot4{0_rad, units::radian_t{std::numbers::pi / 3}, 0_rad};
|
||||
EXPECT_EQ(rot3, rot4);
|
||||
|
||||
const Eigen::Vector3d zAxis{0.0, 0.0, 1.0};
|
||||
const Rotation3d rot5{zAxis, units::radian_t{wpi::numbers::pi / 3}};
|
||||
const Rotation3d rot6{0_rad, 0_rad, units::radian_t{wpi::numbers::pi / 3}};
|
||||
const Rotation3d rot5{zAxis, units::radian_t{std::numbers::pi / 3}};
|
||||
const Rotation3d rot6{0_rad, 0_rad, units::radian_t{std::numbers::pi / 3}};
|
||||
EXPECT_EQ(rot5, rot6);
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ TEST(Rotation3dTest, InitTwoVector) {
|
||||
|
||||
// 90 degree CW rotation around y-axis
|
||||
const Rotation3d rot1{xAxis, zAxis};
|
||||
const Rotation3d expected1{yAxis, units::radian_t{-wpi::numbers::pi / 2.0}};
|
||||
const Rotation3d expected1{yAxis, units::radian_t{-std::numbers::pi / 2.0}};
|
||||
EXPECT_EQ(expected1, rot1);
|
||||
|
||||
// 45 degree CCW rotation around z-axis
|
||||
const Rotation3d rot2{xAxis, Eigen::Vector3d{1.0, 1.0, 0.0}};
|
||||
const Rotation3d expected2{zAxis, units::radian_t{wpi::numbers::pi / 4.0}};
|
||||
const Rotation3d expected2{zAxis, units::radian_t{std::numbers::pi / 4.0}};
|
||||
EXPECT_EQ(expected2, rot2);
|
||||
|
||||
// 0 degree rotation of x-axes
|
||||
@@ -107,12 +107,12 @@ TEST(Rotation3dTest, InitTwoVector) {
|
||||
TEST(Rotation3dTest, RadiansToDegrees) {
|
||||
const Eigen::Vector3d zAxis{0.0, 0.0, 1.0};
|
||||
|
||||
const Rotation3d rot1{zAxis, units::radian_t{wpi::numbers::pi / 3}};
|
||||
const Rotation3d rot1{zAxis, units::radian_t{std::numbers::pi / 3}};
|
||||
EXPECT_DOUBLE_EQ(0.0, rot1.X().value());
|
||||
EXPECT_DOUBLE_EQ(0.0, rot1.Y().value());
|
||||
EXPECT_DOUBLE_EQ(units::radian_t{60_deg}.value(), rot1.Z().value());
|
||||
|
||||
const Rotation3d rot2{zAxis, units::radian_t{wpi::numbers::pi / 4}};
|
||||
const Rotation3d rot2{zAxis, units::radian_t{std::numbers::pi / 4}};
|
||||
EXPECT_DOUBLE_EQ(0.0, rot2.X().value());
|
||||
EXPECT_DOUBLE_EQ(0.0, rot2.Y().value());
|
||||
EXPECT_DOUBLE_EQ(units::radian_t{45_deg}.value(), rot2.Z().value());
|
||||
@@ -124,12 +124,12 @@ TEST(Rotation3dTest, DegreesToRadians) {
|
||||
const auto rot1 = Rotation3d{zAxis, 45_deg};
|
||||
EXPECT_DOUBLE_EQ(0.0, rot1.X().value());
|
||||
EXPECT_DOUBLE_EQ(0.0, rot1.Y().value());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 4.0, rot1.Z().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 4.0, rot1.Z().value());
|
||||
|
||||
const auto rot2 = Rotation3d{zAxis, 30_deg};
|
||||
EXPECT_DOUBLE_EQ(0.0, rot2.X().value());
|
||||
EXPECT_DOUBLE_EQ(0.0, rot2.Y().value());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 6.0, rot2.Z().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 6.0, rot2.Z().value());
|
||||
}
|
||||
|
||||
TEST(Rotation3dTest, RotationLoop) {
|
||||
@@ -228,15 +228,15 @@ TEST(Rotation3dTest, AxisAngle) {
|
||||
|
||||
Rotation3d rot1{xAxis, 90_deg};
|
||||
EXPECT_EQ(xAxis, rot1.Axis());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 2.0, rot1.Angle().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 2.0, rot1.Angle().value());
|
||||
|
||||
Rotation3d rot2{yAxis, 45_deg};
|
||||
EXPECT_EQ(yAxis, rot2.Axis());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 4.0, rot2.Angle().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 4.0, rot2.Angle().value());
|
||||
|
||||
Rotation3d rot3{zAxis, 60_deg};
|
||||
EXPECT_EQ(zAxis, rot3.Axis());
|
||||
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 3.0, rot3.Angle().value());
|
||||
EXPECT_DOUBLE_EQ(std::numbers::pi / 3.0, rot3.Angle().value());
|
||||
}
|
||||
|
||||
TEST(Rotation3dTest, ToRotation2d) {
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <wpi/numbers>
|
||||
#include <numbers>
|
||||
|
||||
#include "frc/geometry/Pose2d.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -21,8 +20,8 @@ TEST(Twist2dTest, Straight) {
|
||||
}
|
||||
|
||||
TEST(Twist2dTest, QuarterCircle) {
|
||||
const Twist2d quarterCircle{5_m / 2.0 * wpi::numbers::pi, 0_m,
|
||||
units::radian_t{wpi::numbers::pi / 2.0}};
|
||||
const Twist2d quarterCircle{5_m / 2.0 * std::numbers::pi, 0_m,
|
||||
units::radian_t{std::numbers::pi / 2.0}};
|
||||
const auto quarterCirclePose = Pose2d{}.Exp(quarterCircle);
|
||||
|
||||
EXPECT_DOUBLE_EQ(5.0, quarterCirclePose.X().value());
|
||||
@@ -57,8 +56,8 @@ TEST(Twist2dTest, Pose2dLog) {
|
||||
|
||||
const auto twist = start.Log(end);
|
||||
|
||||
Twist2d expected{units::meter_t{5.0 / 2.0 * wpi::numbers::pi}, 0_m,
|
||||
units::radian_t{wpi::numbers::pi / 2.0}};
|
||||
Twist2d expected{units::meter_t{5.0 / 2.0 * std::numbers::pi}, 0_m,
|
||||
units::radian_t{std::numbers::pi / 2.0}};
|
||||
EXPECT_EQ(expected, twist);
|
||||
|
||||
// Make sure computed twist gives back original end pose
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <wpi/numbers>
|
||||
#include <numbers>
|
||||
|
||||
#include "frc/geometry/Pose3d.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -39,8 +38,8 @@ TEST(Twist3dTest, QuarterCircle) {
|
||||
Eigen::Vector3d zAxis{0.0, 0.0, 1.0};
|
||||
|
||||
const Twist3d quarterCircle{
|
||||
5_m / 2.0 * wpi::numbers::pi, 0_m, 0_m, 0_rad, 0_rad,
|
||||
units::radian_t{wpi::numbers::pi / 2.0}};
|
||||
5_m / 2.0 * std::numbers::pi, 0_m, 0_m, 0_rad, 0_rad,
|
||||
units::radian_t{std::numbers::pi / 2.0}};
|
||||
const auto quarterCirclePose = Pose3d{}.Exp(quarterCircle);
|
||||
|
||||
Pose3d expected{5_m, 5_m, 0_m, Rotation3d{zAxis, 90_deg}};
|
||||
@@ -73,7 +72,7 @@ TEST(Twist3dTest, Pose3dLogX) {
|
||||
|
||||
const auto twist = start.Log(end);
|
||||
|
||||
Twist3d expected{0_m, units::meter_t{5.0 / 2.0 * wpi::numbers::pi},
|
||||
Twist3d expected{0_m, units::meter_t{5.0 / 2.0 * std::numbers::pi},
|
||||
0_m, 90_deg,
|
||||
0_deg, 0_deg};
|
||||
EXPECT_EQ(expected, twist);
|
||||
@@ -89,7 +88,7 @@ TEST(Twist3dTest, Pose3dLogY) {
|
||||
|
||||
const auto twist = start.Log(end);
|
||||
|
||||
Twist3d expected{0_m, 0_m, units::meter_t{5.0 / 2.0 * wpi::numbers::pi},
|
||||
Twist3d expected{0_m, 0_m, units::meter_t{5.0 / 2.0 * std::numbers::pi},
|
||||
0_deg, 90_deg, 0_deg};
|
||||
EXPECT_EQ(expected, twist);
|
||||
|
||||
@@ -104,7 +103,7 @@ TEST(Twist3dTest, Pose3dLogZ) {
|
||||
|
||||
const auto twist = start.Log(end);
|
||||
|
||||
Twist3d expected{units::meter_t{5.0 / 2.0 * wpi::numbers::pi},
|
||||
Twist3d expected{units::meter_t{5.0 / 2.0 * std::numbers::pi},
|
||||
0_m,
|
||||
0_m,
|
||||
0_deg,
|
||||
|
||||
Reference in New Issue
Block a user