-
Notifications
You must be signed in to change notification settings - Fork 5
/
MixGreyscaleHwbTests.cs
98 lines (82 loc) · 4.75 KB
/
MixGreyscaleHwbTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using NUnit.Framework;
using Wacton.Unicolour.Tests.Utils;
namespace Wacton.Unicolour.Tests;
// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when mixing
// greyscale HWB has a hue so it should be used (it just can't be seen while whiteness + blackness >= 1)
public class MixGreyscaleHwbTests
{
[Test]
public void GreyscaleStartColour()
{
var rgbBlack = new Unicolour(ColourSpace.Rgb255, 0, 0, 0);
var rgbWhite = new Unicolour(ColourSpace.Rgb255, 255, 255, 255);
var hwbBlack = new Unicolour(ColourSpace.Hwb, 180, 0, 1); // full blackness = black
var hwbWhite = new Unicolour(ColourSpace.Hwb, 180, 1, 0); // full whiteness = white
var green = new Unicolour(ColourSpace.Hwb, 120, 0, 0);
var fromRgbBlack = rgbBlack.Mix(green, ColourSpace.Hwb, premultiplyAlpha: false);
var fromRgbWhite = rgbWhite.Mix(green, ColourSpace.Hwb, premultiplyAlpha: false);
var fromHwbBlack = hwbBlack.Mix(green, ColourSpace.Hwb, premultiplyAlpha: false);
var fromHwbWhite = hwbWhite.Mix(green, ColourSpace.Hwb, premultiplyAlpha: false);
// greyscale mixes differently depending on the initial colour space
AssertTriplet(fromRgbBlack.Hwb.Triplet, new(120, 0, 0.5));
AssertTriplet(fromRgbWhite.Hwb.Triplet, new(120, 0.5, 0));
AssertTriplet(fromHwbBlack.Hwb.Triplet, new(150, 0, 0.5));
AssertTriplet(fromHwbWhite.Hwb.Triplet, new(150, 0.5, 0));
}
[Test]
public void GreyscaleEndColour()
{
var rgbBlack = new Unicolour(ColourSpace.Rgb255, 0, 0, 0);
var rgbWhite = new Unicolour(ColourSpace.Rgb255, 255, 255, 255);
var hwbBlack = new Unicolour(ColourSpace.Hwb, 180, 0, 1); // full blackness = black
var hwbWhite = new Unicolour(ColourSpace.Hwb, 180, 1, 0); // full whiteness = white
var blue = new Unicolour(ColourSpace.Hwb, 240, 0, 0);
var toRgbBlack = blue.Mix(rgbBlack, ColourSpace.Hwb, premultiplyAlpha: false);
var toRgbWhite = blue.Mix(rgbWhite, ColourSpace.Hwb, premultiplyAlpha: false);
var toHwbBlack = blue.Mix(hwbBlack, ColourSpace.Hwb, premultiplyAlpha: false);
var toHwbWhite = blue.Mix(hwbWhite, ColourSpace.Hwb, premultiplyAlpha: false);
// greyscale mixes differently depending on the initial colour space
AssertTriplet(toRgbBlack.Hwb.Triplet, new(240, 0, 0.5));
AssertTriplet(toRgbWhite.Hwb.Triplet, new(240, 0.5, 0));
AssertTriplet(toHwbBlack.Hwb.Triplet, new(210, 0, 0.5));
AssertTriplet(toHwbWhite.Hwb.Triplet, new(210, 0.5, 0));
}
[Test]
public void GreyscaleBothRgbColours()
{
var black = new Unicolour(ColourSpace.Rgb, 0.0, 0.0, 0.0);
var white = new Unicolour(ColourSpace.Rgb, 1.0, 1.0, 1.0);
var grey = new Unicolour(ColourSpace.Rgb, 0.5, 0.5, 0.5);
var blackToWhite = black.Mix(white, ColourSpace.Hwb, premultiplyAlpha: false);
var blackToGrey = black.Mix(grey, ColourSpace.Hwb, premultiplyAlpha: false);
var whiteToGrey = white.Mix(grey, ColourSpace.Hwb, premultiplyAlpha: false);
AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5));
AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25));
AssertTriplet(whiteToGrey.Rgb.Triplet, new(0.75, 0.75, 0.75));
// colours created from RGB therefore hue does not change
AssertTriplet(blackToWhite.Hwb.Triplet, new(0, 0.5, 0.5));
AssertTriplet(blackToGrey.Hwb.Triplet, new(0, 0.25, 0.75));
AssertTriplet(whiteToGrey.Hwb.Triplet, new(0, 0.75, 0.25));
}
[Test]
public void GreyscaleBothHwbColours()
{
var black = new Unicolour(ColourSpace.Hwb, 0, 0, 1.0);
var white = new Unicolour(ColourSpace.Hwb, 300, 1.0, 0);
var grey = new Unicolour(ColourSpace.Hwb, 100, 0.5, 0.5);
var blackToWhite = black.Mix(white, ColourSpace.Hwb, premultiplyAlpha: false);
var blackToGrey = black.Mix(grey, ColourSpace.Hwb, premultiplyAlpha: false);
var whiteToGrey = white.Mix(grey, ColourSpace.Hwb, premultiplyAlpha: false);
AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5));
AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25));
AssertTriplet(whiteToGrey.Rgb.Triplet, new(0.75, 0.75, 0.75));
// colours created from hwb therefore hue changes
AssertTriplet(blackToWhite.Hwb.Triplet, new(330, 0.5, 0.5));
AssertTriplet(blackToGrey.Hwb.Triplet, new(50, 0.25, 0.75));
AssertTriplet(whiteToGrey.Hwb.Triplet, new(20, 0.75, 0.25));
}
private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected)
{
TestUtils.AssertTriplet(actual, expected, TestUtils.MixTolerance);
}
}