[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

@@ -14,8 +14,6 @@ import java.util.Objects;
*/
@SuppressWarnings("MemberName")
public class Color {
private static final double kPrecision = Math.pow(2, -12);
public final double red;
public final double green;
public final double blue;
@@ -178,8 +176,7 @@ public class Color {
}
private static double roundAndClamp(double value) {
final var rounded = Math.round((value + kPrecision / 2) / kPrecision) * kPrecision;
return MathUtil.clamp(rounded, 0.0, 1.0);
return MathUtil.clamp(Math.ceil(value * (1 << 12)) / (1 << 12), 0.0, 1.0);
}
/*