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