-
Notifications
You must be signed in to change notification settings - Fork 5
/
MixGreyscaleJzczhzTests.cs
98 lines (82 loc) · 4.88 KB
/
MixGreyscaleJzczhzTests.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 Jzazbz has no hue - shouldn't assume to start at red (0 degrees) when mixing
// greyscale Jzczhz has a hue so it should be used (it just can't be seen until there is some lightness & chroma)
public class MixGreyscaleJzczhzTests
{
[Test]
public void GreyscaleStartColour()
{
var jabBlack = new Unicolour(ColourSpace.Jzazbz, 0, 0, 0);
var jabWhite = new Unicolour(ColourSpace.Jzazbz, 1, 0, 0);
var jchBlack = new Unicolour(ColourSpace.Jzczhz, 0, 0.5, 180); // no lightness = black
var jchWhite = new Unicolour(ColourSpace.Jzczhz, 1, 0.5, 180); // full lightness = white
var green = new Unicolour(ColourSpace.Jzczhz, 0.5, 0.5, 120);
var fromJabBlack = jabBlack.Mix(green, ColourSpace.Jzczhz, premultiplyAlpha: false);
var fromJabWhite = jabWhite.Mix(green, ColourSpace.Jzczhz, premultiplyAlpha: false);
var fromJchBlack = jchBlack.Mix(green, ColourSpace.Jzczhz, premultiplyAlpha: false);
var fromJchWhite = jchWhite.Mix(green, ColourSpace.Jzczhz, premultiplyAlpha: false);
// greyscale mixes differently depending on the initial colour space
AssertTriplet(fromJabBlack.Jzczhz.Triplet, new(0.25, 0.25, 120));
AssertTriplet(fromJabWhite.Jzczhz.Triplet, new(0.75, 0.25, 120));
AssertTriplet(fromJchBlack.Jzczhz.Triplet, new(0.25, 0.5, 150));
AssertTriplet(fromJchWhite.Jzczhz.Triplet, new(0.75, 0.5, 150));
}
[Test]
public void GreyscaleEndColour()
{
var jabBlack = new Unicolour(ColourSpace.Jzazbz, 0, 0, 0);
var jabWhite = new Unicolour(ColourSpace.Jzazbz, 1, 0, 0);
var jchBlack = new Unicolour(ColourSpace.Jzczhz, 0, 0.5, 180); // no lightness = black
var jcWhite = new Unicolour(ColourSpace.Jzczhz, 1, 0.5, 180); // full lightness = white
var blue = new Unicolour(ColourSpace.Jzczhz, 0.5, 0.5, 240);
var toJzazbzBlack = blue.Mix(jabBlack, ColourSpace.Jzczhz, premultiplyAlpha: false);
var toJzazbzWhite = blue.Mix(jabWhite, ColourSpace.Jzczhz, premultiplyAlpha: false);
var toJzczhzBlack = blue.Mix(jchBlack, ColourSpace.Jzczhz, premultiplyAlpha: false);
var toJzczhzWhite = blue.Mix(jcWhite, ColourSpace.Jzczhz, premultiplyAlpha: false);
// greyscale mixes differently depending on the initial colour space
AssertTriplet(toJzazbzBlack.Jzczhz.Triplet, new(0.25, 0.25, 240));
AssertTriplet(toJzazbzWhite.Jzczhz.Triplet, new(0.75, 0.25, 240));
AssertTriplet(toJzczhzBlack.Jzczhz.Triplet, new(0.25, 0.5, 210));
AssertTriplet(toJzczhzWhite.Jzczhz.Triplet, new(0.75, 0.5, 210));
}
[Test]
public void GreyscaleBothJzazbzColours()
{
var black = new Unicolour(ColourSpace.Jzazbz, 0, 0, 0);
var white = new Unicolour(ColourSpace.Jzazbz, 1, 0, 0);
var grey = new Unicolour(ColourSpace.Jzazbz, 0.5, 0, 0);
var blackToWhite = black.Mix(white, ColourSpace.Jzczhz, premultiplyAlpha: false);
var blackToGrey = black.Mix(grey, ColourSpace.Jzczhz, premultiplyAlpha: false);
var whiteToGrey = white.Mix(grey, ColourSpace.Jzczhz, premultiplyAlpha: false);
AssertTriplet(blackToWhite.Jzazbz.Triplet, new(0.5, 0, 0));
AssertTriplet(blackToGrey.Jzazbz.Triplet, new(0.25, 0, 0));
AssertTriplet(whiteToGrey.Jzazbz.Triplet, new(0.75, 0, 0));
// colours created from Jzazbz therefore hue does not change
AssertTriplet(blackToWhite.Jzczhz.Triplet, new(0.5, 0, 0));
AssertTriplet(blackToGrey.Jzczhz.Triplet, new(0.25, 0, 0));
AssertTriplet(whiteToGrey.Jzczhz.Triplet, new(0.75, 0, 0));
}
[Test]
public void GreyscaleBothJzczhzColours()
{
var black = new Unicolour(ColourSpace.Jzczhz, 0, 0, 0);
var white = new Unicolour(ColourSpace.Jzczhz, 1, 0, 300);
var grey = new Unicolour(ColourSpace.Jzczhz, 0.5, 0, 100);
var blackToWhite = black.Mix(white, ColourSpace.Jzczhz, premultiplyAlpha: false);
var blackToGrey = black.Mix(grey, ColourSpace.Jzczhz, premultiplyAlpha: false);
var whiteToGrey = white.Mix(grey, ColourSpace.Jzczhz, premultiplyAlpha: false);
AssertTriplet(blackToWhite.Jzazbz.Triplet, new(0.5, 0, 0));
AssertTriplet(blackToGrey.Jzazbz.Triplet, new(0.25, 0, 0));
AssertTriplet(whiteToGrey.Jzazbz.Triplet, new(0.75, 0, 0));
// colours created from Jzczhz therefore hue changes
AssertTriplet(blackToWhite.Jzczhz.Triplet, new(0.5, 0, 330));
AssertTriplet(blackToGrey.Jzczhz.Triplet, new(0.25, 0, 50));
AssertTriplet(whiteToGrey.Jzczhz.Triplet, new(0.75, 0, 20));
}
private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected)
{
TestUtils.AssertTriplet(actual, expected, TestUtils.MixTolerance);
}
}