mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] Fix precision issue in Color round-and-clamp (#6100)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user