From 82c5671866d2cd294b2a009933b0b84113d1e3df Mon Sep 17 00:00:00 2001 From: Wacton Date: Tue, 31 Oct 2023 19:13:35 +0000 Subject: [PATCH] Rename interpolate to mix --- README.md | 92 ++++++------- Unicolour.Example/Gradient.cs | 10 +- Unicolour.Example/Program.cs | 52 ++++---- Unicolour.Tests/InterpolateCam02Tests.cs | 88 ------------- Unicolour.Tests/InterpolateCam16Tests.cs | 88 ------------- Unicolour.Tests/InterpolateHctTests.cs | 124 ------------------ Unicolour.Tests/InterpolateHpluvTests.cs | 124 ------------------ Unicolour.Tests/InterpolateHsbTests.cs | 124 ------------------ Unicolour.Tests/InterpolateHslTests.cs | 124 ------------------ Unicolour.Tests/InterpolateHsluvTests.cs | 124 ------------------ Unicolour.Tests/InterpolateHwbTests.cs | 124 ------------------ Unicolour.Tests/InterpolateIctcpTests.cs | 88 ------------- Unicolour.Tests/InterpolateJzazbzTests.cs | 88 ------------- Unicolour.Tests/InterpolateJzczhzTests.cs | 124 ------------------ Unicolour.Tests/InterpolateLabTests.cs | 88 ------------- Unicolour.Tests/InterpolateLchabTests.cs | 124 ------------------ Unicolour.Tests/InterpolateLchuvTests.cs | 124 ------------------ Unicolour.Tests/InterpolateLuvTests.cs | 88 ------------- Unicolour.Tests/InterpolateOklabTests.cs | 88 ------------- Unicolour.Tests/InterpolateOklchTests.cs | 124 ------------------ Unicolour.Tests/InterpolateRgbTests.cs | 88 ------------- Unicolour.Tests/InterpolateXyyTests.cs | 88 ------------- Unicolour.Tests/InterpolateXyzTests.cs | 88 ------------- Unicolour.Tests/InvalidInterpolationTests.cs | 14 +- Unicolour.Tests/LazyEvaluationTests.cs | 4 +- Unicolour.Tests/MixCam02Tests.cs | 88 +++++++++++++ Unicolour.Tests/MixCam16Tests.cs | 88 +++++++++++++ ...ationTests.cs => MixConfigurationTests.cs} | 18 +-- ...aleHctTests.cs => MixGreyscaleHctTests.cs} | 46 +++---- ...pluvTests.cs => MixGreyscaleHpluvTests.cs} | 40 +++--- ...aleHsbTests.cs => MixGreyscaleHsbTests.cs} | 38 +++--- ...aleHslTests.cs => MixGreyscaleHslTests.cs} | 38 +++--- ...sluvTests.cs => MixGreyscaleHsluvTests.cs} | 40 +++--- ...aleHwbTests.cs => MixGreyscaleHwbTests.cs} | 38 +++--- ...zhzTests.cs => MixGreyscaleJzczhzTests.cs} | 38 +++--- ...chabTests.cs => MixGreyscaleLchabTests.cs} | 38 +++--- ...chuvTests.cs => MixGreyscaleLchuvTests.cs} | 38 +++--- ...klchTests.cs => MixGreyscaleOklchTests.cs} | 38 +++--- Unicolour.Tests/MixHctTests.cs | 124 ++++++++++++++++++ ...teHeritageTests.cs => MixHeritageTests.cs} | 78 +++++------ Unicolour.Tests/MixHpluvTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixHsbTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixHslTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixHsluvTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixHwbTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixIctcpTests.cs | 88 +++++++++++++ Unicolour.Tests/MixJzazbzTests.cs | 88 +++++++++++++ Unicolour.Tests/MixJzczhzTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixLabTests.cs | 88 +++++++++++++ Unicolour.Tests/MixLchabTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixLchuvTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixLuvTests.cs | 88 +++++++++++++ Unicolour.Tests/MixOklabTests.cs | 88 +++++++++++++ Unicolour.Tests/MixOklchTests.cs | 124 ++++++++++++++++++ Unicolour.Tests/MixRgbTests.cs | 88 +++++++++++++ Unicolour.Tests/MixXyyTests.cs | 88 +++++++++++++ Unicolour.Tests/MixXyzTests.cs | 88 +++++++++++++ Unicolour.Tests/README.md | 4 +- Unicolour.Tests/Utils/AssertUtils.cs | 25 ++-- Unicolour.Tests/Utils/TestColour.cs | 2 +- Unicolour/ColourRepresentation.cs | 4 +- Unicolour/Comparison.cs | 22 ++-- Unicolour/Interpolation.cs | 27 +--- Unicolour/Unicolour.cs | 42 +++++- Unicolour/Unicolour.csproj | 6 +- 65 files changed, 2521 insertions(+), 2511 deletions(-) delete mode 100644 Unicolour.Tests/InterpolateCam02Tests.cs delete mode 100644 Unicolour.Tests/InterpolateCam16Tests.cs delete mode 100644 Unicolour.Tests/InterpolateHctTests.cs delete mode 100644 Unicolour.Tests/InterpolateHpluvTests.cs delete mode 100644 Unicolour.Tests/InterpolateHsbTests.cs delete mode 100644 Unicolour.Tests/InterpolateHslTests.cs delete mode 100644 Unicolour.Tests/InterpolateHsluvTests.cs delete mode 100644 Unicolour.Tests/InterpolateHwbTests.cs delete mode 100644 Unicolour.Tests/InterpolateIctcpTests.cs delete mode 100644 Unicolour.Tests/InterpolateJzazbzTests.cs delete mode 100644 Unicolour.Tests/InterpolateJzczhzTests.cs delete mode 100644 Unicolour.Tests/InterpolateLabTests.cs delete mode 100644 Unicolour.Tests/InterpolateLchabTests.cs delete mode 100644 Unicolour.Tests/InterpolateLchuvTests.cs delete mode 100644 Unicolour.Tests/InterpolateLuvTests.cs delete mode 100644 Unicolour.Tests/InterpolateOklabTests.cs delete mode 100644 Unicolour.Tests/InterpolateOklchTests.cs delete mode 100644 Unicolour.Tests/InterpolateRgbTests.cs delete mode 100644 Unicolour.Tests/InterpolateXyyTests.cs delete mode 100644 Unicolour.Tests/InterpolateXyzTests.cs create mode 100644 Unicolour.Tests/MixCam02Tests.cs create mode 100644 Unicolour.Tests/MixCam16Tests.cs rename Unicolour.Tests/{InterpolateConfigurationTests.cs => MixConfigurationTests.cs} (79%) rename Unicolour.Tests/{InterpolateGreyscaleHctTests.cs => MixGreyscaleHctTests.cs} (80%) rename Unicolour.Tests/{InterpolateGreyscaleHpluvTests.cs => MixGreyscaleHpluvTests.cs} (74%) rename Unicolour.Tests/{InterpolateGreyscaleHsbTests.cs => MixGreyscaleHsbTests.cs} (74%) rename Unicolour.Tests/{InterpolateGreyscaleHslTests.cs => MixGreyscaleHslTests.cs} (74%) rename Unicolour.Tests/{InterpolateGreyscaleHsluvTests.cs => MixGreyscaleHsluvTests.cs} (74%) rename Unicolour.Tests/{InterpolateGreyscaleHwbTests.cs => MixGreyscaleHwbTests.cs} (74%) rename Unicolour.Tests/{InterpolateGreyscaleJzczhzTests.cs => MixGreyscaleJzczhzTests.cs} (73%) rename Unicolour.Tests/{InterpolateGreyscaleLchabTests.cs => MixGreyscaleLchabTests.cs} (73%) rename Unicolour.Tests/{InterpolateGreyscaleLchuvTests.cs => MixGreyscaleLchuvTests.cs} (73%) rename Unicolour.Tests/{InterpolateGreyscaleOklchTests.cs => MixGreyscaleOklchTests.cs} (73%) create mode 100644 Unicolour.Tests/MixHctTests.cs rename Unicolour.Tests/{InterpolateHeritageTests.cs => MixHeritageTests.cs} (61%) create mode 100644 Unicolour.Tests/MixHpluvTests.cs create mode 100644 Unicolour.Tests/MixHsbTests.cs create mode 100644 Unicolour.Tests/MixHslTests.cs create mode 100644 Unicolour.Tests/MixHsluvTests.cs create mode 100644 Unicolour.Tests/MixHwbTests.cs create mode 100644 Unicolour.Tests/MixIctcpTests.cs create mode 100644 Unicolour.Tests/MixJzazbzTests.cs create mode 100644 Unicolour.Tests/MixJzczhzTests.cs create mode 100644 Unicolour.Tests/MixLabTests.cs create mode 100644 Unicolour.Tests/MixLchabTests.cs create mode 100644 Unicolour.Tests/MixLchuvTests.cs create mode 100644 Unicolour.Tests/MixLuvTests.cs create mode 100644 Unicolour.Tests/MixOklabTests.cs create mode 100644 Unicolour.Tests/MixOklchTests.cs create mode 100644 Unicolour.Tests/MixRgbTests.cs create mode 100644 Unicolour.Tests/MixXyyTests.cs create mode 100644 Unicolour.Tests/MixXyzTests.cs diff --git a/README.md b/README.md index b5aa5c45..5a48a16f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Unicolour is a .NET library written in C# for working with colour: - Colour space conversion -- Colour interpolation +- Colour mixing / colour interpolation - Colour comparison - Colour properties @@ -76,30 +76,30 @@ It is also [extensively tested](Unicolour.Tests), including verification of roun Targets [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0) for use in .NET 5.0+, .NET Core 2.0+ and .NET Framework 4.6.1+ applications. ## Quickstart ⚡ -| Colour space | Construction | Access | Interpolation | -|-----------------------------------------|--------------------------|----------------|------------------------| -| RGB (Hex) | `Unicolour.FromHex()` | `.Hex` | `.InterpolateRgb()` | -| RGB (0-255) | `Unicolour.FromRgb255()` | `.Rgb.Byte255` | `.InterpolateRgb()` | -| RGB | `Unicolour.FromRgb()` | `.Rgb` | `.InterpolateRgb()` | -| HSB/HSV | `Unicolour.FromHsb()` | `.Hsb` | `.InterpolateHsb()` | -| HSL | `Unicolour.FromHsl()` | `.Hsl` | `.InterpolateHsl()` | -| HWB | `Unicolour.FromHwb()` | `.Hwb` | `.InterpolateHwb()` | -| CIEXYZ | `Unicolour.FromXyz()` | `.Xyz` | `.InterpolateXyz()` | -| CIExyY | `Unicolour.FromXyy()` | `.Xyy` | `.InterpolateXyy()` | -| CIELAB | `Unicolour.FromLab()` | `.Lab` | `.InterpolateLab()` | -| CIELChab | `Unicolour.FromLchab()` | `.Lchab` | `.InterpolateLchab()` | -| CIELUV | `Unicolour.FromLuv()` | `.Luv` | `.InterpolateLuv()` | -| CIELChuv | `Unicolour.FromLchuv()` | `.Lchuv` | `.InterpolateLchuv()` | -| HSLuv | `Unicolour.FromHsluv()` | `.Hsluv` | `.InterpolateHsluv()` | -| HPLuv | `Unicolour.FromHpluv()` | `.Hpluv` | `.InterpolateHpluv()` | -| ICTCP | `Unicolour.FromIctcp()` | `.Ictcp` | `.InterpolateIctcp()` | -| Jzazbz | `Unicolour.FromJzazbz()` | `.Jzazbz` | `.InterpolateJzazbz()` | -| JzCzhz | `Unicolour.FromJzczhz()` | `.Jzczhz` | `.InterpolateJzczhz()` | -| Oklab | `Unicolour.FromOklab()` | `.Oklab` | `.InterpolateOklab()` | -| Oklch | `Unicolour.FromOklch()` | `.Oklch` | `.InterpolateOklch()` | -| CIECAM02 | `Unicolour.FromCam02()` | `.Cam02` | `.InterpolateCam02()` | -| CAM16 | `Unicolour.FromCam16()` | `.Cam16` | `.InterpolateCam16()` | -| HCT | `Unicolour.FromHct()` | `.Hct` | `.InterpolateHct()` | +| Colour space | Construction | Access | Interpolation | +|-----------------------------------------|--------------------------|----------------|----------------| +| RGB (Hex) | `Unicolour.FromHex()` | `.Hex` | `.MixRgb()` | +| RGB (0-255) | `Unicolour.FromRgb255()` | `.Rgb.Byte255` | `.MixRgb()` | +| RGB | `Unicolour.FromRgb()` | `.Rgb` | `.MixRgb()` | +| HSB/HSV | `Unicolour.FromHsb()` | `.Hsb` | `.MixHsb()` | +| HSL | `Unicolour.FromHsl()` | `.Hsl` | `.MixHsl()` | +| HWB | `Unicolour.FromHwb()` | `.Hwb` | `.MixHwb()` | +| CIEXYZ | `Unicolour.FromXyz()` | `.Xyz` | `.MixXyz()` | +| CIExyY | `Unicolour.FromXyy()` | `.Xyy` | `.MixXyy()` | +| CIELAB | `Unicolour.FromLab()` | `.Lab` | `.MixLab()` | +| CIELChab | `Unicolour.FromLchab()` | `.Lchab` | `.MixLchab()` | +| CIELUV | `Unicolour.FromLuv()` | `.Luv` | `.MixLuv()` | +| CIELChuv | `Unicolour.FromLchuv()` | `.Lchuv` | `.MixLchuv()` | +| HSLuv | `Unicolour.FromHsluv()` | `.Hsluv` | `.MixHsluv()` | +| HPLuv | `Unicolour.FromHpluv()` | `.Hpluv` | `.MixHpluv()` | +| ICTCP | `Unicolour.FromIctcp()` | `.Ictcp` | `.MixIctcp()` | +| Jzazbz | `Unicolour.FromJzazbz()` | `.Jzazbz` | `.MixJzazbz()` | +| JzCzhz | `Unicolour.FromJzczhz()` | `.Jzczhz` | `.MixJzczhz()` | +| Oklab | `Unicolour.FromOklab()` | `.Oklab` | `.MixOklab()` | +| Oklch | `Unicolour.FromOklch()` | `.Oklch` | `.MixOklch()` | +| CIECAM02 | `Unicolour.FromCam02()` | `.Cam02` | `.MixCam02()` | +| CAM16 | `Unicolour.FromCam16()` | `.Cam16` | `.MixCam16()` | +| HCT | `Unicolour.FromHct()` | `.Hct` | `.MixHct()` | ## How to use 🌈 1. Install the package from [NuGet](https://www.nuget.org/packages/Wacton.Unicolour/) @@ -169,28 +169,28 @@ var relativeLuminance = unicolour.RelativeLuminance; var temperature = unicolour.Temperature; ``` -6. Interpolate between colours: +6. Mix colours (interpolate between them): ```c# -var interpolated = unicolour1.InterpolateRgb(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHsb(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHsl(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHwb(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateXyz(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateXyy(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateLab(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateLchab(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateLuv(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateLchuv(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHsluv(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHpluv(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateIctcp(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateJzazbz(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateJzczhz(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateOklab(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateOklch(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateCam02(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateCam16(unicolour2, 0.5); -var interpolated = unicolour1.InterpolateHct(unicolour2, 0.5); +var mixed = unicolour1.MixRgb(unicolour2, 0.5); +var mixed = unicolour1.MixHsb(unicolour2, 0.5); +var mixed = unicolour1.MixHsl(unicolour2, 0.5); +var mixed = unicolour1.MixHwb(unicolour2, 0.5); +var mixed = unicolour1.MixXyz(unicolour2, 0.5); +var mixed = unicolour1.MixXyy(unicolour2, 0.5); +var mixed = unicolour1.MixLab(unicolour2, 0.5); +var mixed = unicolour1.MixLchab(unicolour2, 0.5); +var mixed = unicolour1.MixLuv(unicolour2, 0.5); +var mixed = unicolour1.MixLchuv(unicolour2, 0.5); +var mixed = unicolour1.MixHsluv(unicolour2, 0.5); +var mixed = unicolour1.MixHpluv(unicolour2, 0.5); +var mixed = unicolour1.MixIctcp(unicolour2, 0.5); +var mixed = unicolour1.MixJzazbz(unicolour2, 0.5); +var mixed = unicolour1.MixJzczhz(unicolour2, 0.5); +var mixed = unicolour1.MixOklab(unicolour2, 0.5); +var mixed = unicolour1.MixOklch(unicolour2, 0.5); +var mixed = unicolour1.MixCam02(unicolour2, 0.5); +var mixed = unicolour1.MixCam16(unicolour2, 0.5); +var mixed = unicolour1.MixHct(unicolour2, 0.5); ``` 7. Compare colours: diff --git a/Unicolour.Example/Gradient.cs b/Unicolour.Example/Gradient.cs index 3a70594a..1ca48f4c 100644 --- a/Unicolour.Example/Gradient.cs +++ b/Unicolour.Example/Gradient.cs @@ -7,10 +7,10 @@ internal static class Gradient { const bool ConstrainUndisplayableColours = true; // if false, undisplayable colours will render as transparent - internal delegate Unicolour Interpolate(Unicolour start, Unicolour end, double distance); + internal delegate Unicolour Mix(Unicolour start, Unicolour end, double distance); internal static Image Draw((string text, Unicolour colour) label, int width, int height, - Unicolour[] colourPoints, Interpolate interpolate) + Unicolour[] colourPoints, Mix mix) { var image = new Image(width, height); @@ -21,7 +21,7 @@ internal static Image Draw((string text, Unicolour colour) label, int wi { var startColour = colourPoints[sectionIndex]; var endColour = colourPoints[sectionIndex + 1]; - SetSectionPixels(image, sectionWidth, sectionIndex, height, startColour, endColour, interpolate); + SetSectionPixels(image, sectionWidth, sectionIndex, height, startColour, endColour, mix); } SetLabel(image, label.text, label.colour); @@ -29,12 +29,12 @@ internal static Image Draw((string text, Unicolour colour) label, int wi } private static void SetSectionPixels(Image image, int sectionWidth, int sectionIndex, int height, - Unicolour startColour, Unicolour endColour, Interpolate interpolate) + Unicolour startColour, Unicolour endColour, Mix mix) { for (var pixelIndex = 0; pixelIndex < sectionWidth; pixelIndex++) { var distance = pixelIndex / (double)(sectionWidth - 1); - var colour = interpolate(startColour, endColour, distance); + var colour = mix(startColour, endColour, distance); var column = sectionWidth * sectionIndex + pixelIndex; SetImageColumnPixels(image, column, height, colour); } diff --git a/Unicolour.Example/Program.cs b/Unicolour.Example/Program.cs index be21bccf..98b5a9ce 100644 --- a/Unicolour.Example/Program.cs +++ b/Unicolour.Example/Program.cs @@ -18,7 +18,7 @@ void GenerateColourSpaceGradients() var cyan = Unicolour.FromRgb255(0, 255, 255); var black = Unicolour.FromRgb(0, 0, 0); var green = Unicolour.FromRgb(0, 1, 0); - + var light = Unicolour.FromHex("#E8E8FF"); var column1 = DrawColumn(new[] { purple, orange }); var column2 = DrawColumn(new[] { pink, cyan }); @@ -36,26 +36,26 @@ void GenerateColourSpaceGradients() Image DrawColumn(Unicolour[] colourPoints) { - var rgb = Gradient.Draw(("RGB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateRgb(end, distance)); - var hsb = Gradient.Draw(("HSB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHsb(end, distance)); - var hsl = Gradient.Draw(("HSL", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHsl(end, distance)); - var hwb = Gradient.Draw(("HWB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHwb(end, distance)); - var xyz = Gradient.Draw(("XYZ", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateXyz(end, distance)); - var xyy = Gradient.Draw(("xyY", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateXyy(end, distance)); - var lab = Gradient.Draw(("LAB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateLab(end, distance)); - var lchab = Gradient.Draw(("LCHab", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateLchab(end, distance)); - var luv = Gradient.Draw(("LUV", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateLuv(end, distance)); - var lchuv = Gradient.Draw(("LCHuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateLchuv(end, distance)); - var hsluv = Gradient.Draw(("HSLuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHsluv(end, distance)); - var hpluv = Gradient.Draw(("HPLuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHpluv(end, distance)); - var ictcp = Gradient.Draw(("ICtCp", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateIctcp(end, distance)); - var jzazbz = Gradient.Draw(("JzAzBz", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateJzazbz(end, distance)); - var jzczhz = Gradient.Draw(("JzCzHz", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateJzczhz(end, distance)); - var oklab = Gradient.Draw(("OKLAB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateOklab(end, distance)); - var oklch = Gradient.Draw(("OKLCH", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateOklch(end, distance)); - var cam02 = Gradient.Draw(("CAM02", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateCam02(end, distance)); - var cam16 = Gradient.Draw(("CAM16", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateCam16(end, distance)); - var hct = Gradient.Draw(("HCT", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.InterpolateHct(end, distance)); + var rgb = Gradient.Draw(("RGB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixRgb(end, distance)); + var hsb = Gradient.Draw(("HSB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHsb(end, distance)); + var hsl = Gradient.Draw(("HSL", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHsl(end, distance)); + var hwb = Gradient.Draw(("HWB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHwb(end, distance)); + var xyz = Gradient.Draw(("XYZ", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixXyz(end, distance)); + var xyy = Gradient.Draw(("xyY", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixXyy(end, distance)); + var lab = Gradient.Draw(("LAB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixLab(end, distance)); + var lchab = Gradient.Draw(("LCHab", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixLchab(end, distance)); + var luv = Gradient.Draw(("LUV", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixLuv(end, distance)); + var lchuv = Gradient.Draw(("LCHuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixLchuv(end, distance)); + var hsluv = Gradient.Draw(("HSLuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHsluv(end, distance)); + var hpluv = Gradient.Draw(("HPLuv", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHpluv(end, distance)); + var ictcp = Gradient.Draw(("ICtCp", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixIctcp(end, distance)); + var jzazbz = Gradient.Draw(("JzAzBz", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixJzazbz(end, distance)); + var jzczhz = Gradient.Draw(("JzCzHz", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixJzczhz(end, distance)); + var oklab = Gradient.Draw(("OKLAB", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixOklab(end, distance)); + var oklch = Gradient.Draw(("OKLCH", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixOklch(end, distance)); + var cam02 = Gradient.Draw(("CAM02", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixCam02(end, distance)); + var cam16 = Gradient.Draw(("CAM16", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixCam16(end, distance)); + var hct = Gradient.Draw(("HCT", light), columnWidth, rowHeight, colourPoints, (start, end, distance) => start.MixHct(end, distance)); var columnImage = new Image(columnWidth, rowHeight * rows); columnImage.Mutate(context => context @@ -103,15 +103,15 @@ void GenerateVisionDeficiencyGradients() var dark = Unicolour.FromHex("#404046"); var none = Gradient.Draw(("No deficiency", dark), width, rowHeight, colourPoints, - (start, end, distance) => start.InterpolateHsb(end, distance)); + (start, end, distance) => start.MixHsb(end, distance)); var protanopia = Gradient.Draw(("Protanopia", dark), width, rowHeight, colourPoints, - (start, end, distance) => start.InterpolateHsb(end, distance).SimulateProtanopia()); + (start, end, distance) => start.MixHsb(end, distance).SimulateProtanopia()); var deuteranopia = Gradient.Draw(("Deuteranopia", dark), width, rowHeight, colourPoints, - (start, end, distance) => start.InterpolateHsb(end, distance).SimulateDeuteranopia()); + (start, end, distance) => start.MixHsb(end, distance).SimulateDeuteranopia()); var tritanopia = Gradient.Draw(("Tritanopia", dark), width, rowHeight, colourPoints, - (start, end, distance) => start.InterpolateHsb(end, distance).SimulateTritanopia()); + (start, end, distance) => start.MixHsb(end, distance).SimulateTritanopia()); var achromatopsia = Gradient.Draw(("Achromatopsia", dark), width, rowHeight, colourPoints, - (start, end, distance) => start.InterpolateHsb(end, distance).SimulateAchromatopsia()); + (start, end, distance) => start.MixHsb(end, distance).SimulateAchromatopsia()); var image = new Image(width, rowHeight * rows); image.Mutate(context => context diff --git a/Unicolour.Tests/InterpolateCam02Tests.cs b/Unicolour.Tests/InterpolateCam02Tests.cs deleted file mode 100644 index fad70e06..00000000 --- a/Unicolour.Tests/InterpolateCam02Tests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateCam02Tests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromCam02(50, -25, 25, 0.5); - var unicolour2 = Unicolour.FromCam02(50, -25, 25, 0.5); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateCam02(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateCam02(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated2, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated3, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated4, (50, -25, 25, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromCam02(0, -50, -50, 0.0); - var unicolour2 = Unicolour.FromCam02(50, 50, 50); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 0, 0, 0.5)); - AssertInterpolated(interpolated2, (25, 0, 0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromCam02(0, 50, -50); - var unicolour2 = Unicolour.FromCam02(80, -50, 50, 0.5); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, -25, 25, 0.625)); - AssertInterpolated(interpolated2, (20, 25, -25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromCam02(0, 50, -50); - var unicolour2 = Unicolour.FromCam02(80, -50, 50, 0.5); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 25, -25, 0.875)); - AssertInterpolated(interpolated2, (60, -25, 25, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromCam02(20, -10, 10, 0.8); - var unicolour2 = Unicolour.FromCam02(30, 10, -10, 0.9); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 20, -20, 0.95)); - AssertInterpolated(interpolated2, (15, -20, 20, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromCam02(20, -10, 10, 0.8); - var unicolour2 = Unicolour.FromCam02(30, 10, -10, 0.9); - var interpolated1 = unicolour1.InterpolateCam02(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateCam02(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, -20, 20, 0.75)); - AssertInterpolated(interpolated2, (35, 20, -20, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Cam02.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateCam16Tests.cs b/Unicolour.Tests/InterpolateCam16Tests.cs deleted file mode 100644 index 508a115a..00000000 --- a/Unicolour.Tests/InterpolateCam16Tests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateCam16Tests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromCam16(50, -25, 25, 0.5); - var unicolour2 = Unicolour.FromCam16(50, -25, 25, 0.5); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateCam16(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateCam16(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated2, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated3, (50, -25, 25, 0.5)); - AssertInterpolated(interpolated4, (50, -25, 25, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromCam16(0, -50, -50, 0.0); - var unicolour2 = Unicolour.FromCam16(50, 50, 50); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 0, 0, 0.5)); - AssertInterpolated(interpolated2, (25, 0, 0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromCam16(0, 50, -50); - var unicolour2 = Unicolour.FromCam16(80, -50, 50, 0.5); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, -25, 25, 0.625)); - AssertInterpolated(interpolated2, (20, 25, -25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromCam16(0, 50, -50); - var unicolour2 = Unicolour.FromCam16(80, -50, 50, 0.5); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 25, -25, 0.875)); - AssertInterpolated(interpolated2, (60, -25, 25, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromCam16(20, -10, 10, 0.8); - var unicolour2 = Unicolour.FromCam16(30, 10, -10, 0.9); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 20, -20, 0.95)); - AssertInterpolated(interpolated2, (15, -20, 20, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromCam16(20, -10, 10, 0.8); - var unicolour2 = Unicolour.FromCam16(30, 10, -10, 0.9); - var interpolated1 = unicolour1.InterpolateCam16(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateCam16(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, -20, 20, 0.75)); - AssertInterpolated(interpolated2, (35, 20, -20, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Cam16.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHctTests.cs b/Unicolour.Tests/InterpolateHctTests.cs deleted file mode 100644 index 5f2f03c7..00000000 --- a/Unicolour.Tests/InterpolateHctTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHctTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHct(180, 30, 75, 0.5); - var unicolour2 = Unicolour.FromHct(180, 30, 75, 0.5); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHct(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHct(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 30, 75, 0.5)); - AssertInterpolated(interpolated2, (180, 30, 75, 0.5)); - AssertInterpolated(interpolated3, (180, 30, 75, 0.5)); - AssertInterpolated(interpolated4, (180, 30, 75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHct(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHct(180, 120, 100); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 60, 50, 0.5)); - AssertInterpolated(interpolated2, (90, 60, 50, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHct(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHct(340, 60, 80, 0.2); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 30, 40, 0.1)); - AssertInterpolated(interpolated2, (350, 30, 40, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHct(0, 120, 0); - var unicolour2 = Unicolour.FromHct(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 30, 75, 0.625)); - AssertInterpolated(interpolated2, (45, 90, 25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHct(300, 120, 0); - var unicolour2 = Unicolour.FromHct(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 30, 75, 0.625)); - AssertInterpolated(interpolated2, (330, 90, 25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHct(0, 120, 0); - var unicolour2 = Unicolour.FromHct(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 90, 25, 0.875)); - AssertInterpolated(interpolated2, (135, 30, 75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHct(300, 120, 0); - var unicolour2 = Unicolour.FromHct(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 90, 25, 0.875)); - AssertInterpolated(interpolated2, (30, 30, 75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHct(0, 48, 60, 0.8); - var unicolour2 = Unicolour.FromHct(90, 72, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 84, 30, 0.95)); - AssertInterpolated(interpolated2, (315, 36, 70, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHct(0, 48, 60, 0.8); - var unicolour2 = Unicolour.FromHct(90, 72, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHct(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHct(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 36, 70, 0.75)); - AssertInterpolated(interpolated2, (135, 84, 30, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hct.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHpluvTests.cs b/Unicolour.Tests/InterpolateHpluvTests.cs deleted file mode 100644 index 1fc4d7ce..00000000 --- a/Unicolour.Tests/InterpolateHpluvTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHpluvTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHpluv(180, 25, 75, 0.5); - var unicolour2 = Unicolour.FromHpluv(180, 25, 75, 0.5); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHpluv(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHpluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated2, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated3, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated4, (180, 25, 75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHpluv(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHpluv(180, 100, 100); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 50, 50, 0.5)); - AssertInterpolated(interpolated2, (90, 50, 50, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHpluv(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHpluv(340, 50, 80, 0.2); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 25, 40, 0.1)); - AssertInterpolated(interpolated2, (350, 25, 40, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHpluv(0, 100, 0); - var unicolour2 = Unicolour.FromHpluv(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 25, 75, 0.625)); - AssertInterpolated(interpolated2, (45, 75, 25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHpluv(300, 100, 0); - var unicolour2 = Unicolour.FromHpluv(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 25, 75, 0.625)); - AssertInterpolated(interpolated2, (330, 75, 25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHpluv(0, 100, 0); - var unicolour2 = Unicolour.FromHpluv(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 75, 25, 0.875)); - AssertInterpolated(interpolated2, (135, 25, 75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHpluv(300, 100, 0); - var unicolour2 = Unicolour.FromHpluv(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 75, 25, 0.875)); - AssertInterpolated(interpolated2, (30, 25, 75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHpluv(0, 40, 60, 0.8); - var unicolour2 = Unicolour.FromHpluv(90, 60, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 70, 30, 0.95)); - AssertInterpolated(interpolated2, (315, 30, 70, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHpluv(0, 40, 60, 0.8); - var unicolour2 = Unicolour.FromHpluv(90, 60, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHpluv(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHpluv(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 30, 70, 0.75)); - AssertInterpolated(interpolated2, (135, 70, 30, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hpluv.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHsbTests.cs b/Unicolour.Tests/InterpolateHsbTests.cs deleted file mode 100644 index 00e9213a..00000000 --- a/Unicolour.Tests/InterpolateHsbTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHsbTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHsb(180, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromHsb(180, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHsb(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHsb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (180, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHsb(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsb(180, 1, 1); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (90, 0.5, 0.5, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHsb(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsb(340, 0.5, 0.8, 0.2); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 0.25, 0.4, 0.1)); - AssertInterpolated(interpolated2, (350, 0.25, 0.4, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHsb(0, 1, 0); - var unicolour2 = Unicolour.FromHsb(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (45, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHsb(300, 1, 0); - var unicolour2 = Unicolour.FromHsb(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (330, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHsb(0, 1, 0); - var unicolour2 = Unicolour.FromHsb(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (135, 0.25, 0.75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHsb(300, 1, 0); - var unicolour2 = Unicolour.FromHsb(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (30, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHsb(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHsb(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (315, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHsb(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHsb(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHsb(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (135, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hsb.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHslTests.cs b/Unicolour.Tests/InterpolateHslTests.cs deleted file mode 100644 index 28ca1d37..00000000 --- a/Unicolour.Tests/InterpolateHslTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHslTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHsl(180, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromHsl(180, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHsl(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHsl(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (180, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHsl(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsl(180, 1, 1); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (90, 0.5, 0.5, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHsl(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsl(340, 0.5, 0.8, 0.2); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 0.25, 0.4, 0.1)); - AssertInterpolated(interpolated2, (350, 0.25, 0.4, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHsl(0, 1, 0); - var unicolour2 = Unicolour.FromHsl(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (45, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHsl(300, 1, 0); - var unicolour2 = Unicolour.FromHsl(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (330, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHsl(0, 1, 0); - var unicolour2 = Unicolour.FromHsl(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (135, 0.25, 0.75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHsl(300, 1, 0); - var unicolour2 = Unicolour.FromHsl(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (30, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHsl(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHsl(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (315, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHsl(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHsl(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHsl(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHsl(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (135, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hsl.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHsluvTests.cs b/Unicolour.Tests/InterpolateHsluvTests.cs deleted file mode 100644 index d2753183..00000000 --- a/Unicolour.Tests/InterpolateHsluvTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHsluvTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHsluv(180, 25, 75, 0.5); - var unicolour2 = Unicolour.FromHsluv(180, 25, 75, 0.5); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHsluv(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHsluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated2, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated3, (180, 25, 75, 0.5)); - AssertInterpolated(interpolated4, (180, 25, 75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHsluv(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsluv(180, 100, 100); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 50, 50, 0.5)); - AssertInterpolated(interpolated2, (90, 50, 50, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHsluv(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHsluv(340, 50, 80, 0.2); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 25, 40, 0.1)); - AssertInterpolated(interpolated2, (350, 25, 40, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHsluv(0, 100, 0); - var unicolour2 = Unicolour.FromHsluv(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 25, 75, 0.625)); - AssertInterpolated(interpolated2, (45, 75, 25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHsluv(300, 100, 0); - var unicolour2 = Unicolour.FromHsluv(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 25, 75, 0.625)); - AssertInterpolated(interpolated2, (330, 75, 25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHsluv(0, 100, 0); - var unicolour2 = Unicolour.FromHsluv(180, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 75, 25, 0.875)); - AssertInterpolated(interpolated2, (135, 25, 75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHsluv(300, 100, 0); - var unicolour2 = Unicolour.FromHsluv(60, 0, 100, 0.5); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 75, 25, 0.875)); - AssertInterpolated(interpolated2, (30, 25, 75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHsluv(0, 40, 60, 0.8); - var unicolour2 = Unicolour.FromHsluv(90, 60, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 70, 30, 0.95)); - AssertInterpolated(interpolated2, (315, 30, 70, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHsluv(0, 40, 60, 0.8); - var unicolour2 = Unicolour.FromHsluv(90, 60, 40, 0.9); - var interpolated1 = unicolour1.InterpolateHsluv(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHsluv(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 30, 70, 0.75)); - AssertInterpolated(interpolated2, (135, 70, 30, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hsluv.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHwbTests.cs b/Unicolour.Tests/InterpolateHwbTests.cs deleted file mode 100644 index 372b5738..00000000 --- a/Unicolour.Tests/InterpolateHwbTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateHwbTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromHwb(180, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromHwb(180, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateHwb(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateHwb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (180, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (180, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromHwb(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHwb(180, 1, 1); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (90, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (90, 0.5, 0.5, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromHwb(0, 0, 0, 0); - var unicolour2 = Unicolour.FromHwb(340, 0.5, 0.8, 0.2); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (350, 0.25, 0.4, 0.1)); - AssertInterpolated(interpolated2, (350, 0.25, 0.4, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromHwb(0, 1, 0); - var unicolour2 = Unicolour.FromHwb(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (135, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (45, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromHwb(300, 1, 0); - var unicolour2 = Unicolour.FromHwb(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (30, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (330, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromHwb(0, 1, 0); - var unicolour2 = Unicolour.FromHwb(180, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (45, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (135, 0.25, 0.75, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromHwb(300, 1, 0); - var unicolour2 = Unicolour.FromHwb(60, 0, 1, 0.5); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (330, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (30, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromHwb(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHwb(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (135, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (315, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromHwb(0, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromHwb(90, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateHwb(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateHwb(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (315, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (135, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Hwb.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateIctcpTests.cs b/Unicolour.Tests/InterpolateIctcpTests.cs deleted file mode 100644 index e9fd0ca3..00000000 --- a/Unicolour.Tests/InterpolateIctcpTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateIctcpTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromIctcp(0.5, -0.25, 0.25, 0.5); - var unicolour2 = Unicolour.FromIctcp(0.5, -0.25, 0.25, 0.5); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateIctcp(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateIctcp(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated2, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated3, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated4, (0.5, -0.25, 0.25, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromIctcp(0.0, -0.5, -0.5, 0.0); - var unicolour2 = Unicolour.FromIctcp(0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.0, 0.0, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.0, 0.0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromIctcp(0, 0.5, -0.5); - var unicolour2 = Unicolour.FromIctcp(0.8, -0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, -0.25, 0.25, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.25, -0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromIctcp(0, 0.5, -0.5); - var unicolour2 = Unicolour.FromIctcp(0.8, -0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.25, -0.25, 0.875)); - AssertInterpolated(interpolated2, (0.6, -0.25, 0.25, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromIctcp(0.2, -0.125, 0.125, 0.8); - var unicolour2 = Unicolour.FromIctcp(0.3, 0.125, -0.125, 0.9); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.25, -0.25, 0.95)); - AssertInterpolated(interpolated2, (0.15, -0.25, 0.25, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromIctcp(0.2, -0.125, 0.125, 0.8); - var unicolour2 = Unicolour.FromIctcp(0.3, 0.125, -0.125, 0.9); - var interpolated1 = unicolour1.InterpolateIctcp(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateIctcp(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, -0.25, 0.25, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.25, -0.25, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Ictcp.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateJzazbzTests.cs b/Unicolour.Tests/InterpolateJzazbzTests.cs deleted file mode 100644 index 83659163..00000000 --- a/Unicolour.Tests/InterpolateJzazbzTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateJzazbzTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromJzazbz(0.08, -0.05, 0.05, 0.5); - var unicolour2 = Unicolour.FromJzazbz(0.08, -0.05, 0.05, 0.5); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateJzazbz(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateJzazbz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.08, -0.05, 0.05, 0.5)); - AssertInterpolated(interpolated2, (0.08, -0.05, 0.05, 0.5)); - AssertInterpolated(interpolated3, (0.08, -0.05, 0.05, 0.5)); - AssertInterpolated(interpolated4, (0.08, -0.05, 0.05, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromJzazbz(0.0, -0.1, -0.1, 0.0); - var unicolour2 = Unicolour.FromJzazbz(0.08, 0.1, 0.1); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.04, 0.0, 0.0, 0.5)); - AssertInterpolated(interpolated2, (0.04, 0.0, 0.0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromJzazbz(0, 0.1, -0.1); - var unicolour2 = Unicolour.FromJzazbz(0.12, -0.1, 0.1, 0.5); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.09, -0.05, 0.05, 0.625)); - AssertInterpolated(interpolated2, (0.03, 0.05, -0.05, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromJzazbz(0, 0.1, -0.1); - var unicolour2 = Unicolour.FromJzazbz(0.12, -0.1, 0.1, 0.5); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.03, 0.05, -0.05, 0.875)); - AssertInterpolated(interpolated2, (0.09, -0.05, 0.05, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromJzazbz(0.02, -0.025, 0.025, 0.8); - var unicolour2 = Unicolour.FromJzazbz(0.03, 0.025, -0.025, 0.9); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.035, 0.05, -0.05, 0.95)); - AssertInterpolated(interpolated2, (0.015, -0.05, 0.05, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromJzazbz(0.02, -0.025, 0.025, 0.8); - var unicolour2 = Unicolour.FromJzazbz(0.03, 0.025, -0.025, 0.9); - var interpolated1 = unicolour1.InterpolateJzazbz(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateJzazbz(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.015, -0.05, 0.05, 0.75)); - AssertInterpolated(interpolated2, (0.035, 0.05, -0.05, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Jzazbz.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateJzczhzTests.cs b/Unicolour.Tests/InterpolateJzczhzTests.cs deleted file mode 100644 index d82606fc..00000000 --- a/Unicolour.Tests/InterpolateJzczhzTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateJzczhzTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromJzczhz(0.08, 0.08, 180, 0.5); - var unicolour2 = Unicolour.FromJzczhz(0.08, 0.08, 180, 0.5); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateJzczhz(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateJzczhz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.08, 0.08, 180, 0.5)); - AssertInterpolated(interpolated2, (0.08, 0.08, 180, 0.5)); - AssertInterpolated(interpolated3, (0.08, 0.08, 180, 0.5)); - AssertInterpolated(interpolated4, (0.08, 0.08, 180, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0, 0, 0.0); - var unicolour2 = Unicolour.FromJzczhz(0.08, 0.08, 180); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.04, 0.04, 90, 0.5)); - AssertInterpolated(interpolated2, (0.04, 0.04, 90, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0, 0, 0); - var unicolour2 = Unicolour.FromJzczhz(0.12, 0.04, 340, 0.2); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.06, 0.02, 350, 0.1)); - AssertInterpolated(interpolated2, (0.06, 0.02, 350, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 0); - var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.09, 0.02, 135, 0.625)); - AssertInterpolated(interpolated2, (0.03, 0.06, 45, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 300); - var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.09, 0.02, 30, 0.625)); - AssertInterpolated(interpolated2, (0.03, 0.06, 330, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 0); - var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.03, 0.06, 45, 0.875)); - AssertInterpolated(interpolated2, (0.09, 0.02, 135, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 300); - var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.03, 0.06, 330, 0.875)); - AssertInterpolated(interpolated2, (0.09, 0.02, 30, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromJzczhz(0.02, 0.02, 0, 0.8); - var unicolour2 = Unicolour.FromJzczhz(0.03, 0.03, 90, 0.9); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.035, 0.035, 135, 0.95)); - AssertInterpolated(interpolated2, (0.015, 0.015, 315, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromJzczhz(0.02, 0.02, 0, 0.8); - var unicolour2 = Unicolour.FromJzczhz(0.03, 0.03, 90, 0.9); - var interpolated1 = unicolour1.InterpolateJzczhz(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateJzczhz(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.015, 0.015, 315, 0.75)); - AssertInterpolated(interpolated2, (0.035, 0.035, 135, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Jzczhz.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateLabTests.cs b/Unicolour.Tests/InterpolateLabTests.cs deleted file mode 100644 index 20ff6486..00000000 --- a/Unicolour.Tests/InterpolateLabTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateLabTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromLab(50, -64, 64, 0.5); - var unicolour2 = Unicolour.FromLab(50, -64, 64, 0.5); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateLab(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateLab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, -64, 64, 0.5)); - AssertInterpolated(interpolated2, (50, -64, 64, 0.5)); - AssertInterpolated(interpolated3, (50, -64, 64, 0.5)); - AssertInterpolated(interpolated4, (50, -64, 64, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromLab(0, -128, -128, 0.0); - var unicolour2 = Unicolour.FromLab(50, 128, 128); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 0, 0, 0.5)); - AssertInterpolated(interpolated2, (25, 0, 0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromLab(0, 128, -128); - var unicolour2 = Unicolour.FromLab(80, -128, 128, 0.5); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, -64, 64, 0.625)); - AssertInterpolated(interpolated2, (20, 64, -64, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromLab(0, 128, -128); - var unicolour2 = Unicolour.FromLab(80, -128, 128, 0.5); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 64, -64, 0.875)); - AssertInterpolated(interpolated2, (60, -64, 64, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromLab(20, -25.6, 25.6, 0.8); - var unicolour2 = Unicolour.FromLab(30, 25.6, -25.6, 0.9); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 51.2, -51.2, 0.95)); - AssertInterpolated(interpolated2, (15, -51.2, 51.2, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromLab(20, -25.6, 25.6, 0.8); - var unicolour2 = Unicolour.FromLab(30, 25.6, -25.6, 0.9); - var interpolated1 = unicolour1.InterpolateLab(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateLab(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, -51.2, 51.2, 0.75)); - AssertInterpolated(interpolated2, (35, 51.2, -51.2, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Lab.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateLchabTests.cs b/Unicolour.Tests/InterpolateLchabTests.cs deleted file mode 100644 index e745338b..00000000 --- a/Unicolour.Tests/InterpolateLchabTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateLchabTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromLchab(50, 50, 180, 0.5); - var unicolour2 = Unicolour.FromLchab(50, 50, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateLchab(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateLchab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated2, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated3, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated4, (50, 50, 180, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromLchab(0, 0, 0, 0.0); - var unicolour2 = Unicolour.FromLchab(50, 100, 180); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 50, 90, 0.5)); - AssertInterpolated(interpolated2, (25, 50, 90, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromLchab(0, 0, 0, 0); - var unicolour2 = Unicolour.FromLchab(80, 50, 340, 0.2); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (40, 25, 350, 0.1)); - AssertInterpolated(interpolated2, (40, 25, 350, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromLchab(0, 100, 0); - var unicolour2 = Unicolour.FromLchab(80, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, 25, 135, 0.625)); - AssertInterpolated(interpolated2, (20, 75, 45, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromLchab(0, 100, 300); - var unicolour2 = Unicolour.FromLchab(80, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, 25, 30, 0.625)); - AssertInterpolated(interpolated2, (20, 75, 330, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromLchab(0, 100, 0); - var unicolour2 = Unicolour.FromLchab(80, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 75, 45, 0.875)); - AssertInterpolated(interpolated2, (60, 25, 135, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromLchab(0, 100, 300); - var unicolour2 = Unicolour.FromLchab(80, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 75, 330, 0.875)); - AssertInterpolated(interpolated2, (60, 25, 30, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromLchab(20, 40, 0, 0.8); - var unicolour2 = Unicolour.FromLchab(30, 60, 90, 0.9); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 70, 135, 0.95)); - AssertInterpolated(interpolated2, (15, 30, 315, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromLchab(20, 40, 0, 0.8); - var unicolour2 = Unicolour.FromLchab(30, 60, 90, 0.9); - var interpolated1 = unicolour1.InterpolateLchab(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateLchab(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, 30, 315, 0.75)); - AssertInterpolated(interpolated2, (35, 70, 135, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Lchab.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateLchuvTests.cs b/Unicolour.Tests/InterpolateLchuvTests.cs deleted file mode 100644 index a3ea095c..00000000 --- a/Unicolour.Tests/InterpolateLchuvTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateLchuvTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromLchuv(50, 50, 180, 0.5); - var unicolour2 = Unicolour.FromLchuv(50, 50, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateLchuv(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateLchuv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated2, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated3, (50, 50, 180, 0.5)); - AssertInterpolated(interpolated4, (50, 50, 180, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromLchuv(0, 0, 0, 0.0); - var unicolour2 = Unicolour.FromLchuv(50, 100, 180); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 50, 90, 0.5)); - AssertInterpolated(interpolated2, (25, 50, 90, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromLchuv(0, 0, 0, 0); - var unicolour2 = Unicolour.FromLchuv(80, 50, 340, 0.2); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (40, 25, 350, 0.1)); - AssertInterpolated(interpolated2, (40, 25, 350, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromLchuv(0, 100, 0); - var unicolour2 = Unicolour.FromLchuv(80, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, 25, 135, 0.625)); - AssertInterpolated(interpolated2, (20, 75, 45, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromLchuv(0, 100, 300); - var unicolour2 = Unicolour.FromLchuv(80, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, 25, 30, 0.625)); - AssertInterpolated(interpolated2, (20, 75, 330, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromLchuv(0, 100, 0); - var unicolour2 = Unicolour.FromLchuv(80, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 75, 45, 0.875)); - AssertInterpolated(interpolated2, (60, 25, 135, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromLchuv(0, 100, 300); - var unicolour2 = Unicolour.FromLchuv(80, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 75, 330, 0.875)); - AssertInterpolated(interpolated2, (60, 25, 30, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromLchuv(20, 40, 0, 0.8); - var unicolour2 = Unicolour.FromLchuv(30, 60, 90, 0.9); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 70, 135, 0.95)); - AssertInterpolated(interpolated2, (15, 30, 315, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromLchuv(20, 40, 0, 0.8); - var unicolour2 = Unicolour.FromLchuv(30, 60, 90, 0.9); - var interpolated1 = unicolour1.InterpolateLchuv(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateLchuv(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, 30, 315, 0.75)); - AssertInterpolated(interpolated2, (35, 70, 135, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Lchuv.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateLuvTests.cs b/Unicolour.Tests/InterpolateLuvTests.cs deleted file mode 100644 index 6b3d84d2..00000000 --- a/Unicolour.Tests/InterpolateLuvTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateLuvTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromLuv(50, -50, 50, 0.5); - var unicolour2 = Unicolour.FromLuv(50, -50, 50, 0.5); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateLuv(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateLuv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (50, -50, 50, 0.5)); - AssertInterpolated(interpolated2, (50, -50, 50, 0.5)); - AssertInterpolated(interpolated3, (50, -50, 50, 0.5)); - AssertInterpolated(interpolated4, (50, -50, 50, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromLuv(0, -100, -100, 0.0); - var unicolour2 = Unicolour.FromLuv(50, 100, 100); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (25, 0, 0, 0.5)); - AssertInterpolated(interpolated2, (25, 0, 0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromLuv(0, 100, -100); - var unicolour2 = Unicolour.FromLuv(80, -100, 100, 0.5); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (60, -50, 50, 0.625)); - AssertInterpolated(interpolated2, (20, 50, -50, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromLuv(0, 100, -100); - var unicolour2 = Unicolour.FromLuv(80, -100, 100, 0.5); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (20, 50, -50, 0.875)); - AssertInterpolated(interpolated2, (60, -50, 50, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromLuv(20, -25.6, 25.6, 0.8); - var unicolour2 = Unicolour.FromLuv(30, 25.6, -25.6, 0.9); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (35, 51.2, -51.2, 0.95)); - AssertInterpolated(interpolated2, (15, -51.2, 51.2, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromLuv(20, -25.6, 25.6, 0.8); - var unicolour2 = Unicolour.FromLuv(30, 25.6, -25.6, 0.9); - var interpolated1 = unicolour1.InterpolateLuv(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateLuv(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (15, -51.2, 51.2, 0.75)); - AssertInterpolated(interpolated2, (35, 51.2, -51.2, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Luv.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateOklabTests.cs b/Unicolour.Tests/InterpolateOklabTests.cs deleted file mode 100644 index b407c6ec..00000000 --- a/Unicolour.Tests/InterpolateOklabTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateOklabTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromOklab(0.5, -0.25, 0.25, 0.5); - var unicolour2 = Unicolour.FromOklab(0.5, -0.25, 0.25, 0.5); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateOklab(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateOklab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated2, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated3, (0.5, -0.25, 0.25, 0.5)); - AssertInterpolated(interpolated4, (0.5, -0.25, 0.25, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromOklab(0.0, -0.5, -0.5, 0.0); - var unicolour2 = Unicolour.FromOklab(0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.0, 0.0, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.0, 0.0, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromOklab(0, 0.5, -0.5); - var unicolour2 = Unicolour.FromOklab(0.8, -0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, -0.25, 0.25, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.25, -0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromOklab(0, 0.5, -0.5); - var unicolour2 = Unicolour.FromOklab(0.8, -0.5, 0.5, 0.5); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.25, -0.25, 0.875)); - AssertInterpolated(interpolated2, (0.6, -0.25, 0.25, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromOklab(0.2, -0.125, 0.125, 0.8); - var unicolour2 = Unicolour.FromOklab(0.3, 0.125, -0.125, 0.9); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.25, -0.25, 0.95)); - AssertInterpolated(interpolated2, (0.15, -0.25, 0.25, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromOklab(0.2, -0.125, 0.125, 0.8); - var unicolour2 = Unicolour.FromOklab(0.3, 0.125, -0.125, 0.9); - var interpolated1 = unicolour1.InterpolateOklab(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateOklab(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, -0.25, 0.25, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.25, -0.25, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Oklab.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateOklchTests.cs b/Unicolour.Tests/InterpolateOklchTests.cs deleted file mode 100644 index 156883b0..00000000 --- a/Unicolour.Tests/InterpolateOklchTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateOklchTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromOklch(0.5, 0.25, 180, 0.5); - var unicolour2 = Unicolour.FromOklch(0.5, 0.25, 180, 0.5); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateOklch(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateOklch(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, 0.25, 180, 0.5)); - AssertInterpolated(interpolated2, (0.5, 0.25, 180, 0.5)); - AssertInterpolated(interpolated3, (0.5, 0.25, 180, 0.5)); - AssertInterpolated(interpolated4, (0.5, 0.25, 180, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromOklch(0, 0, 0, 0.0); - var unicolour2 = Unicolour.FromOklch(0.5, 0.5, 180); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.25, 90, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.25, 90, 0.5)); - } - - [Test] - public void EquidistantViaZero() - { - var unicolour1 = Unicolour.FromOklch(0, 0, 0, 0); - var unicolour2 = Unicolour.FromOklch(0.8, 0.25, 340, 0.2); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.4, 0.125, 350, 0.1)); - AssertInterpolated(interpolated2, (0.4, 0.125, 350, 0.1)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromOklch(0, 0.5, 0); - var unicolour2 = Unicolour.FromOklch(0.8, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, 0.125, 135, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.375, 45, 0.875)); - } - - [Test] - public void CloserToEndColourViaZero() - { - var unicolour1 = Unicolour.FromOklch(0, 0.5, 300); - var unicolour2 = Unicolour.FromOklch(0.8, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, 0.125, 30, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.375, 330, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromOklch(0, 0.5, 0); - var unicolour2 = Unicolour.FromOklch(0.8, 0, 180, 0.5); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.375, 45, 0.875)); - AssertInterpolated(interpolated2, (0.6, 0.125, 135, 0.625)); - } - - [Test] - public void CloserToStartColourViaZero() - { - var unicolour1 = Unicolour.FromOklch(0, 0.5, 300); - var unicolour2 = Unicolour.FromOklch(0.8, 0, 60, 0.5); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.375, 330, 0.875)); - AssertInterpolated(interpolated2, (0.6, 0.125, 30, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromOklch(0.2, 0.2, 0, 0.8); - var unicolour2 = Unicolour.FromOklch(0.3, 0.3, 90, 0.9); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.35, 135, 0.95)); - AssertInterpolated(interpolated2, (0.15, 0.15, 315, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromOklch(0.2, 0.2, 0, 0.8); - var unicolour2 = Unicolour.FromOklch(0.3, 0.3, 90, 0.9); - var interpolated1 = unicolour1.InterpolateOklch(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateOklch(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, 0.15, 315, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.35, 135, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Oklch.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateRgbTests.cs b/Unicolour.Tests/InterpolateRgbTests.cs deleted file mode 100644 index defddb47..00000000 --- a/Unicolour.Tests/InterpolateRgbTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateRgbTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromRgb(0.5, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromRgb(0.5, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateRgb(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateRgb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (0.5, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromRgb(0.0, 0.0, 0.0, 0.0); - var unicolour2 = Unicolour.FromRgb(0.5, 1.0, 1.0); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.5, 0.5, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromRgb(0, 1, 0); - var unicolour2 = Unicolour.FromRgb(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromRgb(0.0, 1.0, 0.0); - var unicolour2 = Unicolour.FromRgb(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (0.6, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromRgb(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromRgb(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (0.15, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromRgb(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromRgb(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateRgb(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateRgb(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Rgb.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateXyyTests.cs b/Unicolour.Tests/InterpolateXyyTests.cs deleted file mode 100644 index 20831f1c..00000000 --- a/Unicolour.Tests/InterpolateXyyTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateXyyTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromXyy(0.5, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromXyy(0.5, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateXyy(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateXyy(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (0.5, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromXyy(0.0, 0.0, 0.0, 0.0); - var unicolour2 = Unicolour.FromXyy(0.5, 1.0, 1.0); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.5, 0.5, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromXyy(0, 1, 0); - var unicolour2 = Unicolour.FromXyy(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromXyy(0.0, 1.0, 0.0); - var unicolour2 = Unicolour.FromXyy(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (0.6, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromXyy(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromXyy(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (0.15, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromXyy(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromXyy(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateXyy(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateXyy(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Xyy.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateXyzTests.cs b/Unicolour.Tests/InterpolateXyzTests.cs deleted file mode 100644 index 1ae6a411..00000000 --- a/Unicolour.Tests/InterpolateXyzTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Wacton.Unicolour.Tests; - -using NUnit.Framework; -using Wacton.Unicolour.Tests.Utils; - -public class InterpolateXyzTests -{ - [Test] - public void SameColour() - { - var unicolour1 = Unicolour.FromXyz(0.5, 0.25, 0.75, 0.5); - var unicolour2 = Unicolour.FromXyz(0.5, 0.25, 0.75, 0.5); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, 0.75); - var interpolated3 = unicolour1.InterpolateXyz(unicolour2, 0.75); - var interpolated4 = unicolour2.InterpolateXyz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated2, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated3, (0.5, 0.25, 0.75, 0.5)); - AssertInterpolated(interpolated4, (0.5, 0.25, 0.75, 0.5)); - } - - [Test] - public void Equidistant() - { - var unicolour1 = Unicolour.FromXyz(0.0, 0.0, 0.0, 0.0); - var unicolour2 = Unicolour.FromXyz(0.5, 1.0, 1.0); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, 0.5); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, 0.5); - - AssertInterpolated(interpolated1, (0.25, 0.5, 0.5, 0.5)); - AssertInterpolated(interpolated2, (0.25, 0.5, 0.5, 0.5)); - } - - [Test] - public void CloserToEndColour() - { - var unicolour1 = Unicolour.FromXyz(0, 1, 0); - var unicolour2 = Unicolour.FromXyz(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, 0.75); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, 0.75); - - AssertInterpolated(interpolated1, (0.6, 0.25, 0.75, 0.625)); - AssertInterpolated(interpolated2, (0.2, 0.75, 0.25, 0.875)); - } - - [Test] - public void CloserToStartColour() - { - var unicolour1 = Unicolour.FromXyz(0.0, 1.0, 0.0); - var unicolour2 = Unicolour.FromXyz(0.8, 0.0, 1.0, 0.5); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, 0.25); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, 0.25); - - AssertInterpolated(interpolated1, (0.2, 0.75, 0.25, 0.875)); - AssertInterpolated(interpolated2, (0.6, 0.25, 0.75, 0.625)); - } - - [Test] - public void BeyondEndColour() - { - var unicolour1 = Unicolour.FromXyz(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromXyz(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, 1.5); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, 1.5); - - AssertInterpolated(interpolated1, (0.35, 0.7, 0.3, 0.95)); - AssertInterpolated(interpolated2, (0.15, 0.3, 0.7, 0.75)); - } - - [Test] - public void BeyondStartColour() - { - var unicolour1 = Unicolour.FromXyz(0.2, 0.4, 0.6, 0.8); - var unicolour2 = Unicolour.FromXyz(0.3, 0.6, 0.4, 0.9); - var interpolated1 = unicolour1.InterpolateXyz(unicolour2, -0.5); - var interpolated2 = unicolour2.InterpolateXyz(unicolour1, -0.5); - - AssertInterpolated(interpolated1, (0.15, 0.3, 0.7, 0.75)); - AssertInterpolated(interpolated2, (0.35, 0.7, 0.3, 0.95)); - } - - private static void AssertInterpolated(Unicolour unicolour, (double first, double second, double third, double alpha) expected) - { - AssertUtils.AssertInterpolated(unicolour.Xyz.Triplet, unicolour.Alpha.A, expected); - } -} \ No newline at end of file diff --git a/Unicolour.Tests/InvalidInterpolationTests.cs b/Unicolour.Tests/InvalidInterpolationTests.cs index 48832d71..9c64dc35 100644 --- a/Unicolour.Tests/InvalidInterpolationTests.cs +++ b/Unicolour.Tests/InvalidInterpolationTests.cs @@ -16,24 +16,22 @@ public class InvalidInterpolationTests [Test] public void InvalidInterpolationInput() { - Assert.Throws(() => Interpolation.Interpolate(BadColourSpace, unicolour1, unicolour2, 0.5)); + Assert.Throws(() => Interpolation.Mix(BadColourSpace, unicolour1, unicolour2, 0.5)); } [Test] public void InvalidInterpolationOutput() { const string methodName = "GetConstructor"; - var types = new[] { typeof(ColourSpace) }; - AssertDoesNotThrow(() => InvokeMethod(methodName, types, GoodColourSpace)); - AssertThrows(() => InvokeMethod(methodName, types, BadColourSpace)); + AssertDoesNotThrow(() => InvokeMethod(methodName, GoodColourSpace)); + AssertThrows(() => InvokeMethod(methodName, BadColourSpace)); } private static void AssertDoesNotThrow(Action action) => Assert.DoesNotThrow(action.Invoke); private static void AssertThrows(Action action) => Assert.Throws(ExceptionConstraint(), action.Invoke); private static ExactTypeConstraint ExceptionConstraint() => Is.TypeOf().And.InnerException.TypeOf(); - private static void InvokeMethod(string name, Type[] types, params object[] args) => GetPrivateMethod(name, types).Invoke(null, args); - - // need to include types to disambiguate between the multiple private "Interpolate()" functions - private static MethodInfo GetPrivateMethod(string name, Type[] types) => typeof(Interpolation).GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static, types)!; + private static void InvokeMethod(string name, params object[] args) => GetPrivateMethod(name).Invoke(null, args); + + private static MethodInfo GetPrivateMethod(string name) => typeof(Interpolation).GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static)!; } \ No newline at end of file diff --git a/Unicolour.Tests/LazyEvaluationTests.cs b/Unicolour.Tests/LazyEvaluationTests.cs index 1452a44f..d2e3ce2e 100644 --- a/Unicolour.Tests/LazyEvaluationTests.cs +++ b/Unicolour.Tests/LazyEvaluationTests.cs @@ -59,12 +59,12 @@ public void AfterEquality(Func unicolourFunction) } [TestCaseSource(nameof(TestCases))] - public void AfterInterpolation(Func unicolourFunction) + public void AfterMix(Func unicolourFunction) { var unicolour = unicolourFunction(); var other = unicolourFunction(); var initialColourSpace = unicolour.InitialColourSpace; - _ = Interpolation.Interpolate(initialColourSpace, unicolour, other, 0.5); + _ = Interpolation.Mix(initialColourSpace, unicolour, other, 0.5); AssertBackingFields(unicolour); } diff --git a/Unicolour.Tests/MixCam02Tests.cs b/Unicolour.Tests/MixCam02Tests.cs new file mode 100644 index 00000000..90fb6cdd --- /dev/null +++ b/Unicolour.Tests/MixCam02Tests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixCam02Tests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromCam02(50, -25, 25, 0.5); + var unicolour2 = Unicolour.FromCam02(50, -25, 25, 0.5); + var mixed1 = unicolour1.MixCam02(unicolour2, 0.25); + var mixed2 = unicolour2.MixCam02(unicolour1, 0.75); + var mixed3 = unicolour1.MixCam02(unicolour2, 0.75); + var mixed4 = unicolour2.MixCam02(unicolour1, 0.25); + + AssertMixed(mixed1, (50, -25, 25, 0.5)); + AssertMixed(mixed2, (50, -25, 25, 0.5)); + AssertMixed(mixed3, (50, -25, 25, 0.5)); + AssertMixed(mixed4, (50, -25, 25, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromCam02(0, -50, -50, 0.0); + var unicolour2 = Unicolour.FromCam02(50, 50, 50); + var mixed1 = unicolour1.MixCam02(unicolour2, 0.5); + var mixed2 = unicolour2.MixCam02(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 0, 0, 0.5)); + AssertMixed(mixed2, (25, 0, 0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromCam02(0, 50, -50); + var unicolour2 = Unicolour.FromCam02(80, -50, 50, 0.5); + var mixed1 = unicolour1.MixCam02(unicolour2, 0.75); + var mixed2 = unicolour2.MixCam02(unicolour1, 0.75); + + AssertMixed(mixed1, (60, -25, 25, 0.625)); + AssertMixed(mixed2, (20, 25, -25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromCam02(0, 50, -50); + var unicolour2 = Unicolour.FromCam02(80, -50, 50, 0.5); + var mixed1 = unicolour1.MixCam02(unicolour2, 0.25); + var mixed2 = unicolour2.MixCam02(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 25, -25, 0.875)); + AssertMixed(mixed2, (60, -25, 25, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromCam02(20, -10, 10, 0.8); + var unicolour2 = Unicolour.FromCam02(30, 10, -10, 0.9); + var mixed1 = unicolour1.MixCam02(unicolour2, 1.5); + var mixed2 = unicolour2.MixCam02(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 20, -20, 0.95)); + AssertMixed(mixed2, (15, -20, 20, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromCam02(20, -10, 10, 0.8); + var unicolour2 = Unicolour.FromCam02(30, 10, -10, 0.9); + var mixed1 = unicolour1.MixCam02(unicolour2, -0.5); + var mixed2 = unicolour2.MixCam02(unicolour1, -0.5); + + AssertMixed(mixed1, (15, -20, 20, 0.75)); + AssertMixed(mixed2, (35, 20, -20, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Cam02.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixCam16Tests.cs b/Unicolour.Tests/MixCam16Tests.cs new file mode 100644 index 00000000..f99693f3 --- /dev/null +++ b/Unicolour.Tests/MixCam16Tests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixCam16Tests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromCam16(50, -25, 25, 0.5); + var unicolour2 = Unicolour.FromCam16(50, -25, 25, 0.5); + var mixed1 = unicolour1.MixCam16(unicolour2, 0.25); + var mixed2 = unicolour2.MixCam16(unicolour1, 0.75); + var mixed3 = unicolour1.MixCam16(unicolour2, 0.75); + var mixed4 = unicolour2.MixCam16(unicolour1, 0.25); + + AssertMixed(mixed1, (50, -25, 25, 0.5)); + AssertMixed(mixed2, (50, -25, 25, 0.5)); + AssertMixed(mixed3, (50, -25, 25, 0.5)); + AssertMixed(mixed4, (50, -25, 25, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromCam16(0, -50, -50, 0.0); + var unicolour2 = Unicolour.FromCam16(50, 50, 50); + var mixed1 = unicolour1.MixCam16(unicolour2, 0.5); + var mixed2 = unicolour2.MixCam16(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 0, 0, 0.5)); + AssertMixed(mixed2, (25, 0, 0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromCam16(0, 50, -50); + var unicolour2 = Unicolour.FromCam16(80, -50, 50, 0.5); + var mixed1 = unicolour1.MixCam16(unicolour2, 0.75); + var mixed2 = unicolour2.MixCam16(unicolour1, 0.75); + + AssertMixed(mixed1, (60, -25, 25, 0.625)); + AssertMixed(mixed2, (20, 25, -25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromCam16(0, 50, -50); + var unicolour2 = Unicolour.FromCam16(80, -50, 50, 0.5); + var mixed1 = unicolour1.MixCam16(unicolour2, 0.25); + var mixed2 = unicolour2.MixCam16(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 25, -25, 0.875)); + AssertMixed(mixed2, (60, -25, 25, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromCam16(20, -10, 10, 0.8); + var unicolour2 = Unicolour.FromCam16(30, 10, -10, 0.9); + var mixed1 = unicolour1.MixCam16(unicolour2, 1.5); + var mixed2 = unicolour2.MixCam16(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 20, -20, 0.95)); + AssertMixed(mixed2, (15, -20, 20, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromCam16(20, -10, 10, 0.8); + var unicolour2 = Unicolour.FromCam16(30, 10, -10, 0.9); + var mixed1 = unicolour1.MixCam16(unicolour2, -0.5); + var mixed2 = unicolour2.MixCam16(unicolour1, -0.5); + + AssertMixed(mixed1, (15, -20, 20, 0.75)); + AssertMixed(mixed2, (35, 20, -20, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Cam16.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateConfigurationTests.cs b/Unicolour.Tests/MixConfigurationTests.cs similarity index 79% rename from Unicolour.Tests/InterpolateConfigurationTests.cs rename to Unicolour.Tests/MixConfigurationTests.cs index 3bfc2288..167ab8a1 100644 --- a/Unicolour.Tests/InterpolateConfigurationTests.cs +++ b/Unicolour.Tests/MixConfigurationTests.cs @@ -3,7 +3,7 @@ namespace Wacton.Unicolour.Tests; using System; using NUnit.Framework; -public class InterpolateConfigurationTests +public class MixConfigurationTests { [Test] public void UndefinedConfig() @@ -48,18 +48,18 @@ private static Configuration GetConfig() private static void AssertNoError(Unicolour unicolour1, Unicolour unicolour2) { Assert.That(unicolour1.Config.Id, Is.EqualTo(unicolour2.Config.Id)); - Assert.DoesNotThrow(() => unicolour1.InterpolateRgb(unicolour2, 0.5)); - Assert.DoesNotThrow(() => unicolour2.InterpolateRgb(unicolour1, 0.5)); - Assert.DoesNotThrow(() => unicolour1.InterpolateHsb(unicolour2, 0.5)); - Assert.DoesNotThrow(() => unicolour2.InterpolateHsb(unicolour1, 0.5)); + Assert.DoesNotThrow(() => unicolour1.MixRgb(unicolour2, 0.5)); + Assert.DoesNotThrow(() => unicolour2.MixRgb(unicolour1, 0.5)); + Assert.DoesNotThrow(() => unicolour1.MixHsb(unicolour2, 0.5)); + Assert.DoesNotThrow(() => unicolour2.MixHsb(unicolour1, 0.5)); } private static void AssertError(Unicolour unicolour1, Unicolour unicolour2) { Assert.That(unicolour1.Config.Id, Is.Not.EqualTo(unicolour2.Config.Id)); - Assert.Throws(() => unicolour1.InterpolateRgb(unicolour2, 0.5)); - Assert.Throws(() => unicolour2.InterpolateRgb(unicolour1, 0.5)); - Assert.Throws(() => unicolour1.InterpolateHsb(unicolour2, 0.5)); - Assert.Throws(() => unicolour2.InterpolateHsb(unicolour1, 0.5)); + Assert.Throws(() => unicolour1.MixRgb(unicolour2, 0.5)); + Assert.Throws(() => unicolour2.MixRgb(unicolour1, 0.5)); + Assert.Throws(() => unicolour1.MixHsb(unicolour2, 0.5)); + Assert.Throws(() => unicolour2.MixHsb(unicolour1, 0.5)); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHctTests.cs b/Unicolour.Tests/MixGreyscaleHctTests.cs similarity index 80% rename from Unicolour.Tests/InterpolateGreyscaleHctTests.cs rename to Unicolour.Tests/MixGreyscaleHctTests.cs index 2c50d760..2263fdd9 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHctTests.cs +++ b/Unicolour.Tests/MixGreyscaleHctTests.cs @@ -6,9 +6,9 @@ namespace Wacton.Unicolour.Tests; // note: HCT is a composite of LAB & CAM16, therefore there is no obvious cartesian/hueless space to compare against // so using RGB to generate non-HCT greyscales // ---------- -// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale HCT has a hue so it should be used (it just can't be seen until there is some chroma & tone) -public class InterpolateGreyscaleHctTests +public class MixGreyscaleHctTests { private const double RgbWhiteChroma = 2.8690369750685738; @@ -21,17 +21,17 @@ public void GreyscaleStartColour() var hctWhite = Unicolour.FromHct(180, 100, 100); // full tone = white var green = Unicolour.FromHct(120, 100, 50); - var fromRgbBlack = rgbBlack.InterpolateHct(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHct(green, 0.5); - var fromHctBlack = hctBlack.InterpolateHct(green, 0.5); - var fromHctWhite = hctWhite.InterpolateHct(green, 0.5); + var fromRgbBlack = rgbBlack.MixHct(green, 0.5); + var fromRgbWhite = rgbWhite.MixHct(green, 0.5); + var fromHctBlack = hctBlack.MixHct(green, 0.5); + var fromHctWhite = hctWhite.MixHct(green, 0.5); // no obvious way to create known HCT value when starting from non-HCT space // so need to calculate what the expected Chroma will be for RGB-white // however, not really a problem as this test focuses on hue const double expectedFromRgbWhiteChroma = (RgbWhiteChroma + 100) * 0.5; - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromRgbBlack.Hct.Triplet, new(120, 50, 25)); AssertTriplet(fromRgbWhite.Hct.Triplet, new(120, expectedFromRgbWhiteChroma, 75)); AssertTriplet(fromHctBlack.Hct.Triplet, new(150, 100, 25)); @@ -47,17 +47,17 @@ public void GreyscaleEndColour() var hctWhite = Unicolour.FromHct(180, 100, 100); // full tone = white var blue = Unicolour.FromHct(240, 100, 50); - var toRgbBlack = blue.InterpolateHct(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHct(rgbWhite, 0.5); - var toHctBlack = blue.InterpolateHct(hctBlack, 0.5); - var toHctWhite = blue.InterpolateHct(hctWhite, 0.5); + var toRgbBlack = blue.MixHct(rgbBlack, 0.5); + var toRgbWhite = blue.MixHct(rgbWhite, 0.5); + var toHctBlack = blue.MixHct(hctBlack, 0.5); + var toHctWhite = blue.MixHct(hctWhite, 0.5); // no obvious way to create known HCT value when starting from non-HCT space // so need to calculate what the expected Chroma will be for RGB-white // however, not really a problem as this test focuses on hue const double expectedFromRgbWhiteChroma = (RgbWhiteChroma + 100) * 0.5; - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toRgbBlack.Hct.Triplet, new(240, 50, 25)); AssertTriplet(toRgbWhite.Hct.Triplet, new(240, expectedFromRgbWhiteChroma, 75)); AssertTriplet(toHctBlack.Hct.Triplet, new(210, 100, 25)); @@ -74,9 +74,9 @@ public void GreyscaleBothRgbColours() var white = Unicolour.FromRgb(1, 1, 1); var grey = Unicolour.FromRgb(0.5, 0.5, 0.5); - var blackToWhite = black.InterpolateHct(white, 0.5); - var blackToGrey = black.InterpolateHct(grey, 0.5); - var whiteToGrey = white.InterpolateHct(grey, 0.5); + var blackToWhite = black.MixHct(white, 0.5); + var blackToGrey = black.MixHct(grey, 0.5); + var whiteToGrey = white.MixHct(grey, 0.5); // colours created from RGB therefore hue does not change // (except for HCT for RGB-black, which converts to a different hue than other greyscales) @@ -96,9 +96,9 @@ public void GreyscaleBothHctColours() var white = Unicolour.FromHct(300, 0, 100); var grey = Unicolour.FromHct(100, 0, 50); - var blackToWhite = black.InterpolateHct(white, 0.5); - var blackToGrey = black.InterpolateHct(grey, 0.5); - var whiteToGrey = white.InterpolateHct(grey, 0.5); + var blackToWhite = black.MixHct(white, 0.5); + var blackToGrey = black.MixHct(grey, 0.5); + var whiteToGrey = white.MixHct(grey, 0.5); AssertGrey(blackToWhite.Rgb); AssertGrey(blackToGrey.Rgb); @@ -109,11 +109,6 @@ public void GreyscaleBothHctColours() AssertTriplet(blackToGrey.Hct.Triplet, new(50, 0, 25)); AssertTriplet(whiteToGrey.Hct.Triplet, new(20, 0, 75)); } - - private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) - { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); - } private static void AssertGrey(Rgb rgb) { @@ -121,4 +116,9 @@ private static void AssertGrey(Rgb rgb) Assert.That(rgb.G, Is.EqualTo(rgb.B).Within(0.05)); Assert.That(rgb.B, Is.EqualTo(rgb.R).Within(0.05)); } + + private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) + { + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); + } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHpluvTests.cs b/Unicolour.Tests/MixGreyscaleHpluvTests.cs similarity index 74% rename from Unicolour.Tests/InterpolateGreyscaleHpluvTests.cs rename to Unicolour.Tests/MixGreyscaleHpluvTests.cs index c007ad3c..fa900017 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHpluvTests.cs +++ b/Unicolour.Tests/MixGreyscaleHpluvTests.cs @@ -6,9 +6,9 @@ namespace Wacton.Unicolour.Tests; // note: HPLuv is a transformation from LCHuv, therefore there is no obvious cartesian/hueless space to compare against // so using RGB for greyscale -> colour behaviour, and LUV for greyscale -> greyscale behaviour // ---------- -// greyscale RGB & LUV have no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale RGB & LUV have no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale HPLuv has a hue so it should be used (it just can't be seen until there is some saturation & lightness) -public class InterpolateGreyscaleHpluvTests +public class MixGreyscaleHpluvTests { [Test] public void GreyscaleStartColour() @@ -19,12 +19,12 @@ public void GreyscaleStartColour() var hpluvWhite = Unicolour.FromHpluv(180, 0, 100); // no saturation = greyscale var green = Unicolour.FromHpluv(120, 100, 50); - var fromRgbBlack = rgbBlack.InterpolateHpluv(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHpluv(green, 0.5); - var fromHpluvBlack = hpluvBlack.InterpolateHpluv(green, 0.5); - var fromHpluvWhite = hpluvWhite.InterpolateHpluv(green, 0.5); + var fromRgbBlack = rgbBlack.MixHpluv(green, 0.5); + var fromRgbWhite = rgbWhite.MixHpluv(green, 0.5); + var fromHpluvBlack = hpluvBlack.MixHpluv(green, 0.5); + var fromHpluvWhite = hpluvWhite.MixHpluv(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromRgbBlack.Hpluv.Triplet, new(120, 50, 25)); AssertTriplet(fromRgbWhite.Hpluv.Triplet, new(120, 50, 75)); AssertTriplet(fromHpluvBlack.Hpluv.Triplet, new(150, 100, 25)); @@ -40,12 +40,12 @@ public void GreyscaleEndColour() var hpluvWhite = Unicolour.FromHpluv(180, 0, 100); // no saturation = greyscale var blue = Unicolour.FromHpluv(240, 100, 50); - var toRgbBlack = blue.InterpolateHpluv(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHpluv(rgbWhite, 0.5); - var toHpluvBlack = blue.InterpolateHpluv(hpluvBlack, 0.5); - var toHpluvWhite = blue.InterpolateHpluv(hpluvWhite, 0.5); + var toRgbBlack = blue.MixHpluv(rgbBlack, 0.5); + var toRgbWhite = blue.MixHpluv(rgbWhite, 0.5); + var toHpluvBlack = blue.MixHpluv(hpluvBlack, 0.5); + var toHpluvWhite = blue.MixHpluv(hpluvWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toRgbBlack.Hpluv.Triplet, new(240, 50, 25)); AssertTriplet(toRgbWhite.Hpluv.Triplet, new(240, 50, 75)); AssertTriplet(toHpluvBlack.Hpluv.Triplet, new(210, 100, 25)); @@ -59,9 +59,9 @@ public void GreyscaleBothLuvColours() var white = Unicolour.FromLuv(100, 0, 0); var grey = Unicolour.FromLuv(50, 0, 0); - var blackToWhite = black.InterpolateHpluv(white, 0.5); - var blackToGrey = black.InterpolateHpluv(grey, 0.5); - var whiteToGrey = white.InterpolateHpluv(grey, 0.5); + var blackToWhite = black.MixHpluv(white, 0.5); + var blackToGrey = black.MixHpluv(grey, 0.5); + var whiteToGrey = white.MixHpluv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -80,9 +80,9 @@ public void GreyscaleBothHpluvColours() var white = Unicolour.FromHpluv(300, 0, 100); var grey = Unicolour.FromHpluv(100, 0, 50); - var blackToWhite = black.InterpolateHpluv(white, 0.5); - var blackToGrey = black.InterpolateHpluv(grey, 0.5); - var whiteToGrey = white.InterpolateHpluv(grey, 0.5); + var blackToWhite = black.MixHpluv(white, 0.5); + var blackToGrey = black.MixHpluv(grey, 0.5); + var whiteToGrey = white.MixHpluv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -93,9 +93,9 @@ public void GreyscaleBothHpluvColours() AssertTriplet(blackToGrey.Lchuv.Triplet, new(25, 0, 50)); AssertTriplet(whiteToGrey.Lchuv.Triplet, new(75, 0, 20)); } - + private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHsbTests.cs b/Unicolour.Tests/MixGreyscaleHsbTests.cs similarity index 74% rename from Unicolour.Tests/InterpolateGreyscaleHsbTests.cs rename to Unicolour.Tests/MixGreyscaleHsbTests.cs index 1a1ac2e8..a9cd4446 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHsbTests.cs +++ b/Unicolour.Tests/MixGreyscaleHsbTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale HSB has a hue so it should be used (it just can't be seen until there is some saturation & brightness) -public class InterpolateGreyscaleHsbTests +public class MixGreyscaleHsbTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var hsbWhite = Unicolour.FromHsb(180, 0, 1); // no saturation = greyscale var green = Unicolour.FromHsb(120, 1, 1); - var fromRgbBlack = rgbBlack.InterpolateHsb(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHsb(green, 0.5); - var fromHsbBlack = hsbBlack.InterpolateHsb(green, 0.5); - var fromHsbWhite = hsbWhite.InterpolateHsb(green, 0.5); + var fromRgbBlack = rgbBlack.MixHsb(green, 0.5); + var fromRgbWhite = rgbWhite.MixHsb(green, 0.5); + var fromHsbBlack = hsbBlack.MixHsb(green, 0.5); + var fromHsbWhite = hsbWhite.MixHsb(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromRgbBlack.Hsb.Triplet, new(120, 0.5, 0.5)); AssertTriplet(fromRgbWhite.Hsb.Triplet, new(120, 0.5, 1)); AssertTriplet(fromHsbBlack.Hsb.Triplet, new(150, 1, 0.5)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var hsbWhite = Unicolour.FromHsb(180, 0, 1); // no saturation = greyscale var blue = Unicolour.FromHsb(240, 1, 1); - var toRgbBlack = blue.InterpolateHsb(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHsb(rgbWhite, 0.5); - var toHsbBlack = blue.InterpolateHsb(hsbBlack, 0.5); - var toHsbWhite = blue.InterpolateHsb(hsbWhite, 0.5); + var toRgbBlack = blue.MixHsb(rgbBlack, 0.5); + var toRgbWhite = blue.MixHsb(rgbWhite, 0.5); + var toHsbBlack = blue.MixHsb(hsbBlack, 0.5); + var toHsbWhite = blue.MixHsb(hsbWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toRgbBlack.Hsb.Triplet, new(240, 0.5, 0.5)); AssertTriplet(toRgbWhite.Hsb.Triplet, new(240, 0.5, 1)); AssertTriplet(toHsbBlack.Hsb.Triplet, new(210, 1, 0.5)); @@ -56,9 +56,9 @@ public void GreyscaleBothRgbColours() var white = Unicolour.FromRgb(1.0, 1.0, 1.0); var grey = Unicolour.FromRgb(0.5, 0.5, 0.5); - var blackToWhite = black.InterpolateHsb(white, 0.5); - var blackToGrey = black.InterpolateHsb(grey, 0.5); - var whiteToGrey = white.InterpolateHsb(grey, 0.5); + var blackToWhite = black.MixHsb(white, 0.5); + var blackToGrey = black.MixHsb(grey, 0.5); + var whiteToGrey = white.MixHsb(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -77,9 +77,9 @@ public void GreyscaleBothHsbColours() var white = Unicolour.FromHsb(300, 0, 1.0); var grey = Unicolour.FromHsb(100, 0, 0.5); - var blackToWhite = black.InterpolateHsb(white, 0.5); - var blackToGrey = black.InterpolateHsb(grey, 0.5); - var whiteToGrey = white.InterpolateHsb(grey, 0.5); + var blackToWhite = black.MixHsb(white, 0.5); + var blackToGrey = black.MixHsb(grey, 0.5); + var whiteToGrey = white.MixHsb(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -93,6 +93,6 @@ public void GreyscaleBothHsbColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHslTests.cs b/Unicolour.Tests/MixGreyscaleHslTests.cs similarity index 74% rename from Unicolour.Tests/InterpolateGreyscaleHslTests.cs rename to Unicolour.Tests/MixGreyscaleHslTests.cs index 19754b2c..2362ffa8 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHslTests.cs +++ b/Unicolour.Tests/MixGreyscaleHslTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale HSL has a hue so it should be used (it just can't be seen until there is some saturation & lightness) -public class InterpolateGreyscaleHslTests +public class MixGreyscaleHslTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var hslWhite = Unicolour.FromHsl(180, 0, 1); // no saturation = greyscale var green = Unicolour.FromHsl(120, 1, 0.5); - var fromRgbBlack = rgbBlack.InterpolateHsl(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHsl(green, 0.5); - var fromHslBlack = hslBlack.InterpolateHsl(green, 0.5); - var fromHslWhite = hslWhite.InterpolateHsl(green, 0.5); + var fromRgbBlack = rgbBlack.MixHsl(green, 0.5); + var fromRgbWhite = rgbWhite.MixHsl(green, 0.5); + var fromHslBlack = hslBlack.MixHsl(green, 0.5); + var fromHslWhite = hslWhite.MixHsl(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromRgbBlack.Hsl.Triplet, new(120, 0.5, 0.25)); AssertTriplet(fromRgbWhite.Hsl.Triplet, new(120, 0.5, 0.75)); AssertTriplet(fromHslBlack.Hsl.Triplet, new(150, 1, 0.25)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var hslWhite = Unicolour.FromHsl(180, 0, 1); // no saturation = greyscale var blue = Unicolour.FromHsl(240, 1, 0.5); - var toRgbBlack = blue.InterpolateHsl(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHsl(rgbWhite, 0.5); - var toHslBlack = blue.InterpolateHsl(hslBlack, 0.5); - var toHslWhite = blue.InterpolateHsl(hslWhite, 0.5); + var toRgbBlack = blue.MixHsl(rgbBlack, 0.5); + var toRgbWhite = blue.MixHsl(rgbWhite, 0.5); + var toHslBlack = blue.MixHsl(hslBlack, 0.5); + var toHslWhite = blue.MixHsl(hslWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toRgbBlack.Hsl.Triplet, new(240, 0.5, 0.25)); AssertTriplet(toRgbWhite.Hsl.Triplet, new(240, 0.5, 0.75)); AssertTriplet(toHslBlack.Hsl.Triplet, new(210, 1, 0.25)); @@ -56,9 +56,9 @@ public void GreyscaleBothRgbColours() var white = Unicolour.FromRgb(1.0, 1.0, 1.0); var grey = Unicolour.FromRgb(0.5, 0.5, 0.5); - var blackToWhite = black.InterpolateHsl(white, 0.5); - var blackToGrey = black.InterpolateHsl(grey, 0.5); - var whiteToGrey = white.InterpolateHsl(grey, 0.5); + var blackToWhite = black.MixHsl(white, 0.5); + var blackToGrey = black.MixHsl(grey, 0.5); + var whiteToGrey = white.MixHsl(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -77,9 +77,9 @@ public void GreyscaleBothHslColours() var white = Unicolour.FromHsl(300, 0, 1.0); var grey = Unicolour.FromHsl(100, 0, 0.5); - var blackToWhite = black.InterpolateHsl(white, 0.5); - var blackToGrey = black.InterpolateHsl(grey, 0.5); - var whiteToGrey = white.InterpolateHsl(grey, 0.5); + var blackToWhite = black.MixHsl(white, 0.5); + var blackToGrey = black.MixHsl(grey, 0.5); + var whiteToGrey = white.MixHsl(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -93,6 +93,6 @@ public void GreyscaleBothHslColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHsluvTests.cs b/Unicolour.Tests/MixGreyscaleHsluvTests.cs similarity index 74% rename from Unicolour.Tests/InterpolateGreyscaleHsluvTests.cs rename to Unicolour.Tests/MixGreyscaleHsluvTests.cs index c177e398..be7bf8d9 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHsluvTests.cs +++ b/Unicolour.Tests/MixGreyscaleHsluvTests.cs @@ -6,9 +6,9 @@ namespace Wacton.Unicolour.Tests; // note: HSLuv is a transformation from LCHuv, therefore there is no obvious cartesian/hueless space to compare against // so using RGB for greyscale -> colour behaviour, and LUV for greyscale -> greyscale behaviour // ---------- -// greyscale RGB & LUV have no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale RGB & LUV have no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale HSLuv has a hue so it should be used (it just can't be seen until there is some saturation & lightness) -public class InterpolateGreyscaleHsluvTests +public class MixGreyscaleHsluvTests { [Test] public void GreyscaleStartColour() @@ -19,12 +19,12 @@ public void GreyscaleStartColour() var hsluvWhite = Unicolour.FromHsluv(180, 0, 100); // no saturation = greyscale var green = Unicolour.FromHsluv(120, 100, 50); - var fromRgbBlack = rgbBlack.InterpolateHsluv(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHsluv(green, 0.5); - var fromHsluvBlack = hsluvBlack.InterpolateHsluv(green, 0.5); - var fromHsluvWhite = hsluvWhite.InterpolateHsluv(green, 0.5); + var fromRgbBlack = rgbBlack.MixHsluv(green, 0.5); + var fromRgbWhite = rgbWhite.MixHsluv(green, 0.5); + var fromHsluvBlack = hsluvBlack.MixHsluv(green, 0.5); + var fromHsluvWhite = hsluvWhite.MixHsluv(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromRgbBlack.Hsluv.Triplet, new(120, 50, 25)); AssertTriplet(fromRgbWhite.Hsluv.Triplet, new(120, 50, 75)); AssertTriplet(fromHsluvBlack.Hsluv.Triplet, new(150, 100, 25)); @@ -40,12 +40,12 @@ public void GreyscaleEndColour() var hsluvWhite = Unicolour.FromHsluv(180, 0, 100); // no saturation = greyscale var blue = Unicolour.FromHsluv(240, 100, 50); - var toRgbBlack = blue.InterpolateHsluv(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHsluv(rgbWhite, 0.5); - var toHsluvBlack = blue.InterpolateHsluv(hsluvBlack, 0.5); - var toHsluvWhite = blue.InterpolateHsluv(hsluvWhite, 0.5); + var toRgbBlack = blue.MixHsluv(rgbBlack, 0.5); + var toRgbWhite = blue.MixHsluv(rgbWhite, 0.5); + var toHsluvBlack = blue.MixHsluv(hsluvBlack, 0.5); + var toHsluvWhite = blue.MixHsluv(hsluvWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toRgbBlack.Hsluv.Triplet, new(240, 50, 25)); AssertTriplet(toRgbWhite.Hsluv.Triplet, new(240, 50, 75)); AssertTriplet(toHsluvBlack.Hsluv.Triplet, new(210, 100, 25)); @@ -59,9 +59,9 @@ public void GreyscaleBothLuvColours() var white = Unicolour.FromLuv(100, 0, 0); var grey = Unicolour.FromLuv(50, 0, 0); - var blackToWhite = black.InterpolateHsluv(white, 0.5); - var blackToGrey = black.InterpolateHsluv(grey, 0.5); - var whiteToGrey = white.InterpolateHsluv(grey, 0.5); + var blackToWhite = black.MixHsluv(white, 0.5); + var blackToGrey = black.MixHsluv(grey, 0.5); + var whiteToGrey = white.MixHsluv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -80,9 +80,9 @@ public void GreyscaleBothHsluvColours() var white = Unicolour.FromHsluv(300, 0, 100); var grey = Unicolour.FromHsluv(100, 0, 50); - var blackToWhite = black.InterpolateHsluv(white, 0.5); - var blackToGrey = black.InterpolateHsluv(grey, 0.5); - var whiteToGrey = white.InterpolateHsluv(grey, 0.5); + var blackToWhite = black.MixHsluv(white, 0.5); + var blackToGrey = black.MixHsluv(grey, 0.5); + var whiteToGrey = white.MixHsluv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -93,9 +93,9 @@ public void GreyscaleBothHsluvColours() AssertTriplet(blackToGrey.Lchuv.Triplet, new(25, 0, 50)); AssertTriplet(whiteToGrey.Lchuv.Triplet, new(75, 0, 20)); } - + private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleHwbTests.cs b/Unicolour.Tests/MixGreyscaleHwbTests.cs similarity index 74% rename from Unicolour.Tests/InterpolateGreyscaleHwbTests.cs rename to Unicolour.Tests/MixGreyscaleHwbTests.cs index d6f4d05f..0d9544c8 100644 --- a/Unicolour.Tests/InterpolateGreyscaleHwbTests.cs +++ b/Unicolour.Tests/MixGreyscaleHwbTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale RGB has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// 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 InterpolateGreyscaleHwbTests +public class MixGreyscaleHwbTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var hwbWhite = Unicolour.FromHwb(180, 1, 0); // full whiteness = white var green = Unicolour.FromHwb(120, 0, 0); - var fromRgbBlack = rgbBlack.InterpolateHwb(green, 0.5); - var fromRgbWhite = rgbWhite.InterpolateHwb(green, 0.5); - var fromHwbBlack = hwbBlack.InterpolateHwb(green, 0.5); - var fromHwbWhite = hwbWhite.InterpolateHwb(green, 0.5); + var fromRgbBlack = rgbBlack.MixHwb(green, 0.5); + var fromRgbWhite = rgbWhite.MixHwb(green, 0.5); + var fromHwbBlack = hwbBlack.MixHwb(green, 0.5); + var fromHwbWhite = hwbWhite.MixHwb(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // 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)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var hwbWhite = Unicolour.FromHwb(180, 1, 0); // full whiteness = white var blue = Unicolour.FromHwb(240, 0, 0); - var toRgbBlack = blue.InterpolateHwb(rgbBlack, 0.5); - var toRgbWhite = blue.InterpolateHwb(rgbWhite, 0.5); - var toHwbBlack = blue.InterpolateHwb(hwbBlack, 0.5); - var toHwbWhite = blue.InterpolateHwb(hwbWhite, 0.5); + var toRgbBlack = blue.MixHwb(rgbBlack, 0.5); + var toRgbWhite = blue.MixHwb(rgbWhite, 0.5); + var toHwbBlack = blue.MixHwb(hwbBlack, 0.5); + var toHwbWhite = blue.MixHwb(hwbWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // 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)); @@ -56,9 +56,9 @@ public void GreyscaleBothRgbColours() var white = Unicolour.FromRgb(1.0, 1.0, 1.0); var grey = Unicolour.FromRgb(0.5, 0.5, 0.5); - var blackToWhite = black.InterpolateHwb(white, 0.5); - var blackToGrey = black.InterpolateHwb(grey, 0.5); - var whiteToGrey = white.InterpolateHwb(grey, 0.5); + var blackToWhite = black.MixHwb(white, 0.5); + var blackToGrey = black.MixHwb(grey, 0.5); + var whiteToGrey = white.MixHwb(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -77,9 +77,9 @@ public void GreyscaleBothHwbColours() var white = Unicolour.FromHwb(300, 1.0, 0); var grey = Unicolour.FromHwb(100, 0.5, 0.5); - var blackToWhite = black.InterpolateHwb(white, 0.5); - var blackToGrey = black.InterpolateHwb(grey, 0.5); - var whiteToGrey = white.InterpolateHwb(grey, 0.5); + var blackToWhite = black.MixHwb(white, 0.5); + var blackToGrey = black.MixHwb(grey, 0.5); + var whiteToGrey = white.MixHwb(grey, 0.5); AssertTriplet(blackToWhite.Rgb.Triplet, new(0.5, 0.5, 0.5)); AssertTriplet(blackToGrey.Rgb.Triplet, new(0.25, 0.25, 0.25)); @@ -93,6 +93,6 @@ public void GreyscaleBothHwbColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleJzczhzTests.cs b/Unicolour.Tests/MixGreyscaleJzczhzTests.cs similarity index 73% rename from Unicolour.Tests/InterpolateGreyscaleJzczhzTests.cs rename to Unicolour.Tests/MixGreyscaleJzczhzTests.cs index 6106865e..f99ece04 100644 --- a/Unicolour.Tests/InterpolateGreyscaleJzczhzTests.cs +++ b/Unicolour.Tests/MixGreyscaleJzczhzTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale Jzazbz has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// 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 InterpolateGreyscaleJzczhzTests +public class MixGreyscaleJzczhzTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var jchWhite = Unicolour.FromJzczhz(1, 0.5, 180); // full lightness = white var green = Unicolour.FromJzczhz(0.5, 0.5, 120); - var fromJabBlack = jabBlack.InterpolateJzczhz(green, 0.5); - var fromJabWhite = jabWhite.InterpolateJzczhz(green, 0.5); - var fromJchBlack = jchBlack.InterpolateJzczhz(green, 0.5); - var fromJchWhite = jchWhite.InterpolateJzczhz(green, 0.5); + var fromJabBlack = jabBlack.MixJzczhz(green, 0.5); + var fromJabWhite = jabWhite.MixJzczhz(green, 0.5); + var fromJchBlack = jchBlack.MixJzczhz(green, 0.5); + var fromJchWhite = jchWhite.MixJzczhz(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // 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)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var jcWhite = Unicolour.FromJzczhz(1, 0.5, 180); // full lightness = white var blue = Unicolour.FromJzczhz(0.5, 0.5, 240); - var toJzazbzBlack = blue.InterpolateJzczhz(jabBlack, 0.5); - var toJzazbzWhite = blue.InterpolateJzczhz(jabWhite, 0.5); - var toJzczhzBlack = blue.InterpolateJzczhz(jchBlack, 0.5); - var toJzczhzWhite = blue.InterpolateJzczhz(jcWhite, 0.5); + var toJzazbzBlack = blue.MixJzczhz(jabBlack, 0.5); + var toJzazbzWhite = blue.MixJzczhz(jabWhite, 0.5); + var toJzczhzBlack = blue.MixJzczhz(jchBlack, 0.5); + var toJzczhzWhite = blue.MixJzczhz(jcWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // 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)); @@ -56,9 +56,9 @@ public void GreyscaleBothJzazbzColours() var white = Unicolour.FromJzazbz(1, 0, 0); var grey = Unicolour.FromJzazbz(0.5, 0, 0); - var blackToWhite = black.InterpolateJzczhz(white, 0.5); - var blackToGrey = black.InterpolateJzczhz(grey, 0.5); - var whiteToGrey = white.InterpolateJzczhz(grey, 0.5); + var blackToWhite = black.MixJzczhz(white, 0.5); + var blackToGrey = black.MixJzczhz(grey, 0.5); + var whiteToGrey = white.MixJzczhz(grey, 0.5); AssertTriplet(blackToWhite.Jzazbz.Triplet, new(0.5, 0, 0)); AssertTriplet(blackToGrey.Jzazbz.Triplet, new(0.25, 0, 0)); @@ -77,9 +77,9 @@ public void GreyscaleBothJzczhzColours() var white = Unicolour.FromJzczhz(1, 0, 300); var grey = Unicolour.FromJzczhz(0.5, 0, 100); - var blackToWhite = black.InterpolateJzczhz(white, 0.5); - var blackToGrey = black.InterpolateJzczhz(grey, 0.5); - var whiteToGrey = white.InterpolateJzczhz(grey, 0.5); + var blackToWhite = black.MixJzczhz(white, 0.5); + var blackToGrey = black.MixJzczhz(grey, 0.5); + var whiteToGrey = white.MixJzczhz(grey, 0.5); AssertTriplet(blackToWhite.Jzazbz.Triplet, new(0.5, 0, 0)); AssertTriplet(blackToGrey.Jzazbz.Triplet, new(0.25, 0, 0)); @@ -93,6 +93,6 @@ public void GreyscaleBothJzczhzColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleLchabTests.cs b/Unicolour.Tests/MixGreyscaleLchabTests.cs similarity index 73% rename from Unicolour.Tests/InterpolateGreyscaleLchabTests.cs rename to Unicolour.Tests/MixGreyscaleLchabTests.cs index 4ca38fe3..94949211 100644 --- a/Unicolour.Tests/InterpolateGreyscaleLchabTests.cs +++ b/Unicolour.Tests/MixGreyscaleLchabTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale LAB has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale LAB has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale LCHab has a hue so it should be used (it just can't be seen until there is some lightness & chroma) -public class InterpolateGreyscaleLchabTests +public class MixGreyscaleLchabTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var lchabWhite = Unicolour.FromLchab(100, 100, 180); // full lightness = white var green = Unicolour.FromLchab(50, 100, 120); - var fromLabBlack = labBlack.InterpolateLchab(green, 0.5); - var fromLabWhite = labWhite.InterpolateLchab(green, 0.5); - var fromLchabBlack = lchabBlack.InterpolateLchab(green, 0.5); - var fromLchabWhite = lchabWhite.InterpolateLchab(green, 0.5); + var fromLabBlack = labBlack.MixLchab(green, 0.5); + var fromLabWhite = labWhite.MixLchab(green, 0.5); + var fromLchabBlack = lchabBlack.MixLchab(green, 0.5); + var fromLchabWhite = lchabWhite.MixLchab(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromLabBlack.Lchab.Triplet, new(25, 50, 120)); AssertTriplet(fromLabWhite.Lchab.Triplet, new(75, 50, 120)); AssertTriplet(fromLchabBlack.Lchab.Triplet, new(25, 100, 150)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var lchabWhite = Unicolour.FromLchab(100, 100, 180); // full lightness = white var blue = Unicolour.FromLchab(50, 100, 240); - var toLabBlack = blue.InterpolateLchab(labBlack, 0.5); - var toLabWhite = blue.InterpolateLchab(labWhite, 0.5); - var toLchabBlack = blue.InterpolateLchab(lchabBlack, 0.5); - var toLchabWhite = blue.InterpolateLchab(lchabWhite, 0.5); + var toLabBlack = blue.MixLchab(labBlack, 0.5); + var toLabWhite = blue.MixLchab(labWhite, 0.5); + var toLchabBlack = blue.MixLchab(lchabBlack, 0.5); + var toLchabWhite = blue.MixLchab(lchabWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toLabBlack.Lchab.Triplet, new(25, 50, 240)); AssertTriplet(toLabWhite.Lchab.Triplet, new(75, 50, 240)); AssertTriplet(toLchabBlack.Lchab.Triplet, new(25, 100, 210)); @@ -56,9 +56,9 @@ public void GreyscaleBothLabColours() var white = Unicolour.FromLab(100, 0, 0); var grey = Unicolour.FromLab(50, 0, 0); - var blackToWhite = black.InterpolateLchab(white, 0.5); - var blackToGrey = black.InterpolateLchab(grey, 0.5); - var whiteToGrey = white.InterpolateLchab(grey, 0.5); + var blackToWhite = black.MixLchab(white, 0.5); + var blackToGrey = black.MixLchab(grey, 0.5); + var whiteToGrey = white.MixLchab(grey, 0.5); AssertTriplet(blackToWhite.Lab.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Lab.Triplet, new(25, 0, 0)); @@ -77,9 +77,9 @@ public void GreyscaleBothLchabColours() var white = Unicolour.FromLchab(100, 0, 300); var grey = Unicolour.FromLchab(50, 0, 100); - var blackToWhite = black.InterpolateLchab(white, 0.5); - var blackToGrey = black.InterpolateLchab(grey, 0.5); - var whiteToGrey = white.InterpolateLchab(grey, 0.5); + var blackToWhite = black.MixLchab(white, 0.5); + var blackToGrey = black.MixLchab(grey, 0.5); + var whiteToGrey = white.MixLchab(grey, 0.5); AssertTriplet(blackToWhite.Lab.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Lab.Triplet, new(25, 0, 0)); @@ -93,6 +93,6 @@ public void GreyscaleBothLchabColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleLchuvTests.cs b/Unicolour.Tests/MixGreyscaleLchuvTests.cs similarity index 73% rename from Unicolour.Tests/InterpolateGreyscaleLchuvTests.cs rename to Unicolour.Tests/MixGreyscaleLchuvTests.cs index 43d9d85e..47ff3864 100644 --- a/Unicolour.Tests/InterpolateGreyscaleLchuvTests.cs +++ b/Unicolour.Tests/MixGreyscaleLchuvTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale LUV has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale LUV has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale LCHuv has a hue so it should be used (it just can't be seen until there is some lightness & chroma) -public class InterpolateGreyscaleLchuvTests +public class MixGreyscaleLchuvTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var lchuvWhite = Unicolour.FromLchuv(100, 100, 180); // full lightness = white var green = Unicolour.FromLchuv(50, 100, 120); - var fromLuvBlack = luvBlack.InterpolateLchuv(green, 0.5); - var fromLuvWhite = luvWhite.InterpolateLchuv(green, 0.5); - var fromLchuvBlack = lchuvBlack.InterpolateLchuv(green, 0.5); - var fromLchuvWhite = lchuvWhite.InterpolateLchuv(green, 0.5); + var fromLuvBlack = luvBlack.MixLchuv(green, 0.5); + var fromLuvWhite = luvWhite.MixLchuv(green, 0.5); + var fromLchuvBlack = lchuvBlack.MixLchuv(green, 0.5); + var fromLchuvWhite = lchuvWhite.MixLchuv(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromLuvBlack.Lchuv.Triplet, new(25, 50, 120)); AssertTriplet(fromLuvWhite.Lchuv.Triplet, new(75, 50, 120)); AssertTriplet(fromLchuvBlack.Lchuv.Triplet, new(25, 100, 150)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var lchuvWhite = Unicolour.FromLchuv(100, 100, 180); // full lightness = white var blue = Unicolour.FromLchuv(50, 100, 240); - var toLuvBlack = blue.InterpolateLchuv(luvBlack, 0.5); - var toLuvWhite = blue.InterpolateLchuv(luvWhite, 0.5); - var toLchuvBlack = blue.InterpolateLchuv(lchuvBlack, 0.5); - var toLchuvWhite = blue.InterpolateLchuv(lchuvWhite, 0.5); + var toLuvBlack = blue.MixLchuv(luvBlack, 0.5); + var toLuvWhite = blue.MixLchuv(luvWhite, 0.5); + var toLchuvBlack = blue.MixLchuv(lchuvBlack, 0.5); + var toLchuvWhite = blue.MixLchuv(lchuvWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toLuvBlack.Lchuv.Triplet, new(25, 50, 240)); AssertTriplet(toLuvWhite.Lchuv.Triplet, new(75, 50, 240)); AssertTriplet(toLchuvBlack.Lchuv.Triplet, new(25, 100, 210)); @@ -56,9 +56,9 @@ public void GreyscaleBothLuvColours() var white = Unicolour.FromLuv(100, 0, 0); var grey = Unicolour.FromLuv(50, 0, 0); - var blackToWhite = black.InterpolateLchuv(white, 0.5); - var blackToGrey = black.InterpolateLchuv(grey, 0.5); - var whiteToGrey = white.InterpolateLchuv(grey, 0.5); + var blackToWhite = black.MixLchuv(white, 0.5); + var blackToGrey = black.MixLchuv(grey, 0.5); + var whiteToGrey = white.MixLchuv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -77,9 +77,9 @@ public void GreyscaleBothLchuvColours() var white = Unicolour.FromLchuv(100, 0, 300); var grey = Unicolour.FromLchuv(50, 0, 100); - var blackToWhite = black.InterpolateLchuv(white, 0.5); - var blackToGrey = black.InterpolateLchuv(grey, 0.5); - var whiteToGrey = white.InterpolateLchuv(grey, 0.5); + var blackToWhite = black.MixLchuv(white, 0.5); + var blackToGrey = black.MixLchuv(grey, 0.5); + var whiteToGrey = white.MixLchuv(grey, 0.5); AssertTriplet(blackToWhite.Luv.Triplet, new(50, 0, 0)); AssertTriplet(blackToGrey.Luv.Triplet, new(25, 0, 0)); @@ -93,6 +93,6 @@ public void GreyscaleBothLchuvColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateGreyscaleOklchTests.cs b/Unicolour.Tests/MixGreyscaleOklchTests.cs similarity index 73% rename from Unicolour.Tests/InterpolateGreyscaleOklchTests.cs rename to Unicolour.Tests/MixGreyscaleOklchTests.cs index c0e8581d..505297b2 100644 --- a/Unicolour.Tests/InterpolateGreyscaleOklchTests.cs +++ b/Unicolour.Tests/MixGreyscaleOklchTests.cs @@ -3,9 +3,9 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -// greyscale Oklab has no hue - shouldn't assume to start at red (0 degrees) when interpolating +// greyscale Oklab has no hue - shouldn't assume to start at red (0 degrees) when mixing // greyscale Oklch has a hue so it should be used (it just can't be seen until there is some lightness & chroma) -public class InterpolateGreyscaleOklchTests +public class MixGreyscaleOklchTests { [Test] public void GreyscaleStartColour() @@ -16,12 +16,12 @@ public void GreyscaleStartColour() var oklchWhite = Unicolour.FromOklch(1, 0.5, 180); // full lightness = white var green = Unicolour.FromOklch(0.5, 0.5, 120); - var fromOklabBlack = oklabBlack.InterpolateOklch(green, 0.5); - var fromOklabWhite = oklabWhite.InterpolateOklch(green, 0.5); - var fromOklchBlack = oklchBlack.InterpolateOklch(green, 0.5); - var fromOklchWhite = oklchWhite.InterpolateOklch(green, 0.5); + var fromOklabBlack = oklabBlack.MixOklch(green, 0.5); + var fromOklabWhite = oklabWhite.MixOklch(green, 0.5); + var fromOklchBlack = oklchBlack.MixOklch(green, 0.5); + var fromOklchWhite = oklchWhite.MixOklch(green, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(fromOklabBlack.Oklch.Triplet, new(0.25, 0.25, 120)); AssertTriplet(fromOklabWhite.Oklch.Triplet, new(0.75, 0.25, 120)); AssertTriplet(fromOklchBlack.Oklch.Triplet, new(0.25, 0.5, 150)); @@ -37,12 +37,12 @@ public void GreyscaleEndColour() var oklchWhite = Unicolour.FromOklch(1, 0.5, 180); // full lightness = white var blue = Unicolour.FromOklch(0.5, 0.5, 240); - var toOklabBlack = blue.InterpolateOklch(oklabBlack, 0.5); - var toOklabWhite = blue.InterpolateOklch(oklabWhite, 0.5); - var toOklchBlack = blue.InterpolateOklch(oklchBlack, 0.5); - var toOklchWhite = blue.InterpolateOklch(oklchWhite, 0.5); + var toOklabBlack = blue.MixOklch(oklabBlack, 0.5); + var toOklabWhite = blue.MixOklch(oklabWhite, 0.5); + var toOklchBlack = blue.MixOklch(oklchBlack, 0.5); + var toOklchWhite = blue.MixOklch(oklchWhite, 0.5); - // greyscale interpolates differently depending on the initial colour space + // greyscale mixes differently depending on the initial colour space AssertTriplet(toOklabBlack.Oklch.Triplet, new(0.25, 0.25, 240)); AssertTriplet(toOklabWhite.Oklch.Triplet, new(0.75, 0.25, 240)); AssertTriplet(toOklchBlack.Oklch.Triplet, new(0.25, 0.5, 210)); @@ -56,9 +56,9 @@ public void GreyscaleBothOklabColours() var white = Unicolour.FromOklab(1, 0, 0); var grey = Unicolour.FromOklab(0.5, 0, 0); - var blackToWhite = black.InterpolateOklch(white, 0.5); - var blackToGrey = black.InterpolateOklch(grey, 0.5); - var whiteToGrey = white.InterpolateOklch(grey, 0.5); + var blackToWhite = black.MixOklch(white, 0.5); + var blackToGrey = black.MixOklch(grey, 0.5); + var whiteToGrey = white.MixOklch(grey, 0.5); AssertTriplet(blackToWhite.Oklab.Triplet, new(0.5, 0, 0)); AssertTriplet(blackToGrey.Oklab.Triplet, new(0.25, 0, 0)); @@ -77,9 +77,9 @@ public void GreyscaleBothOklchColours() var white = Unicolour.FromOklch(1, 0, 300); var grey = Unicolour.FromOklch(0.5, 0, 100); - var blackToWhite = black.InterpolateOklch(white, 0.5); - var blackToGrey = black.InterpolateOklch(grey, 0.5); - var whiteToGrey = white.InterpolateOklch(grey, 0.5); + var blackToWhite = black.MixOklch(white, 0.5); + var blackToGrey = black.MixOklch(grey, 0.5); + var whiteToGrey = white.MixOklch(grey, 0.5); AssertTriplet(blackToWhite.Oklab.Triplet, new(0.5, 0, 0)); AssertTriplet(blackToGrey.Oklab.Triplet, new(0.25, 0, 0)); @@ -93,6 +93,6 @@ public void GreyscaleBothOklchColours() private static void AssertTriplet(ColourTriplet actual, ColourTriplet expected) { - AssertUtils.AssertTriplet(actual, expected, AssertUtils.InterpolationTolerance); + AssertUtils.AssertTriplet(actual, expected, AssertUtils.MixTolerance); } } \ No newline at end of file diff --git a/Unicolour.Tests/MixHctTests.cs b/Unicolour.Tests/MixHctTests.cs new file mode 100644 index 00000000..a590babb --- /dev/null +++ b/Unicolour.Tests/MixHctTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHctTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHct(180, 30, 75, 0.5); + var unicolour2 = Unicolour.FromHct(180, 30, 75, 0.5); + var mixed1 = unicolour1.MixHct(unicolour2, 0.25); + var mixed2 = unicolour2.MixHct(unicolour1, 0.75); + var mixed3 = unicolour1.MixHct(unicolour2, 0.75); + var mixed4 = unicolour2.MixHct(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 30, 75, 0.5)); + AssertMixed(mixed2, (180, 30, 75, 0.5)); + AssertMixed(mixed3, (180, 30, 75, 0.5)); + AssertMixed(mixed4, (180, 30, 75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHct(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHct(180, 120, 100); + var mixed1 = unicolour1.MixHct(unicolour2, 0.5); + var mixed2 = unicolour2.MixHct(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 60, 50, 0.5)); + AssertMixed(mixed2, (90, 60, 50, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHct(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHct(340, 60, 80, 0.2); + var mixed1 = unicolour1.MixHct(unicolour2, 0.5); + var mixed2 = unicolour2.MixHct(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 30, 40, 0.1)); + AssertMixed(mixed2, (350, 30, 40, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHct(0, 120, 0); + var unicolour2 = Unicolour.FromHct(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHct(unicolour2, 0.75); + var mixed2 = unicolour2.MixHct(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 30, 75, 0.625)); + AssertMixed(mixed2, (45, 90, 25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHct(300, 120, 0); + var unicolour2 = Unicolour.FromHct(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHct(unicolour2, 0.75); + var mixed2 = unicolour2.MixHct(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 30, 75, 0.625)); + AssertMixed(mixed2, (330, 90, 25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHct(0, 120, 0); + var unicolour2 = Unicolour.FromHct(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHct(unicolour2, 0.25); + var mixed2 = unicolour2.MixHct(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 90, 25, 0.875)); + AssertMixed(mixed2, (135, 30, 75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHct(300, 120, 0); + var unicolour2 = Unicolour.FromHct(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHct(unicolour2, 0.25); + var mixed2 = unicolour2.MixHct(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 90, 25, 0.875)); + AssertMixed(mixed2, (30, 30, 75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHct(0, 48, 60, 0.8); + var unicolour2 = Unicolour.FromHct(90, 72, 40, 0.9); + var mixed1 = unicolour1.MixHct(unicolour2, 1.5); + var mixed2 = unicolour2.MixHct(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 84, 30, 0.95)); + AssertMixed(mixed2, (315, 36, 70, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHct(0, 48, 60, 0.8); + var unicolour2 = Unicolour.FromHct(90, 72, 40, 0.9); + var mixed1 = unicolour1.MixHct(unicolour2, -0.5); + var mixed2 = unicolour2.MixHct(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 36, 70, 0.75)); + AssertMixed(mixed2, (135, 84, 30, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hct.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/InterpolateHeritageTests.cs b/Unicolour.Tests/MixHeritageTests.cs similarity index 61% rename from Unicolour.Tests/InterpolateHeritageTests.cs rename to Unicolour.Tests/MixHeritageTests.cs index 85b3b4e2..f5ae8069 100644 --- a/Unicolour.Tests/InterpolateHeritageTests.cs +++ b/Unicolour.Tests/MixHeritageTests.cs @@ -5,7 +5,7 @@ namespace Wacton.Unicolour.Tests; using NUnit.Framework; using Wacton.Unicolour.Tests.Utils; -public class InterpolateHeritageTests +public class MixHeritageTests { private static readonly List HuedSpaces = new() { @@ -24,20 +24,20 @@ public void HuedToHued() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - // initial interpolated representation: no heritage, non-NaN, non-greyscale; + // initial mixed representation: no heritage, non-NaN, non-greyscale; // all representations are used as hued where hue axis is present - var interpolated = unicolour1.InterpolateRgb(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); + var mixed = unicolour1.MixRgb(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - var data = new ColourHeritageData(interpolated); + var data = new ColourHeritageData(mixed); Assert.That(data.UseAsHued(HuedSpaces), Has.All.True); Assert.That(data.UseAsHued(NonHuedSpaces), Has.All.False); - // representations of interpolated colour has same behaviour when interpolated via hued space - interpolated = unicolour1.InterpolateHsb(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); + // representations of mixed colour has same behaviour when mixed via hued space + mixed = unicolour1.MixHsb(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); - data = new ColourHeritageData(interpolated); + data = new ColourHeritageData(mixed); Assert.That(data.UseAsHued(HuedSpaces), Has.All.True); Assert.That(data.UseAsHued(NonHuedSpaces), Has.All.False); } @@ -51,12 +51,12 @@ public void HuedToGreyscale() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - // initial interpolated representation: no heritage, greyscale values; + // initial mixed representation: no heritage, greyscale values; // all representations are used as greyscale, none are used as hued - var interpolated = unicolour1.InterpolateRgb(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.None, isHued: false, isGreyscale: true, isNotNumber: false); + var mixed = unicolour1.MixRgb(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.None, isHued: false, isGreyscale: true, isNotNumber: false); - var data = new ColourHeritageData(interpolated); + var data = new ColourHeritageData(mixed); Assert.That(data.UseAsGreyscale(AssertUtils.AllColourSpaces), Has.All.True); Assert.That(data.UseAsHued(AssertUtils.AllColourSpaces), Has.All.False); } @@ -70,12 +70,12 @@ public void GreyscaleToHued() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: false, isGreyscale: true, isNotNumber: false); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - // initial interpolated representation: no heritage, non-greyscale values; + // initial mixed representation: no heritage, non-greyscale values; // all representations are used as hued where hue axis is present - var interpolated = unicolour1.InterpolateRgb(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); + var mixed = unicolour1.MixRgb(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - var data = new ColourHeritageData(interpolated); + var data = new ColourHeritageData(mixed); Assert.That(data.UseAsHued(HuedSpaces), Has.All.True); Assert.That(data.UseAsHued(NonHuedSpaces), Has.All.False); } @@ -89,12 +89,12 @@ public void GreyscaleToGreyscale() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: false, isGreyscale: true, isNotNumber: false); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: false, isGreyscale: true, isNotNumber: false); - // initial interpolated representation: greyscale heritage, greyscale values; + // initial mixed representation: greyscale heritage, greyscale values; // all representations are used as greyscale, none are used as hued - var interpolated = unicolour1.InterpolateLab(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.Greyscale, isHued: false, isGreyscale: true, isNotNumber: false); + var mixed = unicolour1.MixLab(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.Greyscale, isHued: false, isGreyscale: true, isNotNumber: false); - var data = new ColourHeritageData(interpolated); + var data = new ColourHeritageData(mixed); Assert.That(data.UseAsGreyscale(AssertUtils.AllColourSpaces), Has.All.True); Assert.That(data.UseAsHued(AssertUtils.AllColourSpaces), Has.All.False); } @@ -108,12 +108,12 @@ public void NotNumberToNotNumber() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: true); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: false, isGreyscale: false, isNotNumber: false); - // initial interpolated representation: NaN heritage, NaN values; + // initial mixed representation: NaN heritage, NaN values; // all representations are used as NaN, none are used as hued or greyscale - var interpolated = unicolour1.InterpolateRgb(unicolour2, 0.5); - AssertInitialHeritage(interpolated, ColourHeritage.NaN, isHued: false, isGreyscale: false, isNotNumber: true); + var mixed = unicolour1.MixRgb(unicolour2, 0.5); + AssertInitialHeritage(mixed, ColourHeritage.NaN, isHued: false, isGreyscale: false, isNotNumber: true); - var data = new ColourHeritageData(interpolated); + var data = new ColourHeritageData(mixed); Assert.That(data.UseAsNaN(AssertUtils.AllColourSpaces), Has.All.True); Assert.That(data.UseAsGreyscale(AssertUtils.AllColourSpaces), Has.All.False); Assert.That(data.UseAsHued(AssertUtils.AllColourSpaces), Has.All.False); @@ -121,8 +121,8 @@ public void NotNumberToNotNumber() /* * this test ensures that, when using a consistent hued space, - * hue information is retained over multiple interpolations even when the colours themselves are greyscale values - * (e.g. starting with HSB and also interpolating HSB, or even interpolating an HSB-adjacent hued space such as HSL) + * hue information is retained over multiple mixes even when the colours themselves are greyscale values + * (e.g. starting with HSB and also mixing HSB, or even mixing an HSB-adjacent hued space such as HSL) */ [Test] public void GreyscaleAndHued() @@ -132,24 +132,24 @@ public void GreyscaleAndHued() AssertInitialHeritage(unicolour1, ColourHeritage.None, isHued: true, isGreyscale: true, isNotNumber: false); AssertInitialHeritage(unicolour2, ColourHeritage.None, isHued: true, isGreyscale: true, isNotNumber: false); - var interpolated1 = unicolour1.InterpolateHsb(unicolour2, 0.75); // 90, 0, 0 - var interpolated2 = unicolour1.InterpolateHsb(unicolour2, 0.25); // 30, 0, 0 - AssertInitialHeritage(interpolated1, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); - AssertInitialHeritage(interpolated2, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.75); // 90, 0, 0 + var mixed2 = unicolour1.MixHsb(unicolour2, 0.25); // 30, 0, 0 + AssertInitialHeritage(mixed1, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); + AssertInitialHeritage(mixed2, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); - var interpolated3 = interpolated1.InterpolateHsb(interpolated2, 0.5); // 60, 0, 0 + var mixed3 = mixed1.MixHsb(mixed2, 0.5); // 60, 0, 0 var unicolour3 = Unicolour.FromHsb(240, 1, 1); - AssertInitialHeritage(interpolated3, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); + AssertInitialHeritage(mixed3, ColourHeritage.GreyscaleAndHued, isHued: true, isGreyscale: true, isNotNumber: false); AssertInitialHeritage(unicolour3, ColourHeritage.None, isHued: true, isGreyscale: false, isNotNumber: false); - var interpolated4 = interpolated3.InterpolateHsb(unicolour3, 0.5); // 180, 0.5, 0.5 - AssertInitialHeritage(interpolated4, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); - Assert.That(interpolated4.Hsb.H, Is.EqualTo(150)); + var mixed4 = mixed3.MixHsb(unicolour3, 0.5); // 180, 0.5, 0.5 + AssertInitialHeritage(mixed4, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); + Assert.That(mixed4.Hsb.H, Is.EqualTo(150)); // HSL is a transform of HSB, hue information should also still be intact - var interpolatedHsl = interpolated3.InterpolateHsl(unicolour3, 0.5); - AssertInitialHeritage(interpolated4, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); - Assert.That(interpolatedHsl.Hsb.H, Is.EqualTo(150)); + var mixedHsl = mixed3.MixHsl(unicolour3, 0.5); + AssertInitialHeritage(mixed4, ColourHeritage.Hued, isHued: true, isGreyscale: false, isNotNumber: false); + Assert.That(mixedHsl.Hsb.H, Is.EqualTo(150)); } private static void AssertInitialHeritage(Unicolour unicolour, ColourHeritage colourHeritage, bool isHued, bool isGreyscale, bool isNotNumber) diff --git a/Unicolour.Tests/MixHpluvTests.cs b/Unicolour.Tests/MixHpluvTests.cs new file mode 100644 index 00000000..26bced8a --- /dev/null +++ b/Unicolour.Tests/MixHpluvTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHpluvTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHpluv(180, 25, 75, 0.5); + var unicolour2 = Unicolour.FromHpluv(180, 25, 75, 0.5); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.75); + var mixed3 = unicolour1.MixHpluv(unicolour2, 0.75); + var mixed4 = unicolour2.MixHpluv(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 25, 75, 0.5)); + AssertMixed(mixed2, (180, 25, 75, 0.5)); + AssertMixed(mixed3, (180, 25, 75, 0.5)); + AssertMixed(mixed4, (180, 25, 75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHpluv(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHpluv(180, 100, 100); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.5); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 50, 50, 0.5)); + AssertMixed(mixed2, (90, 50, 50, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHpluv(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHpluv(340, 50, 80, 0.2); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.5); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 25, 40, 0.1)); + AssertMixed(mixed2, (350, 25, 40, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHpluv(0, 100, 0); + var unicolour2 = Unicolour.FromHpluv(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.75); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 25, 75, 0.625)); + AssertMixed(mixed2, (45, 75, 25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHpluv(300, 100, 0); + var unicolour2 = Unicolour.FromHpluv(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.75); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 25, 75, 0.625)); + AssertMixed(mixed2, (330, 75, 25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHpluv(0, 100, 0); + var unicolour2 = Unicolour.FromHpluv(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 75, 25, 0.875)); + AssertMixed(mixed2, (135, 25, 75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHpluv(300, 100, 0); + var unicolour2 = Unicolour.FromHpluv(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHpluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHpluv(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 75, 25, 0.875)); + AssertMixed(mixed2, (30, 25, 75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHpluv(0, 40, 60, 0.8); + var unicolour2 = Unicolour.FromHpluv(90, 60, 40, 0.9); + var mixed1 = unicolour1.MixHpluv(unicolour2, 1.5); + var mixed2 = unicolour2.MixHpluv(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 70, 30, 0.95)); + AssertMixed(mixed2, (315, 30, 70, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHpluv(0, 40, 60, 0.8); + var unicolour2 = Unicolour.FromHpluv(90, 60, 40, 0.9); + var mixed1 = unicolour1.MixHpluv(unicolour2, -0.5); + var mixed2 = unicolour2.MixHpluv(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 30, 70, 0.75)); + AssertMixed(mixed2, (135, 70, 30, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hpluv.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixHsbTests.cs b/Unicolour.Tests/MixHsbTests.cs new file mode 100644 index 00000000..fa4c9a64 --- /dev/null +++ b/Unicolour.Tests/MixHsbTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHsbTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHsb(180, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromHsb(180, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.75); + var mixed3 = unicolour1.MixHsb(unicolour2, 0.75); + var mixed4 = unicolour2.MixHsb(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (180, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHsb(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsb(180, 1, 1); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (90, 0.5, 0.5, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHsb(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsb(340, 0.5, 0.8, 0.2); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 0.25, 0.4, 0.1)); + AssertMixed(mixed2, (350, 0.25, 0.4, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHsb(0, 1, 0); + var unicolour2 = Unicolour.FromHsb(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (45, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHsb(300, 1, 0); + var unicolour2 = Unicolour.FromHsb(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (330, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHsb(0, 1, 0); + var unicolour2 = Unicolour.FromHsb(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (135, 0.25, 0.75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHsb(300, 1, 0); + var unicolour2 = Unicolour.FromHsb(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsb(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (30, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHsb(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHsb(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHsb(unicolour2, 1.5); + var mixed2 = unicolour2.MixHsb(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (315, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHsb(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHsb(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHsb(unicolour2, -0.5); + var mixed2 = unicolour2.MixHsb(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (135, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hsb.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixHslTests.cs b/Unicolour.Tests/MixHslTests.cs new file mode 100644 index 00000000..c4ab11d6 --- /dev/null +++ b/Unicolour.Tests/MixHslTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHslTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHsl(180, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromHsl(180, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.75); + var mixed3 = unicolour1.MixHsl(unicolour2, 0.75); + var mixed4 = unicolour2.MixHsl(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (180, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHsl(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsl(180, 1, 1); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (90, 0.5, 0.5, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHsl(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsl(340, 0.5, 0.8, 0.2); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 0.25, 0.4, 0.1)); + AssertMixed(mixed2, (350, 0.25, 0.4, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHsl(0, 1, 0); + var unicolour2 = Unicolour.FromHsl(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (45, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHsl(300, 1, 0); + var unicolour2 = Unicolour.FromHsl(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (330, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHsl(0, 1, 0); + var unicolour2 = Unicolour.FromHsl(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (135, 0.25, 0.75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHsl(300, 1, 0); + var unicolour2 = Unicolour.FromHsl(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHsl(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsl(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (30, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHsl(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHsl(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHsl(unicolour2, 1.5); + var mixed2 = unicolour2.MixHsl(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (315, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHsl(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHsl(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHsl(unicolour2, -0.5); + var mixed2 = unicolour2.MixHsl(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (135, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hsl.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixHsluvTests.cs b/Unicolour.Tests/MixHsluvTests.cs new file mode 100644 index 00000000..01c67d97 --- /dev/null +++ b/Unicolour.Tests/MixHsluvTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHsluvTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHsluv(180, 25, 75, 0.5); + var unicolour2 = Unicolour.FromHsluv(180, 25, 75, 0.5); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.75); + var mixed3 = unicolour1.MixHsluv(unicolour2, 0.75); + var mixed4 = unicolour2.MixHsluv(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 25, 75, 0.5)); + AssertMixed(mixed2, (180, 25, 75, 0.5)); + AssertMixed(mixed3, (180, 25, 75, 0.5)); + AssertMixed(mixed4, (180, 25, 75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHsluv(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsluv(180, 100, 100); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 50, 50, 0.5)); + AssertMixed(mixed2, (90, 50, 50, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHsluv(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHsluv(340, 50, 80, 0.2); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.5); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 25, 40, 0.1)); + AssertMixed(mixed2, (350, 25, 40, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHsluv(0, 100, 0); + var unicolour2 = Unicolour.FromHsluv(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 25, 75, 0.625)); + AssertMixed(mixed2, (45, 75, 25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHsluv(300, 100, 0); + var unicolour2 = Unicolour.FromHsluv(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.75); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 25, 75, 0.625)); + AssertMixed(mixed2, (330, 75, 25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHsluv(0, 100, 0); + var unicolour2 = Unicolour.FromHsluv(180, 0, 100, 0.5); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 75, 25, 0.875)); + AssertMixed(mixed2, (135, 25, 75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHsluv(300, 100, 0); + var unicolour2 = Unicolour.FromHsluv(60, 0, 100, 0.5); + var mixed1 = unicolour1.MixHsluv(unicolour2, 0.25); + var mixed2 = unicolour2.MixHsluv(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 75, 25, 0.875)); + AssertMixed(mixed2, (30, 25, 75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHsluv(0, 40, 60, 0.8); + var unicolour2 = Unicolour.FromHsluv(90, 60, 40, 0.9); + var mixed1 = unicolour1.MixHsluv(unicolour2, 1.5); + var mixed2 = unicolour2.MixHsluv(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 70, 30, 0.95)); + AssertMixed(mixed2, (315, 30, 70, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHsluv(0, 40, 60, 0.8); + var unicolour2 = Unicolour.FromHsluv(90, 60, 40, 0.9); + var mixed1 = unicolour1.MixHsluv(unicolour2, -0.5); + var mixed2 = unicolour2.MixHsluv(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 30, 70, 0.75)); + AssertMixed(mixed2, (135, 70, 30, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hsluv.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixHwbTests.cs b/Unicolour.Tests/MixHwbTests.cs new file mode 100644 index 00000000..f9fa04d0 --- /dev/null +++ b/Unicolour.Tests/MixHwbTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixHwbTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromHwb(180, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromHwb(180, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.75); + var mixed3 = unicolour1.MixHwb(unicolour2, 0.75); + var mixed4 = unicolour2.MixHwb(unicolour1, 0.25); + + AssertMixed(mixed1, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (180, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (180, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromHwb(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHwb(180, 1, 1); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.5); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.5); + + AssertMixed(mixed1, (90, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (90, 0.5, 0.5, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromHwb(0, 0, 0, 0); + var unicolour2 = Unicolour.FromHwb(340, 0.5, 0.8, 0.2); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.5); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.5); + + AssertMixed(mixed1, (350, 0.25, 0.4, 0.1)); + AssertMixed(mixed2, (350, 0.25, 0.4, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromHwb(0, 1, 0); + var unicolour2 = Unicolour.FromHwb(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.75); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.75); + + AssertMixed(mixed1, (135, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (45, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromHwb(300, 1, 0); + var unicolour2 = Unicolour.FromHwb(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.75); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.75); + + AssertMixed(mixed1, (30, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (330, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromHwb(0, 1, 0); + var unicolour2 = Unicolour.FromHwb(180, 0, 1, 0.5); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.25); + + AssertMixed(mixed1, (45, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (135, 0.25, 0.75, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromHwb(300, 1, 0); + var unicolour2 = Unicolour.FromHwb(60, 0, 1, 0.5); + var mixed1 = unicolour1.MixHwb(unicolour2, 0.25); + var mixed2 = unicolour2.MixHwb(unicolour1, 0.25); + + AssertMixed(mixed1, (330, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (30, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromHwb(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHwb(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHwb(unicolour2, 1.5); + var mixed2 = unicolour2.MixHwb(unicolour1, 1.5); + + AssertMixed(mixed1, (135, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (315, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromHwb(0, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromHwb(90, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixHwb(unicolour2, -0.5); + var mixed2 = unicolour2.MixHwb(unicolour1, -0.5); + + AssertMixed(mixed1, (315, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (135, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Hwb.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixIctcpTests.cs b/Unicolour.Tests/MixIctcpTests.cs new file mode 100644 index 00000000..08bebea9 --- /dev/null +++ b/Unicolour.Tests/MixIctcpTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixIctcpTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromIctcp(0.5, -0.25, 0.25, 0.5); + var unicolour2 = Unicolour.FromIctcp(0.5, -0.25, 0.25, 0.5); + var mixed1 = unicolour1.MixIctcp(unicolour2, 0.25); + var mixed2 = unicolour2.MixIctcp(unicolour1, 0.75); + var mixed3 = unicolour1.MixIctcp(unicolour2, 0.75); + var mixed4 = unicolour2.MixIctcp(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed2, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed3, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed4, (0.5, -0.25, 0.25, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromIctcp(0.0, -0.5, -0.5, 0.0); + var unicolour2 = Unicolour.FromIctcp(0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixIctcp(unicolour2, 0.5); + var mixed2 = unicolour2.MixIctcp(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.0, 0.0, 0.5)); + AssertMixed(mixed2, (0.25, 0.0, 0.0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromIctcp(0, 0.5, -0.5); + var unicolour2 = Unicolour.FromIctcp(0.8, -0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixIctcp(unicolour2, 0.75); + var mixed2 = unicolour2.MixIctcp(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, -0.25, 0.25, 0.625)); + AssertMixed(mixed2, (0.2, 0.25, -0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromIctcp(0, 0.5, -0.5); + var unicolour2 = Unicolour.FromIctcp(0.8, -0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixIctcp(unicolour2, 0.25); + var mixed2 = unicolour2.MixIctcp(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.25, -0.25, 0.875)); + AssertMixed(mixed2, (0.6, -0.25, 0.25, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromIctcp(0.2, -0.125, 0.125, 0.8); + var unicolour2 = Unicolour.FromIctcp(0.3, 0.125, -0.125, 0.9); + var mixed1 = unicolour1.MixIctcp(unicolour2, 1.5); + var mixed2 = unicolour2.MixIctcp(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.25, -0.25, 0.95)); + AssertMixed(mixed2, (0.15, -0.25, 0.25, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromIctcp(0.2, -0.125, 0.125, 0.8); + var unicolour2 = Unicolour.FromIctcp(0.3, 0.125, -0.125, 0.9); + var mixed1 = unicolour1.MixIctcp(unicolour2, -0.5); + var mixed2 = unicolour2.MixIctcp(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, -0.25, 0.25, 0.75)); + AssertMixed(mixed2, (0.35, 0.25, -0.25, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Ictcp.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixJzazbzTests.cs b/Unicolour.Tests/MixJzazbzTests.cs new file mode 100644 index 00000000..1755fb71 --- /dev/null +++ b/Unicolour.Tests/MixJzazbzTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixJzazbzTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromJzazbz(0.08, -0.05, 0.05, 0.5); + var unicolour2 = Unicolour.FromJzazbz(0.08, -0.05, 0.05, 0.5); + var mixed1 = unicolour1.MixJzazbz(unicolour2, 0.25); + var mixed2 = unicolour2.MixJzazbz(unicolour1, 0.75); + var mixed3 = unicolour1.MixJzazbz(unicolour2, 0.75); + var mixed4 = unicolour2.MixJzazbz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.08, -0.05, 0.05, 0.5)); + AssertMixed(mixed2, (0.08, -0.05, 0.05, 0.5)); + AssertMixed(mixed3, (0.08, -0.05, 0.05, 0.5)); + AssertMixed(mixed4, (0.08, -0.05, 0.05, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromJzazbz(0.0, -0.1, -0.1, 0.0); + var unicolour2 = Unicolour.FromJzazbz(0.08, 0.1, 0.1); + var mixed1 = unicolour1.MixJzazbz(unicolour2, 0.5); + var mixed2 = unicolour2.MixJzazbz(unicolour1, 0.5); + + AssertMixed(mixed1, (0.04, 0.0, 0.0, 0.5)); + AssertMixed(mixed2, (0.04, 0.0, 0.0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromJzazbz(0, 0.1, -0.1); + var unicolour2 = Unicolour.FromJzazbz(0.12, -0.1, 0.1, 0.5); + var mixed1 = unicolour1.MixJzazbz(unicolour2, 0.75); + var mixed2 = unicolour2.MixJzazbz(unicolour1, 0.75); + + AssertMixed(mixed1, (0.09, -0.05, 0.05, 0.625)); + AssertMixed(mixed2, (0.03, 0.05, -0.05, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromJzazbz(0, 0.1, -0.1); + var unicolour2 = Unicolour.FromJzazbz(0.12, -0.1, 0.1, 0.5); + var mixed1 = unicolour1.MixJzazbz(unicolour2, 0.25); + var mixed2 = unicolour2.MixJzazbz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.03, 0.05, -0.05, 0.875)); + AssertMixed(mixed2, (0.09, -0.05, 0.05, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromJzazbz(0.02, -0.025, 0.025, 0.8); + var unicolour2 = Unicolour.FromJzazbz(0.03, 0.025, -0.025, 0.9); + var mixed1 = unicolour1.MixJzazbz(unicolour2, 1.5); + var mixed2 = unicolour2.MixJzazbz(unicolour1, 1.5); + + AssertMixed(mixed1, (0.035, 0.05, -0.05, 0.95)); + AssertMixed(mixed2, (0.015, -0.05, 0.05, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromJzazbz(0.02, -0.025, 0.025, 0.8); + var unicolour2 = Unicolour.FromJzazbz(0.03, 0.025, -0.025, 0.9); + var mixed1 = unicolour1.MixJzazbz(unicolour2, -0.5); + var mixed2 = unicolour2.MixJzazbz(unicolour1, -0.5); + + AssertMixed(mixed1, (0.015, -0.05, 0.05, 0.75)); + AssertMixed(mixed2, (0.035, 0.05, -0.05, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Jzazbz.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixJzczhzTests.cs b/Unicolour.Tests/MixJzczhzTests.cs new file mode 100644 index 00000000..1454557b --- /dev/null +++ b/Unicolour.Tests/MixJzczhzTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixJzczhzTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromJzczhz(0.08, 0.08, 180, 0.5); + var unicolour2 = Unicolour.FromJzczhz(0.08, 0.08, 180, 0.5); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.25); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.75); + var mixed3 = unicolour1.MixJzczhz(unicolour2, 0.75); + var mixed4 = unicolour2.MixJzczhz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.08, 0.08, 180, 0.5)); + AssertMixed(mixed2, (0.08, 0.08, 180, 0.5)); + AssertMixed(mixed3, (0.08, 0.08, 180, 0.5)); + AssertMixed(mixed4, (0.08, 0.08, 180, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0, 0, 0.0); + var unicolour2 = Unicolour.FromJzczhz(0.08, 0.08, 180); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.5); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.5); + + AssertMixed(mixed1, (0.04, 0.04, 90, 0.5)); + AssertMixed(mixed2, (0.04, 0.04, 90, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0, 0, 0); + var unicolour2 = Unicolour.FromJzczhz(0.12, 0.04, 340, 0.2); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.5); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.5); + + AssertMixed(mixed1, (0.06, 0.02, 350, 0.1)); + AssertMixed(mixed2, (0.06, 0.02, 350, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 0); + var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 180, 0.5); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.75); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.75); + + AssertMixed(mixed1, (0.09, 0.02, 135, 0.625)); + AssertMixed(mixed2, (0.03, 0.06, 45, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 300); + var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 60, 0.5); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.75); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.75); + + AssertMixed(mixed1, (0.09, 0.02, 30, 0.625)); + AssertMixed(mixed2, (0.03, 0.06, 330, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 0); + var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 180, 0.5); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.25); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.03, 0.06, 45, 0.875)); + AssertMixed(mixed2, (0.09, 0.02, 135, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromJzczhz(0, 0.08, 300); + var unicolour2 = Unicolour.FromJzczhz(0.12, 0, 60, 0.5); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 0.25); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.03, 0.06, 330, 0.875)); + AssertMixed(mixed2, (0.09, 0.02, 30, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromJzczhz(0.02, 0.02, 0, 0.8); + var unicolour2 = Unicolour.FromJzczhz(0.03, 0.03, 90, 0.9); + var mixed1 = unicolour1.MixJzczhz(unicolour2, 1.5); + var mixed2 = unicolour2.MixJzczhz(unicolour1, 1.5); + + AssertMixed(mixed1, (0.035, 0.035, 135, 0.95)); + AssertMixed(mixed2, (0.015, 0.015, 315, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromJzczhz(0.02, 0.02, 0, 0.8); + var unicolour2 = Unicolour.FromJzczhz(0.03, 0.03, 90, 0.9); + var mixed1 = unicolour1.MixJzczhz(unicolour2, -0.5); + var mixed2 = unicolour2.MixJzczhz(unicolour1, -0.5); + + AssertMixed(mixed1, (0.015, 0.015, 315, 0.75)); + AssertMixed(mixed2, (0.035, 0.035, 135, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Jzczhz.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixLabTests.cs b/Unicolour.Tests/MixLabTests.cs new file mode 100644 index 00000000..0795759c --- /dev/null +++ b/Unicolour.Tests/MixLabTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixLabTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromLab(50, -64, 64, 0.5); + var unicolour2 = Unicolour.FromLab(50, -64, 64, 0.5); + var mixed1 = unicolour1.MixLab(unicolour2, 0.25); + var mixed2 = unicolour2.MixLab(unicolour1, 0.75); + var mixed3 = unicolour1.MixLab(unicolour2, 0.75); + var mixed4 = unicolour2.MixLab(unicolour1, 0.25); + + AssertMixed(mixed1, (50, -64, 64, 0.5)); + AssertMixed(mixed2, (50, -64, 64, 0.5)); + AssertMixed(mixed3, (50, -64, 64, 0.5)); + AssertMixed(mixed4, (50, -64, 64, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromLab(0, -128, -128, 0.0); + var unicolour2 = Unicolour.FromLab(50, 128, 128); + var mixed1 = unicolour1.MixLab(unicolour2, 0.5); + var mixed2 = unicolour2.MixLab(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 0, 0, 0.5)); + AssertMixed(mixed2, (25, 0, 0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromLab(0, 128, -128); + var unicolour2 = Unicolour.FromLab(80, -128, 128, 0.5); + var mixed1 = unicolour1.MixLab(unicolour2, 0.75); + var mixed2 = unicolour2.MixLab(unicolour1, 0.75); + + AssertMixed(mixed1, (60, -64, 64, 0.625)); + AssertMixed(mixed2, (20, 64, -64, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromLab(0, 128, -128); + var unicolour2 = Unicolour.FromLab(80, -128, 128, 0.5); + var mixed1 = unicolour1.MixLab(unicolour2, 0.25); + var mixed2 = unicolour2.MixLab(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 64, -64, 0.875)); + AssertMixed(mixed2, (60, -64, 64, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromLab(20, -25.6, 25.6, 0.8); + var unicolour2 = Unicolour.FromLab(30, 25.6, -25.6, 0.9); + var mixed1 = unicolour1.MixLab(unicolour2, 1.5); + var mixed2 = unicolour2.MixLab(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 51.2, -51.2, 0.95)); + AssertMixed(mixed2, (15, -51.2, 51.2, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromLab(20, -25.6, 25.6, 0.8); + var unicolour2 = Unicolour.FromLab(30, 25.6, -25.6, 0.9); + var mixed1 = unicolour1.MixLab(unicolour2, -0.5); + var mixed2 = unicolour2.MixLab(unicolour1, -0.5); + + AssertMixed(mixed1, (15, -51.2, 51.2, 0.75)); + AssertMixed(mixed2, (35, 51.2, -51.2, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Lab.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixLchabTests.cs b/Unicolour.Tests/MixLchabTests.cs new file mode 100644 index 00000000..0e3911f0 --- /dev/null +++ b/Unicolour.Tests/MixLchabTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixLchabTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromLchab(50, 50, 180, 0.5); + var unicolour2 = Unicolour.FromLchab(50, 50, 180, 0.5); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.75); + var mixed3 = unicolour1.MixLchab(unicolour2, 0.75); + var mixed4 = unicolour2.MixLchab(unicolour1, 0.25); + + AssertMixed(mixed1, (50, 50, 180, 0.5)); + AssertMixed(mixed2, (50, 50, 180, 0.5)); + AssertMixed(mixed3, (50, 50, 180, 0.5)); + AssertMixed(mixed4, (50, 50, 180, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromLchab(0, 0, 0, 0.0); + var unicolour2 = Unicolour.FromLchab(50, 100, 180); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.5); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 50, 90, 0.5)); + AssertMixed(mixed2, (25, 50, 90, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromLchab(0, 0, 0, 0); + var unicolour2 = Unicolour.FromLchab(80, 50, 340, 0.2); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.5); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.5); + + AssertMixed(mixed1, (40, 25, 350, 0.1)); + AssertMixed(mixed2, (40, 25, 350, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromLchab(0, 100, 0); + var unicolour2 = Unicolour.FromLchab(80, 0, 180, 0.5); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.75); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.75); + + AssertMixed(mixed1, (60, 25, 135, 0.625)); + AssertMixed(mixed2, (20, 75, 45, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromLchab(0, 100, 300); + var unicolour2 = Unicolour.FromLchab(80, 0, 60, 0.5); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.75); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.75); + + AssertMixed(mixed1, (60, 25, 30, 0.625)); + AssertMixed(mixed2, (20, 75, 330, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromLchab(0, 100, 0); + var unicolour2 = Unicolour.FromLchab(80, 0, 180, 0.5); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 75, 45, 0.875)); + AssertMixed(mixed2, (60, 25, 135, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromLchab(0, 100, 300); + var unicolour2 = Unicolour.FromLchab(80, 0, 60, 0.5); + var mixed1 = unicolour1.MixLchab(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchab(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 75, 330, 0.875)); + AssertMixed(mixed2, (60, 25, 30, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromLchab(20, 40, 0, 0.8); + var unicolour2 = Unicolour.FromLchab(30, 60, 90, 0.9); + var mixed1 = unicolour1.MixLchab(unicolour2, 1.5); + var mixed2 = unicolour2.MixLchab(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 70, 135, 0.95)); + AssertMixed(mixed2, (15, 30, 315, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromLchab(20, 40, 0, 0.8); + var unicolour2 = Unicolour.FromLchab(30, 60, 90, 0.9); + var mixed1 = unicolour1.MixLchab(unicolour2, -0.5); + var mixed2 = unicolour2.MixLchab(unicolour1, -0.5); + + AssertMixed(mixed1, (15, 30, 315, 0.75)); + AssertMixed(mixed2, (35, 70, 135, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Lchab.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixLchuvTests.cs b/Unicolour.Tests/MixLchuvTests.cs new file mode 100644 index 00000000..0daf8801 --- /dev/null +++ b/Unicolour.Tests/MixLchuvTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixLchuvTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromLchuv(50, 50, 180, 0.5); + var unicolour2 = Unicolour.FromLchuv(50, 50, 180, 0.5); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.75); + var mixed3 = unicolour1.MixLchuv(unicolour2, 0.75); + var mixed4 = unicolour2.MixLchuv(unicolour1, 0.25); + + AssertMixed(mixed1, (50, 50, 180, 0.5)); + AssertMixed(mixed2, (50, 50, 180, 0.5)); + AssertMixed(mixed3, (50, 50, 180, 0.5)); + AssertMixed(mixed4, (50, 50, 180, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromLchuv(0, 0, 0, 0.0); + var unicolour2 = Unicolour.FromLchuv(50, 100, 180); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.5); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 50, 90, 0.5)); + AssertMixed(mixed2, (25, 50, 90, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromLchuv(0, 0, 0, 0); + var unicolour2 = Unicolour.FromLchuv(80, 50, 340, 0.2); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.5); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.5); + + AssertMixed(mixed1, (40, 25, 350, 0.1)); + AssertMixed(mixed2, (40, 25, 350, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromLchuv(0, 100, 0); + var unicolour2 = Unicolour.FromLchuv(80, 0, 180, 0.5); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.75); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.75); + + AssertMixed(mixed1, (60, 25, 135, 0.625)); + AssertMixed(mixed2, (20, 75, 45, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromLchuv(0, 100, 300); + var unicolour2 = Unicolour.FromLchuv(80, 0, 60, 0.5); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.75); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.75); + + AssertMixed(mixed1, (60, 25, 30, 0.625)); + AssertMixed(mixed2, (20, 75, 330, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromLchuv(0, 100, 0); + var unicolour2 = Unicolour.FromLchuv(80, 0, 180, 0.5); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 75, 45, 0.875)); + AssertMixed(mixed2, (60, 25, 135, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromLchuv(0, 100, 300); + var unicolour2 = Unicolour.FromLchuv(80, 0, 60, 0.5); + var mixed1 = unicolour1.MixLchuv(unicolour2, 0.25); + var mixed2 = unicolour2.MixLchuv(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 75, 330, 0.875)); + AssertMixed(mixed2, (60, 25, 30, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromLchuv(20, 40, 0, 0.8); + var unicolour2 = Unicolour.FromLchuv(30, 60, 90, 0.9); + var mixed1 = unicolour1.MixLchuv(unicolour2, 1.5); + var mixed2 = unicolour2.MixLchuv(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 70, 135, 0.95)); + AssertMixed(mixed2, (15, 30, 315, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromLchuv(20, 40, 0, 0.8); + var unicolour2 = Unicolour.FromLchuv(30, 60, 90, 0.9); + var mixed1 = unicolour1.MixLchuv(unicolour2, -0.5); + var mixed2 = unicolour2.MixLchuv(unicolour1, -0.5); + + AssertMixed(mixed1, (15, 30, 315, 0.75)); + AssertMixed(mixed2, (35, 70, 135, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Lchuv.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixLuvTests.cs b/Unicolour.Tests/MixLuvTests.cs new file mode 100644 index 00000000..83bfeab1 --- /dev/null +++ b/Unicolour.Tests/MixLuvTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixLuvTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromLuv(50, -50, 50, 0.5); + var unicolour2 = Unicolour.FromLuv(50, -50, 50, 0.5); + var mixed1 = unicolour1.MixLuv(unicolour2, 0.25); + var mixed2 = unicolour2.MixLuv(unicolour1, 0.75); + var mixed3 = unicolour1.MixLuv(unicolour2, 0.75); + var mixed4 = unicolour2.MixLuv(unicolour1, 0.25); + + AssertMixed(mixed1, (50, -50, 50, 0.5)); + AssertMixed(mixed2, (50, -50, 50, 0.5)); + AssertMixed(mixed3, (50, -50, 50, 0.5)); + AssertMixed(mixed4, (50, -50, 50, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromLuv(0, -100, -100, 0.0); + var unicolour2 = Unicolour.FromLuv(50, 100, 100); + var mixed1 = unicolour1.MixLuv(unicolour2, 0.5); + var mixed2 = unicolour2.MixLuv(unicolour1, 0.5); + + AssertMixed(mixed1, (25, 0, 0, 0.5)); + AssertMixed(mixed2, (25, 0, 0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromLuv(0, 100, -100); + var unicolour2 = Unicolour.FromLuv(80, -100, 100, 0.5); + var mixed1 = unicolour1.MixLuv(unicolour2, 0.75); + var mixed2 = unicolour2.MixLuv(unicolour1, 0.75); + + AssertMixed(mixed1, (60, -50, 50, 0.625)); + AssertMixed(mixed2, (20, 50, -50, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromLuv(0, 100, -100); + var unicolour2 = Unicolour.FromLuv(80, -100, 100, 0.5); + var mixed1 = unicolour1.MixLuv(unicolour2, 0.25); + var mixed2 = unicolour2.MixLuv(unicolour1, 0.25); + + AssertMixed(mixed1, (20, 50, -50, 0.875)); + AssertMixed(mixed2, (60, -50, 50, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromLuv(20, -25.6, 25.6, 0.8); + var unicolour2 = Unicolour.FromLuv(30, 25.6, -25.6, 0.9); + var mixed1 = unicolour1.MixLuv(unicolour2, 1.5); + var mixed2 = unicolour2.MixLuv(unicolour1, 1.5); + + AssertMixed(mixed1, (35, 51.2, -51.2, 0.95)); + AssertMixed(mixed2, (15, -51.2, 51.2, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromLuv(20, -25.6, 25.6, 0.8); + var unicolour2 = Unicolour.FromLuv(30, 25.6, -25.6, 0.9); + var mixed1 = unicolour1.MixLuv(unicolour2, -0.5); + var mixed2 = unicolour2.MixLuv(unicolour1, -0.5); + + AssertMixed(mixed1, (15, -51.2, 51.2, 0.75)); + AssertMixed(mixed2, (35, 51.2, -51.2, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Luv.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixOklabTests.cs b/Unicolour.Tests/MixOklabTests.cs new file mode 100644 index 00000000..7d043118 --- /dev/null +++ b/Unicolour.Tests/MixOklabTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixOklabTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromOklab(0.5, -0.25, 0.25, 0.5); + var unicolour2 = Unicolour.FromOklab(0.5, -0.25, 0.25, 0.5); + var mixed1 = unicolour1.MixOklab(unicolour2, 0.25); + var mixed2 = unicolour2.MixOklab(unicolour1, 0.75); + var mixed3 = unicolour1.MixOklab(unicolour2, 0.75); + var mixed4 = unicolour2.MixOklab(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed2, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed3, (0.5, -0.25, 0.25, 0.5)); + AssertMixed(mixed4, (0.5, -0.25, 0.25, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromOklab(0.0, -0.5, -0.5, 0.0); + var unicolour2 = Unicolour.FromOklab(0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixOklab(unicolour2, 0.5); + var mixed2 = unicolour2.MixOklab(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.0, 0.0, 0.5)); + AssertMixed(mixed2, (0.25, 0.0, 0.0, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromOklab(0, 0.5, -0.5); + var unicolour2 = Unicolour.FromOklab(0.8, -0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixOklab(unicolour2, 0.75); + var mixed2 = unicolour2.MixOklab(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, -0.25, 0.25, 0.625)); + AssertMixed(mixed2, (0.2, 0.25, -0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromOklab(0, 0.5, -0.5); + var unicolour2 = Unicolour.FromOklab(0.8, -0.5, 0.5, 0.5); + var mixed1 = unicolour1.MixOklab(unicolour2, 0.25); + var mixed2 = unicolour2.MixOklab(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.25, -0.25, 0.875)); + AssertMixed(mixed2, (0.6, -0.25, 0.25, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromOklab(0.2, -0.125, 0.125, 0.8); + var unicolour2 = Unicolour.FromOklab(0.3, 0.125, -0.125, 0.9); + var mixed1 = unicolour1.MixOklab(unicolour2, 1.5); + var mixed2 = unicolour2.MixOklab(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.25, -0.25, 0.95)); + AssertMixed(mixed2, (0.15, -0.25, 0.25, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromOklab(0.2, -0.125, 0.125, 0.8); + var unicolour2 = Unicolour.FromOklab(0.3, 0.125, -0.125, 0.9); + var mixed1 = unicolour1.MixOklab(unicolour2, -0.5); + var mixed2 = unicolour2.MixOklab(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, -0.25, 0.25, 0.75)); + AssertMixed(mixed2, (0.35, 0.25, -0.25, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Oklab.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixOklchTests.cs b/Unicolour.Tests/MixOklchTests.cs new file mode 100644 index 00000000..85a384dd --- /dev/null +++ b/Unicolour.Tests/MixOklchTests.cs @@ -0,0 +1,124 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixOklchTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromOklch(0.5, 0.25, 180, 0.5); + var unicolour2 = Unicolour.FromOklch(0.5, 0.25, 180, 0.5); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.25); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.75); + var mixed3 = unicolour1.MixOklch(unicolour2, 0.75); + var mixed4 = unicolour2.MixOklch(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, 0.25, 180, 0.5)); + AssertMixed(mixed2, (0.5, 0.25, 180, 0.5)); + AssertMixed(mixed3, (0.5, 0.25, 180, 0.5)); + AssertMixed(mixed4, (0.5, 0.25, 180, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromOklch(0, 0, 0, 0.0); + var unicolour2 = Unicolour.FromOklch(0.5, 0.5, 180); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.5); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.25, 90, 0.5)); + AssertMixed(mixed2, (0.25, 0.25, 90, 0.5)); + } + + [Test] + public void EquidistantViaZero() + { + var unicolour1 = Unicolour.FromOklch(0, 0, 0, 0); + var unicolour2 = Unicolour.FromOklch(0.8, 0.25, 340, 0.2); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.5); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.5); + + AssertMixed(mixed1, (0.4, 0.125, 350, 0.1)); + AssertMixed(mixed2, (0.4, 0.125, 350, 0.1)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromOklch(0, 0.5, 0); + var unicolour2 = Unicolour.FromOklch(0.8, 0, 180, 0.5); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.75); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, 0.125, 135, 0.625)); + AssertMixed(mixed2, (0.2, 0.375, 45, 0.875)); + } + + [Test] + public void CloserToEndColourViaZero() + { + var unicolour1 = Unicolour.FromOklch(0, 0.5, 300); + var unicolour2 = Unicolour.FromOklch(0.8, 0, 60, 0.5); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.75); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, 0.125, 30, 0.625)); + AssertMixed(mixed2, (0.2, 0.375, 330, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromOklch(0, 0.5, 0); + var unicolour2 = Unicolour.FromOklch(0.8, 0, 180, 0.5); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.25); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.375, 45, 0.875)); + AssertMixed(mixed2, (0.6, 0.125, 135, 0.625)); + } + + [Test] + public void CloserToStartColourViaZero() + { + var unicolour1 = Unicolour.FromOklch(0, 0.5, 300); + var unicolour2 = Unicolour.FromOklch(0.8, 0, 60, 0.5); + var mixed1 = unicolour1.MixOklch(unicolour2, 0.25); + var mixed2 = unicolour2.MixOklch(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.375, 330, 0.875)); + AssertMixed(mixed2, (0.6, 0.125, 30, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromOklch(0.2, 0.2, 0, 0.8); + var unicolour2 = Unicolour.FromOklch(0.3, 0.3, 90, 0.9); + var mixed1 = unicolour1.MixOklch(unicolour2, 1.5); + var mixed2 = unicolour2.MixOklch(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.35, 135, 0.95)); + AssertMixed(mixed2, (0.15, 0.15, 315, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromOklch(0.2, 0.2, 0, 0.8); + var unicolour2 = Unicolour.FromOklch(0.3, 0.3, 90, 0.9); + var mixed1 = unicolour1.MixOklch(unicolour2, -0.5); + var mixed2 = unicolour2.MixOklch(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, 0.15, 315, 0.75)); + AssertMixed(mixed2, (0.35, 0.35, 135, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Oklch.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixRgbTests.cs b/Unicolour.Tests/MixRgbTests.cs new file mode 100644 index 00000000..e8ec4fc1 --- /dev/null +++ b/Unicolour.Tests/MixRgbTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixRgbTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromRgb(0.5, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromRgb(0.5, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixRgb(unicolour2, 0.25); + var mixed2 = unicolour2.MixRgb(unicolour1, 0.75); + var mixed3 = unicolour1.MixRgb(unicolour2, 0.75); + var mixed4 = unicolour2.MixRgb(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (0.5, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromRgb(0.0, 0.0, 0.0, 0.0); + var unicolour2 = Unicolour.FromRgb(0.5, 1.0, 1.0); + var mixed1 = unicolour1.MixRgb(unicolour2, 0.5); + var mixed2 = unicolour2.MixRgb(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (0.25, 0.5, 0.5, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromRgb(0, 1, 0); + var unicolour2 = Unicolour.FromRgb(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixRgb(unicolour2, 0.75); + var mixed2 = unicolour2.MixRgb(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (0.2, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromRgb(0.0, 1.0, 0.0); + var unicolour2 = Unicolour.FromRgb(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixRgb(unicolour2, 0.25); + var mixed2 = unicolour2.MixRgb(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (0.6, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromRgb(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromRgb(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixRgb(unicolour2, 1.5); + var mixed2 = unicolour2.MixRgb(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (0.15, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromRgb(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromRgb(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixRgb(unicolour2, -0.5); + var mixed2 = unicolour2.MixRgb(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (0.35, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Rgb.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixXyyTests.cs b/Unicolour.Tests/MixXyyTests.cs new file mode 100644 index 00000000..0770e900 --- /dev/null +++ b/Unicolour.Tests/MixXyyTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixXyyTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromXyy(0.5, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromXyy(0.5, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixXyy(unicolour2, 0.25); + var mixed2 = unicolour2.MixXyy(unicolour1, 0.75); + var mixed3 = unicolour1.MixXyy(unicolour2, 0.75); + var mixed4 = unicolour2.MixXyy(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (0.5, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromXyy(0.0, 0.0, 0.0, 0.0); + var unicolour2 = Unicolour.FromXyy(0.5, 1.0, 1.0); + var mixed1 = unicolour1.MixXyy(unicolour2, 0.5); + var mixed2 = unicolour2.MixXyy(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (0.25, 0.5, 0.5, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromXyy(0, 1, 0); + var unicolour2 = Unicolour.FromXyy(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixXyy(unicolour2, 0.75); + var mixed2 = unicolour2.MixXyy(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (0.2, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromXyy(0.0, 1.0, 0.0); + var unicolour2 = Unicolour.FromXyy(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixXyy(unicolour2, 0.25); + var mixed2 = unicolour2.MixXyy(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (0.6, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromXyy(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromXyy(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixXyy(unicolour2, 1.5); + var mixed2 = unicolour2.MixXyy(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (0.15, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromXyy(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromXyy(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixXyy(unicolour2, -0.5); + var mixed2 = unicolour2.MixXyy(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (0.35, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Xyy.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/MixXyzTests.cs b/Unicolour.Tests/MixXyzTests.cs new file mode 100644 index 00000000..1db8a0ee --- /dev/null +++ b/Unicolour.Tests/MixXyzTests.cs @@ -0,0 +1,88 @@ +namespace Wacton.Unicolour.Tests; + +using NUnit.Framework; +using Wacton.Unicolour.Tests.Utils; + +public class MixXyzTests +{ + [Test] + public void SameColour() + { + var unicolour1 = Unicolour.FromXyz(0.5, 0.25, 0.75, 0.5); + var unicolour2 = Unicolour.FromXyz(0.5, 0.25, 0.75, 0.5); + var mixed1 = unicolour1.MixXyz(unicolour2, 0.25); + var mixed2 = unicolour2.MixXyz(unicolour1, 0.75); + var mixed3 = unicolour1.MixXyz(unicolour2, 0.75); + var mixed4 = unicolour2.MixXyz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed2, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed3, (0.5, 0.25, 0.75, 0.5)); + AssertMixed(mixed4, (0.5, 0.25, 0.75, 0.5)); + } + + [Test] + public void Equidistant() + { + var unicolour1 = Unicolour.FromXyz(0.0, 0.0, 0.0, 0.0); + var unicolour2 = Unicolour.FromXyz(0.5, 1.0, 1.0); + var mixed1 = unicolour1.MixXyz(unicolour2, 0.5); + var mixed2 = unicolour2.MixXyz(unicolour1, 0.5); + + AssertMixed(mixed1, (0.25, 0.5, 0.5, 0.5)); + AssertMixed(mixed2, (0.25, 0.5, 0.5, 0.5)); + } + + [Test] + public void CloserToEndColour() + { + var unicolour1 = Unicolour.FromXyz(0, 1, 0); + var unicolour2 = Unicolour.FromXyz(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixXyz(unicolour2, 0.75); + var mixed2 = unicolour2.MixXyz(unicolour1, 0.75); + + AssertMixed(mixed1, (0.6, 0.25, 0.75, 0.625)); + AssertMixed(mixed2, (0.2, 0.75, 0.25, 0.875)); + } + + [Test] + public void CloserToStartColour() + { + var unicolour1 = Unicolour.FromXyz(0.0, 1.0, 0.0); + var unicolour2 = Unicolour.FromXyz(0.8, 0.0, 1.0, 0.5); + var mixed1 = unicolour1.MixXyz(unicolour2, 0.25); + var mixed2 = unicolour2.MixXyz(unicolour1, 0.25); + + AssertMixed(mixed1, (0.2, 0.75, 0.25, 0.875)); + AssertMixed(mixed2, (0.6, 0.25, 0.75, 0.625)); + } + + [Test] + public void BeyondEndColour() + { + var unicolour1 = Unicolour.FromXyz(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromXyz(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixXyz(unicolour2, 1.5); + var mixed2 = unicolour2.MixXyz(unicolour1, 1.5); + + AssertMixed(mixed1, (0.35, 0.7, 0.3, 0.95)); + AssertMixed(mixed2, (0.15, 0.3, 0.7, 0.75)); + } + + [Test] + public void BeyondStartColour() + { + var unicolour1 = Unicolour.FromXyz(0.2, 0.4, 0.6, 0.8); + var unicolour2 = Unicolour.FromXyz(0.3, 0.6, 0.4, 0.9); + var mixed1 = unicolour1.MixXyz(unicolour2, -0.5); + var mixed2 = unicolour2.MixXyz(unicolour1, -0.5); + + AssertMixed(mixed1, (0.15, 0.3, 0.7, 0.75)); + AssertMixed(mixed2, (0.35, 0.7, 0.3, 0.95)); + } + + private static void AssertMixed(Unicolour unicolour, (double first, double second, double third, double alpha) expected) + { + AssertUtils.AssertMixed(unicolour.Xyz.Triplet, unicolour.Alpha.A, expected); + } +} \ No newline at end of file diff --git a/Unicolour.Tests/README.md b/Unicolour.Tests/README.md index 9a8a7165..b1e548f7 100644 --- a/Unicolour.Tests/README.md +++ b/Unicolour.Tests/README.md @@ -2,8 +2,8 @@ Tests to add / update for new colour spaces: - Smoke tests - Known value conversion tests (if data available, e.g. Oklab, Hsluv) - Roundtrip conversion tests -- Interpolation tests -- Greyscale interpolation tests (if colour space has hue component) +- Mixing tests +- Greyscale mixing tests (if colour space has hue component) - Hued tests (if colour space has hue component) - Equality tests - Extreme values tests diff --git a/Unicolour.Tests/Utils/AssertUtils.cs b/Unicolour.Tests/Utils/AssertUtils.cs index 30c3408e..48b813b3 100644 --- a/Unicolour.Tests/Utils/AssertUtils.cs +++ b/Unicolour.Tests/Utils/AssertUtils.cs @@ -9,7 +9,7 @@ internal static class AssertUtils { public static List AllColourSpaces => Enum.GetValues().ToList(); - public const double InterpolationTolerance = 0.00000000005; + public const double MixTolerance = 0.00000000005; public static void AssertTriplet(ColourTriplet actual, ColourTriplet expected, double tolerance, string? info = null) { @@ -45,21 +45,19 @@ private static void AssertNormalisedForHue(double actualHue, double expectedHue, .Or.EqualTo(expectedMinus360).Within(tolerance), failMessage); } - - public static void AssertInterpolated(ColourTriplet triplet, double alpha, (double first, double second, double third, double alpha) expected) + + public static void AssertMixed(ColourTriplet triplet, double alpha, (double first, double second, double third, double alpha) expected) { - Assert.That(triplet.First, Is.EqualTo(expected.first).Within(InterpolationTolerance)); - Assert.That(triplet.Second, Is.EqualTo(expected.second).Within(InterpolationTolerance)); - Assert.That(triplet.Third, Is.EqualTo(expected.third).Within(InterpolationTolerance)); - Assert.That(alpha, Is.EqualTo(expected.alpha).Within(InterpolationTolerance)); + Assert.That(triplet.First, Is.EqualTo(expected.first).Within(MixTolerance)); + Assert.That(triplet.Second, Is.EqualTo(expected.second).Within(MixTolerance)); + Assert.That(triplet.Third, Is.EqualTo(expected.third).Within(MixTolerance)); + Assert.That(alpha, Is.EqualTo(expected.alpha).Within(MixTolerance)); } public static void AssertNoPropertyError(Unicolour unicolour) { - void AccessProperty(Func getProperty) - { - var _ = getProperty(); - } + Assert.DoesNotThrow(AccessProperties); + return; void AccessProperties() { @@ -92,6 +90,9 @@ void AccessProperties() AccessProperty(() => unicolour.Xyz); } - Assert.DoesNotThrow(AccessProperties); + void AccessProperty(Func getProperty) + { + _ = getProperty(); + } } } \ No newline at end of file diff --git a/Unicolour.Tests/Utils/TestColour.cs b/Unicolour.Tests/Utils/TestColour.cs index ee24736a..61b086bc 100644 --- a/Unicolour.Tests/Utils/TestColour.cs +++ b/Unicolour.Tests/Utils/TestColour.cs @@ -40,7 +40,7 @@ public class TestColour /* * ColorMine and Colourful treats xyY black as (0,0,0) - * whereas Unicolour uses white chromaticity with 0 lumninance for accurate interpolation + * whereas Unicolour uses white chromaticity with 0 luminance for accurate mixing */ public bool ExcludeFromXyyTests => ExcludeFromXyyTestReasons.Any(); public List ExcludeFromXyyTestReasons { get; init; } = new(); diff --git a/Unicolour/ColourRepresentation.cs b/Unicolour/ColourRepresentation.cs index 8e58dc62..7ac4a3af 100644 --- a/Unicolour/ColourRepresentation.cs +++ b/Unicolour/ColourRepresentation.cs @@ -33,9 +33,9 @@ public abstract record ColourRepresentation * enabling differentiation between representations where: * a) a hue value is meaningful ------------------------------ e.g. HSB(0,0,0) = red with no saturation or brightness * b) a hue value is used as a fallback when there is no hue - e.g. RGB(0,0,0) -> HSB(0,0,0) = black with no red - * which is essential for proper interpolation; + * which is essential for proper mixing; * [RGB(0,0,0) black -> RGB(0,0,255) blue] via HSB is [HSB(0,0,0) red with no colour -> HSB(240,1,1) blue with full colour] - * but the interpolation should only start at the red hue if the value 0 was provided by the user (FromHsb instead of FromRgb) + * but the mixing should only start at the red hue if the value 0 was provided by the user (FromHsb instead of FromRgb) */ internal bool HasHueAxis => HueIndex != null; internal bool UseAsHued => (Heritage == ColourHeritage.None || Heritage == ColourHeritage.Hued || Heritage == ColourHeritage.GreyscaleAndHued) && !UseAsNaN && HasHueAxis; diff --git a/Unicolour/Comparison.cs b/Unicolour/Comparison.cs index a421f2bf..59af720a 100644 --- a/Unicolour/Comparison.cs +++ b/Unicolour/Comparison.cs @@ -2,11 +2,11 @@ using static Utils; -public static class Comparison +internal static class Comparison { // https://www.w3.org/WAI/WCAG21/Techniques/general/G18.html#tests // minimal recommended contrast ratio is 4.5, or 3 for larger font-sizes - public static double Contrast(this Unicolour colour1, Unicolour colour2) + internal static double Contrast(Unicolour colour1, Unicolour colour2) { var luminance1 = colour1.RelativeLuminance; var luminance2 = colour2.RelativeLuminance; @@ -16,7 +16,7 @@ public static double Contrast(this Unicolour colour1, Unicolour colour2) } // https://en.wikipedia.org/wiki/Color_difference#CIE76 - public static double DeltaE76(this Unicolour reference, Unicolour sample) + internal static double DeltaE76(Unicolour reference, Unicolour sample) { var (l1, a1, b1) = reference.Lab.Triplet; var (l2, a2, b2) = sample.Lab.Triplet; @@ -24,7 +24,7 @@ public static double DeltaE76(this Unicolour reference, Unicolour sample) } // https://en.wikipedia.org/wiki/Color_difference#CIE94 - public static double DeltaE94(this Unicolour reference, Unicolour sample, bool isForTextiles = false) + internal static double DeltaE94(Unicolour reference, Unicolour sample, bool isForTextiles = false) { var (l1, a1, b1) = reference.Lab.Triplet; var (l2, a2, b2) = sample.Lab.Triplet; @@ -55,7 +55,7 @@ public static double DeltaE94(this Unicolour reference, Unicolour sample, bool i } // https://en.wikipedia.org/wiki/Color_difference#CIEDE2000 - public static double DeltaE00(this Unicolour reference, Unicolour sample) + internal static double DeltaE00(Unicolour reference, Unicolour sample) { var (l1, a1, b1) = reference.Lab.Triplet; var (l2, a2, b2) = sample.Lab.Triplet; @@ -127,7 +127,7 @@ public static double DeltaE00(this Unicolour reference, Unicolour sample) } // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2124-0-201901-I!!PDF-E.pdf - public static double DeltaEItp(this Unicolour reference, Unicolour sample) + internal static double DeltaEItp(Unicolour reference, Unicolour sample) { ColourTriplet ToItp(Ictcp ictcp) => new(ictcp.I, 0.5 * ictcp.Ct, ictcp.Cp); var (i1, t1, c1) = ToItp(reference.Ictcp); @@ -136,7 +136,7 @@ public static double DeltaEItp(this Unicolour reference, Unicolour sample) } // https://doi.org/10.1364/OE.25.015131 - public static double DeltaEz(this Unicolour reference, Unicolour sample) + internal static double DeltaEz(Unicolour reference, Unicolour sample) { var (jz1, cz1, hz1) = reference.Jzczhz.Triplet; var (jz2, cz2, hz2) = sample.Jzczhz.Triplet; @@ -148,7 +148,7 @@ public static double DeltaEz(this Unicolour reference, Unicolour sample) } // https://en.wikipedia.org/wiki/Color_difference#Other_geometric_constructions - public static double DeltaEHyab(this Unicolour reference, Unicolour sample) + internal static double DeltaEHyab(Unicolour reference, Unicolour sample) { var (l1, a1, b1) = reference.Lab.Triplet; var (l2, a2, b2) = sample.Lab.Triplet; @@ -156,7 +156,7 @@ public static double DeltaEHyab(this Unicolour reference, Unicolour sample) } // https://www.w3.org/TR/css-color-4/#color-difference-OK - public static double DeltaEOk(this Unicolour reference, Unicolour sample) + internal static double DeltaEOk(Unicolour reference, Unicolour sample) { var (l1, a1, b1) = reference.Oklab.Triplet; var (l2, a2, b2) = sample.Oklab.Triplet; @@ -165,7 +165,7 @@ public static double DeltaEOk(this Unicolour reference, Unicolour sample) // https://doi.org/10.1007/978-1-4419-6190-7_2 // currently only support UCS, not LCD or SCD - no need to handle ΔJ / kl since kl = 1 - public static double DeltaECam02(this Unicolour reference, Unicolour sample) + internal static double DeltaECam02(Unicolour reference, Unicolour sample) { var (j1, a1, b1) = reference.Cam02.Triplet; var (j2, a2, b2) = sample.Cam02.Triplet; @@ -173,7 +173,7 @@ public static double DeltaECam02(this Unicolour reference, Unicolour sample) } // https://doi.org/10.1002/col.22131 - public static double DeltaECam16(this Unicolour reference, Unicolour sample) + internal static double DeltaECam16(Unicolour reference, Unicolour sample) { var (j1, a1, b1) = reference.Cam16.Triplet; var (j2, a2, b2) = sample.Cam16.Triplet; diff --git a/Unicolour/Interpolation.cs b/Unicolour/Interpolation.cs index e502d92a..e24fc203 100644 --- a/Unicolour/Interpolation.cs +++ b/Unicolour/Interpolation.cs @@ -1,29 +1,8 @@ namespace Wacton.Unicolour; -public static class Interpolation +internal static class Interpolation { - public static Unicolour InterpolateRgb(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Rgb, start, end, distance); - public static Unicolour InterpolateHsb(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hsb, start, end, distance); - public static Unicolour InterpolateHsl(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hsl, start, end, distance); - public static Unicolour InterpolateHwb(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hwb, start, end, distance); - public static Unicolour InterpolateXyz(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Xyz, start, end, distance); - public static Unicolour InterpolateXyy(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Xyy, start, end, distance); - public static Unicolour InterpolateLab(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Lab, start, end, distance); - public static Unicolour InterpolateLchab(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Lchab, start, end, distance); - public static Unicolour InterpolateLuv(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Luv, start, end, distance); - public static Unicolour InterpolateLchuv(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Lchuv, start, end, distance); - public static Unicolour InterpolateHsluv(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hsluv, start, end, distance); - public static Unicolour InterpolateHpluv(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hpluv, start, end, distance); - public static Unicolour InterpolateIctcp(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Ictcp, start, end, distance); - public static Unicolour InterpolateJzazbz(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Jzazbz, start, end, distance); - public static Unicolour InterpolateJzczhz(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Jzczhz, start, end, distance); - public static Unicolour InterpolateOklab(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Oklab, start, end, distance); - public static Unicolour InterpolateOklch(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Oklch, start, end, distance); - public static Unicolour InterpolateCam02(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Cam02, start, end, distance); - public static Unicolour InterpolateCam16(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Cam16, start, end, distance); - public static Unicolour InterpolateHct(this Unicolour start, Unicolour end, double distance) => Interpolate(ColourSpace.Hct, start, end, distance); - - internal static Unicolour Interpolate(ColourSpace colourSpace, Unicolour startColour, Unicolour endColour, double distance) + internal static Unicolour Mix(ColourSpace colourSpace, Unicolour startColour, Unicolour endColour, double distance) { GuardConfiguration(startColour, endColour); @@ -98,7 +77,7 @@ private static void GuardConfiguration(Unicolour unicolour1, Unicolour unicolour { if (unicolour1.Config != unicolour2.Config) { - throw new InvalidOperationException("Can only interpolate unicolours with the same configuration reference"); + throw new InvalidOperationException("Can only mix unicolours with the same configuration reference"); } } diff --git a/Unicolour/Unicolour.cs b/Unicolour/Unicolour.cs index e7f3af68..8a50fd9c 100644 --- a/Unicolour/Unicolour.cs +++ b/Unicolour/Unicolour.cs @@ -63,17 +63,49 @@ private Unicolour(Configuration config, ColourRepresentation initialRepresentati SetBackingField(InitialColourSpace); } + public double Contrast(Unicolour other) => Comparison.Contrast(this, other); + public double DeltaE76(Unicolour sample) => Comparison.DeltaE76(this, sample); + public double DeltaE94(Unicolour sample, bool isForTextiles = false) => Comparison.DeltaE94(this, sample, isForTextiles); + public double DeltaE00(Unicolour sample) => Comparison.DeltaE00(this, sample); + public double DeltaEItp(Unicolour sample) => Comparison.DeltaEItp(this, sample); + public double DeltaEz(Unicolour sample) => Comparison.DeltaEz(this, sample); + public double DeltaEHyab(Unicolour sample) => Comparison.DeltaEHyab(this, sample); + public double DeltaEOk(Unicolour sample) => Comparison.DeltaEOk(this, sample); + public double DeltaECam02(Unicolour sample) => Comparison.DeltaECam02(this, sample); + public double DeltaECam16(Unicolour sample) => Comparison.DeltaECam16(this, sample); + + public Unicolour MixRgb(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Rgb, this, other, amount); + public Unicolour MixHsb(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hsb, this, other, amount); + public Unicolour MixHsl(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hsl, this, other, amount); + public Unicolour MixHwb(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hwb, this, other, amount); + public Unicolour MixXyz(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Xyz, this, other, amount); + public Unicolour MixXyy(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Xyy, this, other, amount); + public Unicolour MixLab(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Lab, this, other, amount); + public Unicolour MixLchab(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Lchab, this, other, amount); + public Unicolour MixLuv(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Luv, this, other, amount); + public Unicolour MixLchuv(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Lchuv, this, other, amount); + public Unicolour MixHsluv(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hsluv, this, other, amount); + public Unicolour MixHpluv(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hpluv, this, other, amount); + public Unicolour MixIctcp(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Ictcp, this, other, amount); + public Unicolour MixJzazbz(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Jzazbz, this, other, amount); + public Unicolour MixJzczhz(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Jzczhz, this, other, amount); + public Unicolour MixOklab(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Oklab, this, other, amount); + public Unicolour MixOklch(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Oklch, this, other, amount); + public Unicolour MixCam02(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Cam02, this, other, amount); + public Unicolour MixCam16(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Cam16, this, other, amount); + public Unicolour MixHct(Unicolour other, double amount = 0.5) => Interpolation.Mix(ColourSpace.Hct, this, other, amount); + + public Unicolour SimulateProtanopia() => VisionDeficiency.SimulateProtanopia(Rgb, Config); + public Unicolour SimulateDeuteranopia() => VisionDeficiency.SimulateDeuteranopia(Rgb, Config); + public Unicolour SimulateTritanopia() => VisionDeficiency.SimulateTritanopia(Rgb, Config); + public Unicolour SimulateAchromatopsia() => VisionDeficiency.SimulateAchromatopsia(RelativeLuminance, Config); + public Unicolour ConvertToConfiguration(Configuration newConfig) { var xyzMatrix = Matrix.FromTriplet(Xyz.Triplet); var adaptedMatrix = Adaptation.WhitePoint(xyzMatrix, Config.Xyz.WhitePoint, newConfig.Xyz.WhitePoint); return FromXyz(newConfig, adaptedMatrix.ToTriplet().Tuple, Alpha.A); } - - public Unicolour SimulateProtanopia() => VisionDeficiency.SimulateProtanopia(Rgb, Config); - public Unicolour SimulateDeuteranopia() => VisionDeficiency.SimulateDeuteranopia(Rgb, Config); - public Unicolour SimulateTritanopia() => VisionDeficiency.SimulateTritanopia(Rgb, Config); - public Unicolour SimulateAchromatopsia() => VisionDeficiency.SimulateAchromatopsia(RelativeLuminance, Config); public override string ToString() { diff --git a/Unicolour/Unicolour.csproj b/Unicolour/Unicolour.csproj index 74a24f6b..c4c98062 100644 --- a/Unicolour/Unicolour.csproj +++ b/Unicolour/Unicolour.csproj @@ -15,9 +15,9 @@ netstandard2.0 True Resources\Unicolour.png - 2.5.0 - colour color RGB HSB HSV HSL HWB XYZ xyY LAB LUV LCH LCHab LCHuv HSLuv HPLuv ICtCp JzAzBz JzCzHz Oklab Oklch CAM02 CAM16 HCT converter colour-converter colour-conversion color-converter color-conversion colour-space colour-spaces color-space color-spaces interpolation colour-interpolation color-interpolation comparison colour-comparison color-comparison contrast luminance deltaE chromaticity display-p3 rec-2020 temperature cct duv cvd colour-vision-deficiency color-vision-deficiency colour-blindness color-blindness protanopia deuteranopia tritanopia achromatopsia - Add HCT support + 3.0.0 + colour color RGB HSB HSV HSL HWB XYZ xyY LAB LUV LCH LCHab LCHuv HSLuv HPLuv ICtCp JzAzBz JzCzHz Oklab Oklch CAM02 CAM16 HCT converter colour-converter colour-conversion color-converter color-conversion colour-space colour-spaces color-space color-spaces interpolation colour-interpolation color-interpolation colour-mixing color-mixing comparison colour-comparison color-comparison contrast luminance deltaE chromaticity display-p3 rec-2020 temperature cct duv cvd colour-vision-deficiency color-vision-deficiency colour-blindness color-blindness protanopia deuteranopia tritanopia achromatopsia + TODO: Resources\Unicolour.ico LICENSE