[wpilib] Fix precision issue in Color round-and-clamp (#6100)

This commit is contained in:
Tyler Veness
2023-12-26 13:38:15 -08:00
committed by GitHub
parent 7aa9ad44b8
commit 795d4be9fd
4 changed files with 36 additions and 20 deletions

View File

@@ -10,6 +10,7 @@
#include <string_view>
#include <fmt/core.h>
#include <gcem.hpp>
#include <wpi/StringExtras.h>
#include <wpi/ct_string.h>
@@ -868,12 +869,8 @@ class Color {
double blue = 0.0;
private:
static constexpr double kPrecision = 1.0 / (1 << 12);
static constexpr double roundAndClamp(double value) {
const auto rounded =
(static_cast<int>(value / kPrecision) + 0.5) * kPrecision;
return std::clamp(rounded, 0.0, 1.0);
return std::clamp(gcem::ceil(value * (1 << 12)) / (1 << 12), 0.0, 1.0);
}
};