Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit e7838e6

Browse files
committed
fix colors calculate error
1 parent a4c30c3 commit e7838e6

File tree

1 file changed

+12
-12
lines changed
  • com.unity.uiwidgets/Runtime/painting

1 file changed

+12
-12
lines changed

com.unity.uiwidgets/Runtime/painting/colors.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ internal static float _getHue(float red, float green, float blue, float max, flo
1212
if (max == 0.0f || delta == 0.0f) {
1313
hue = 0.0f;
1414
}
15-
else if (max == red) {
15+
else if (Math.Abs(max - red) < foundation_.precisionErrorTolerance) {
1616
hue = 60.0f * (((green - blue) / delta) % 6);
1717
}
18-
else if (max == green) {
18+
else if (Math.Abs(max - green) < foundation_.precisionErrorTolerance) {
1919
hue = 60.0f * (((blue - red) / delta) + 2);
2020
}
21-
else if (max == blue) {
21+
else if (Math.Abs(max - blue) < foundation_.precisionErrorTolerance) {
2222
hue = 60.0f * (((red - green) / delta) + 4);
2323
}
2424

@@ -92,14 +92,14 @@ public static HSVColor fromAHSV(float alpha, float hue, float saturation, float
9292
}
9393

9494
public static HSVColor fromColor(Color color) {
95-
float red = color.red / 0xFF;
96-
float green = color.green / 0xFF;
97-
float blue = color.blue / 0xFF;
95+
float red = (float)color.red / 0xFF;
96+
float green = (float)color.green / 0xFF;
97+
float blue = (float)color.blue / 0xFF;
9898

9999
float max = Mathf.Max(red, Mathf.Max(green, blue));
100100
float min = Mathf.Min(red, Mathf.Min(green, blue));
101101
float delta = max - min;
102-
float alpha = color.alpha / 0xFF;
102+
float alpha = (float)color.alpha / 0xFF;
103103
float hue = painting_._getHue(red, green, blue, max, delta);
104104
float saturation = max == 0.0f ? 0.0f : delta / max;
105105

@@ -164,18 +164,18 @@ public static HSLColor fromAHSL(float alpha, float hue, float saturation, float
164164
}
165165

166166
public static HSLColor fromColor(Color color) {
167-
float red = color.red / 0xFF;
168-
float green = color.green / 0xFF;
169-
float blue = color.blue / 0xFF;
167+
float red = (float)color.red / 0xFF;
168+
float green = (float)color.green / 0xFF;
169+
float blue = (float)color.blue / 0xFF;
170170

171171
float max = Mathf.Max(red, Mathf.Max(green, blue));
172172
float min = Mathf.Min(red, Mathf.Min(green, blue));
173173
float delta = max - min;
174174

175-
float alpha = color.alpha / 0xFF;
175+
float alpha = (float)color.alpha / 0xFF;
176176
float hue = painting_._getHue(red, green, blue, max, delta);
177177
float lightness = (max + min) / 2.0f;
178-
float saturation = lightness == 1.0f
178+
float saturation = Math.Abs(lightness - 1.0f) < foundation_.precisionErrorTolerance
179179
? 0.0f
180180
: ((delta / (1.0f - Mathf.Abs(2.0f * lightness - 1.0f))).clamp(0.0f, 1.0f));
181181
return HSLColor.fromAHSL(alpha, hue, saturation, lightness);

0 commit comments

Comments
 (0)