-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from kimikage/msc
Fix erroneous `MSC(h)` and improve accuracy of `MSC(h, l)` (#349)
- Loading branch information
Showing
3 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
using Test, Colors | ||
|
||
@testset "Algorithms" begin | ||
@test isconcretetype(eltype(colormap("Grays"))) | ||
|
||
@test_throws ArgumentError colormap("Grays", N=10) | ||
# issue #349 | ||
msc_h_diff = 0 | ||
for hsv_h in 0:0.1:360 | ||
hsv = HSV(hsv_h, 1.0, 1.0) # most saturated | ||
lch = convert(LCHuv, hsv) | ||
msc = MSC(lch.h) | ||
msc_h_diff = max(msc_h_diff, colordiff(msc, lch)) | ||
end | ||
@test msc_h_diff < 1 | ||
|
||
@test MSC(123.45, 100) ≈ 0 | ||
@test MSC(123.45, 0) ≈ 0 | ||
|
||
msc_h_l_sat = 1 | ||
for h = 0:0.1:359.9, l = 1:1:99 | ||
c = MSC(h, l) | ||
hsv = convert(HSV, LCHuv(l, c, h)) | ||
# When the color is saturated (except black/white), `s` or `v` is 1. | ||
msc_h_l_sat = min(msc_h_l_sat, max(hsv.s, hsv.v)) | ||
end | ||
@test msc_h_l_sat > 1 - 1e-4 | ||
|
||
# the linear interpolation introduces some approximation errors.(issue #349) | ||
@test MSC(0, 90, linear=true) > MSC(0, 90) | ||
@test MSC(280, 50, linear=true) < MSC(280, 50) | ||
|
||
col = distinguishable_colors(10) | ||
@test isconcretetype(eltype(col)) | ||
local mindiff | ||
mindiff = Inf | ||
for i = 1:10 | ||
for j = i+1:10 | ||
mindiff = min(mindiff, colordiff(col[i], col[j])) | ||
end | ||
@testset "find_maximum_chroma hsv_h=$hsv_h" for hsv_h in 0:60:300 | ||
hsv = HSV(hsv_h, 1.0, 1.0) # corner | ||
lchab = convert(LCHab, hsv) | ||
lchuv = convert(LCHuv, hsv) | ||
lab = convert(Lab, hsv) | ||
luv = convert(Luv, hsv) | ||
@test Colors.find_maximum_chroma(lchab) ≈ lchab.c atol=0.01 | ||
@test Colors.find_maximum_chroma(lchuv) ≈ lchuv.c atol=0.01 | ||
@test Colors.find_maximum_chroma(lab) ≈ lchab.c atol=0.01 | ||
@test Colors.find_maximum_chroma(luv) ≈ lchuv.c atol=0.01 | ||
end | ||
@test mindiff > 8 | ||
|
||
cols = distinguishable_colors(1) | ||
@test colordiff(distinguishable_colors(1, cols; dropseed=true)[1], cols[1]) > 50 | ||
# yellow in LCHab | ||
@test Colors.find_maximum_chroma(LCHab(94.2, 0, 100)) ≈ 93.749 atol=0.01 | ||
@test Colors.find_maximum_chroma(LCHab(97.6, 0, 105)) ≈ 68.828 atol=0.01 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
@testset "Colormaps" begin | ||
col = distinguishable_colors(10) | ||
@test isconcretetype(eltype(col)) | ||
local mindiff | ||
mindiff = Inf | ||
for i = 1:10 | ||
for j = i+1:10 | ||
mindiff = min(mindiff, colordiff(col[i], col[j])) | ||
end | ||
end | ||
@test mindiff > 8 | ||
|
||
cols = distinguishable_colors(1) | ||
@test colordiff(distinguishable_colors(1, cols; dropseed=true)[1], cols[1]) > 50 | ||
|
||
|
||
@test length(colormap("RdBu", 100)) == 100 | ||
|
||
@test isconcretetype(eltype(colormap("Grays"))) | ||
|
||
@test_throws ArgumentError colormap("Grays", N=10) # optional arguments, not keyword | ||
|
||
# The outputs of `colormap()` were slightly affected by the bug fix of | ||
# `MSC(h)` (issue #349). | ||
# The following were generated by `colormap()` in Colors.jl v0.9.6. | ||
blues_old = ["F4FDFF", "B3E3F4", "65B9E7", "2978BE", "0B2857"] | ||
greens_old = ["FAFFF7", "B6EEA0", "75C769", "308B40", "00391A"] | ||
grays_old = ["FFFFFF", "DCDCDC", "A9A9A9", "626262", "000000"] | ||
oranges_old = ["FFFBF6", "FFD6B4", "FF9D5F", "E2500D", "732108"] | ||
purples_old = ["FBFBFB", "DBD7F6", "AFA7E6", "7666BF", "3C0468"] | ||
reds_old = ["FFF1EE", "FFC4B9", "FF8576", "E72823", "6D0B0C"] | ||
rdbu_old = ["610102", "FF8D7B", "F9F8F9", "76B4E8", "092C58"] | ||
|
||
to_rgb(s) = parse(RGB, "#"*s) | ||
max_colordiff(a1, a2) = reduce(max, colordiff.(a1, a2)) | ||
@test max_colordiff(colormap("Blues", 5), to_rgb.(blues_old)) < 1 | ||
@test max_colordiff(colormap("Greens", 5), to_rgb.(greens_old)) < 1 | ||
@test max_colordiff(colormap("Grays", 5), to_rgb.(grays_old)) < 1 | ||
@test max_colordiff(colormap("Oranges", 5), to_rgb.(oranges_old)) < 1 | ||
@test max_colordiff(colormap("Purples", 5), to_rgb.(purples_old)) < 1 | ||
@test max_colordiff(colormap("Reds", 5), to_rgb.(reds_old)) < 1 | ||
@test max_colordiff(colormap("RdBu", 5), to_rgb.(rdbu_old)) < 1 | ||
|
||
# TODO: add more tests | ||
end |