diff --git a/Assets/Scripts/ServerShared/ColorMath.cs b/Assets/Scripts/ServerShared/ColorMath.cs index 26ea704a7..f91ab9ad0 100644 --- a/Assets/Scripts/ServerShared/ColorMath.cs +++ b/Assets/Scripts/ServerShared/ColorMath.cs @@ -41,7 +41,7 @@ public static class ColorMath public static float3 RgbToHcv(in float3 rgb) { // Based on work by Sam Hocevar and Emil Persson - float4 p = (rgb.y < rgb.z) ? float4(rgb.zy, -1.0f, 2.0f/3.0f) : float4(rgb.zy, 0.0f, -1.0f/3.0f); + float4 p = (rgb.y < rgb.z) ? float4(rgb.zy, -1.0f, 2.0f/3.0f) : float4(rgb.yz, 0.0f, -1.0f/3.0f); float4 q = (rgb.x < p.x) ? float4(p.xyw, rgb.x) : float4(rgb.x, p.yzx); float c = q.x - min(q.w, q.y); float h = abs((q.w - q.y) / (6 * c + Epsilon) + q.z); diff --git a/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs b/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs index e94deab92..fc42536cc 100644 --- a/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs +++ b/tests/Aetheria.Shared.Tests/SunsNeverGreenTests.cs @@ -53,6 +53,18 @@ public sealed class SunsNeverGreenTests : IDisposable Assert.False(ColorMath.HueInBand(degrees * Degree, settings.SunHueExcludedStart, settings.SunHueExcludedEnd)); } + // The hues below are read back from RGB the generator wrote, so the reader must invert the writer. + [Fact] + public void ReadingHueBackFromRgbInvertsWritingIt() + { + for (var degrees = 5; degrees < 360; degrees += 5) + foreach (var value in new[] { .5f, 1f }) + { + var rgb = ColorMath.HsvToRgb(new float3(degrees * Degree, .75f, value)); + Assert.Equal(degrees * Degree, ColorMath.RgbToHsv(rgb).x, 4); + } + } + [Fact] public void TheDrawMapsOntoTheWholeAllowedArcAndNothingElse() {