Skip to content

Commit 6ec22e2

Browse files
authored
Merge pull request #304 from fredrikekre/fe/07
fixes for julia 0.7
2 parents 3d53e10 + bef069c commit 6ec22e2

File tree

14 files changed

+72
-71
lines changed

14 files changed

+72
-71
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ os:
33
- osx
44
- linux
55
julia:
6-
- 0.6
6+
- 0.7
77
- nightly
88
notifications:
99
email: false

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ A seed color or array of seed colors may be provided to `distinguishable_colors`
182182
```julia
183183
distinguishable_colors{T<:Color}(n::Integer, seed::AbstractVector{T};
184184
transform::Function = identity,
185-
lchoices::AbstractVector = linspace(0, 100, 15),
186-
cchoices::AbstractVector = linspace(0, 100, 15),
187-
hchoices::AbstractVector = linspace(0, 340, 20)
185+
lchoices::AbstractVector = range(0, stop=100, length=15),
186+
cchoices::AbstractVector = range(0, stop=100, length=15),
187+
hchoices::AbstractVector = range(0, stop=340, length=20)
188188
)
189189
```
190190

191-
By default, `distinguishable_colors` chooses maximally distinguishable colors from the outer product of lightness, chroma and hue values specified by `lchoices = linspace(0, 100, 15)`, `cchoices = linspace(0, 100, 15)`, and `hchoices = linspace(0, 340, 20)`. The set of colors that `distinguishable_colors` chooses from may be specified by passing different choices as keyword arguments.
191+
By default, `distinguishable_colors` chooses maximally distinguishable colors from the outer product of lightness, chroma and hue values specified by `lchoices = range(0, stop=100, length=15)`, `cchoices = range(0, stop=100, length=15)`, and `hchoices = range(0, stop=340, length=20)`. The set of colors that `distinguishable_colors` chooses from may be specified by passing different choices as keyword arguments.
192192

193193
Distinguishability is maximized with respect to the CIEDE2000 color difference formula (see `colordiff`). If a `transform` function is specified, color difference is instead maximized between colors `a` and `b` according to
194194
`colordiff(transform(a), transform(b))`.
@@ -198,18 +198,18 @@ Color arrays generated by `distinguishable_colors` are particularly useful for i
198198
```
199199
vars = 1:10
200200
cols = distinguishable_colors(length(vars)+1,[RGB(1,1,1)])[2:end]
201-
pcols = map(col->(red(col),green(col),blue(col)),cols)
201+
pcols = map(col->(red(col),green(col),blue(col)),cols)
202202
for i = 1:length(vars)
203203
plot(1:10,rand(10),c = pcols[i])
204204
end
205205
```
206206

207-
#### `linspace`
207+
#### `range`
208208

209-
`linspace(c1::Color, c2::Color, n=100)`
209+
`range(start::Color; stop::Color, length=100)`
210210

211-
Generates `n` colors in a linearly interpolated ramp from `c1` to
212-
`c2`, inclusive, returning an `Array` of colors
211+
Generates `n` colors in a linearly interpolated ramp from `start` to
212+
`stop`, inclusive, returning an `Array` of colors
213213

214214
#### `weighted_color_mean`
215215

REQUIRE

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
julia 0.6
2-
ColorTypes 0.6.3
3-
FixedPointNumbers 0.3.0
1+
julia 0.7-alpha
2+
ColorTypes 0.7.0
3+
FixedPointNumbers 0.5.0
44
Reexport
5-
Compat 0.32

src/Colors.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ __precompile__()
22

33
module Colors
44

5-
using FixedPointNumbers, ColorTypes, Reexport, Compat
5+
using FixedPointNumbers, ColorTypes, Reexport, Printf
66
@reexport using ColorTypes
7-
# deprecated exports
8-
export U8, U16
97

108
AbstractGray{T} = Color{T,1}
119
using ColorTypes: TransparentGray
@@ -15,7 +13,7 @@ Color3{T} = Color{T,3}
1513
Transparent4{C<:Color3,T} = TransparentColor{C,T,4}
1614

1715
import Base: ==, +, -, *, /
18-
import Base: convert, eltype, hex, isless, linspace, show, typemin, typemax
16+
import Base: convert, eltype, hex, isless, range, show, typemin, typemax
1917

2018
# Additional exports, not exported by ColorTypes
2119
export weighted_color_mean,
@@ -26,6 +24,12 @@ export weighted_color_mean,
2624
MSC, sequential_palette, diverging_palette, colormap,
2725
colormatch, CIE1931_CMF, CIE1964_CMF, CIE1931J_CMF, CIE1931JV_CMF
2826

27+
# atan(x,y) was introduced after 0.7.0-alpha
28+
@static if VERSION < v"0.7.0-alpha.44"
29+
atan(x, y) = atan2(x, y)
30+
atan(x) = Base.atan(x)
31+
end
32+
2933
# Early utilities
3034
include("utilities.jl")
3135

src/algorithms.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ protanopic(c::Color) = protanopic(c, 1.0)
149149
deuteranopic(c::Color) = deuteranopic(c, 1.0)
150150
tritanopic(c::Color) = tritanopic(c, 1.0)
151151

152-
Compat.@dep_vectorize_1arg Color protanopic
153-
Compat.@dep_vectorize_1arg Color deuteranopic
154-
Compat.@dep_vectorize_1arg Color tritanopic
155-
156152
# MSC - Most Saturated Colorant for given hue h
157153
# ---------------------
158154

src/colormaps.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@ Args:
2323
Keyword arguments:
2424
2525
- `transform`: Transform applied to colors before measuring distance. Default is the identity; other choices include `deuteranopic` to simulate color-blindness.
26-
- `lchoices`: Possible lightness values (default `linspace(0,100,15)`)
27-
- `cchoices`: Possible chroma values (default `linspace(0,100,15)`)
28-
- `hchoices`: Possible hue values (default `linspace(0,340,20)`)
26+
- `lchoices`: Possible lightness values (default `range(0,stop=100,start=15)`)
27+
- `cchoices`: Possible chroma values (default `range(0,stop=100,start=15)`)
28+
- `hchoices`: Possible hue values (default `range(0,stop=340,start=20)`)
2929
3030
Returns:
3131
A `Vector` of colors of length `n`, of the type specified in `seed`.
3232
"""
3333
function distinguishable_colors(n::Integer,
3434
seed::AbstractVector{T};
3535
transform::Function = identity,
36-
lchoices::AbstractVector = linspace(0, 100, 15),
37-
cchoices::AbstractVector = linspace(0, 100, 15),
38-
hchoices::AbstractVector = linspace(0, 340, 20)) where T<:Color
36+
lchoices::AbstractVector = range(0, stop=100, length=15),
37+
cchoices::AbstractVector = range(0, stop=100, length=15),
38+
hchoices::AbstractVector = range(0, stop=340, length=20)) where T<:Color
3939
if n <= length(seed)
4040
return seed[1:n]
4141
end
4242

4343
# Candidate colors
4444
N = length(lchoices)*length(cchoices)*length(hchoices)
45-
candidate = Vector{Lab{Float64}}(N)
45+
candidate = Vector{Lab{Float64}}(undef, N)
4646
j = 0
4747
for h in hchoices, c in cchoices, l in lchoices
4848
rgb = convert(RGB, LCHab(l, c, h))
4949
candidate[j+=1] = convert(LCHab, rgb)
5050
end
5151

5252
# Transformed colors
53-
candidate_t = Vector{Lab{Float64}}(N)
53+
candidate_t = Vector{Lab{Float64}}(undef, N)
5454
for i = 1:N
5555
candidate_t[i] = transform(candidate[i])
5656
end
5757

5858
# Start with the seed colors
59-
colors = Vector{T}(n)
60-
copy!(colors, seed)
59+
colors = Vector{T}(undef, n)
60+
copyto!(colors, seed)
6161

6262
# Minimum distances of the current color to each previously selected color.
6363
ds = fill(Inf, N)
@@ -69,7 +69,7 @@ function distinguishable_colors(n::Integer,
6969
end
7070

7171
for i in length(seed)+1:n
72-
j = indmax(ds)
72+
j = argmax(ds)
7373
colors[i] = candidate[j]
7474
tc = candidate_t[j]
7575
for k = 1:N
@@ -83,7 +83,7 @@ end
8383

8484

8585
distinguishable_colors(n::Integer, seed::Color; kwargs...) = distinguishable_colors(n, [seed]; kwargs...)
86-
distinguishable_colors(n::Integer; kwargs...) = distinguishable_colors(n, Vector{RGB{N0f8}}(0); kwargs...)
86+
distinguishable_colors(n::Integer; kwargs...) = distinguishable_colors(n, Vector{RGB{N0f8}}(); kwargs...)
8787

8888
@deprecate distinguishable_colors(n::Integer,
8989
transform::Function,
@@ -159,7 +159,7 @@ function sequential_palette(h,
159159
if logscale
160160
absc = logspace(-2.,0.,N)
161161
else
162-
absc = linspace(0.,1.,N)
162+
absc = range(0.,stop=1.,length=N)
163163
end
164164

165165
for t in absc

src/conversions.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ cnvt(::Type{XYZ{T}}, c::LCHuv) where {T} = cnvt(XYZ{T}, convert(Luv{T}, c))
354354
function cnvt(::Type{XYZ{T}}, c::DIN99d) where T
355355

356356
# Go back to C-h space
357-
# FIXME: Clean this up (why is there no atan2d?)
358-
h = rad2deg(atan2(c.b,c.a)) + 50
357+
# FIXME: Clean this up (why is there no atand?)
358+
h = rad2deg(atan(c.b,c.a)) + 50
359359
while h > 360; h -= 360; end
360360
while h < 0; h += 360; end
361361

@@ -492,7 +492,7 @@ function cnvt(::Type{Lab{T}}, c::DIN99o) where T
492492
co = sqrt(c.a^2 + c.b^2)
493493

494494
# hue angle h99o
495-
h = atan2(c.b, c.a)
495+
h = atan(c.b, c.a)
496496

497497
# revert rotation by 26°
498498
ho= rad2deg(h)-26
@@ -559,7 +559,7 @@ cnvt(::Type{Luv{T}}, c::Color3) where {T} = cnvt(Luv{T}, convert(XYZ{T}, c))
559559
# -------------------
560560

561561
function cnvt(::Type{LCHuv{T}}, c::Luv) where T
562-
h = rad2deg(atan2(c.v, c.u))
562+
h = rad2deg(atan(c.v, c.u))
563563
while h > 360; h -= 360; end
564564
while h < 0; h += 360; end
565565
LCHuv{T}(c.l, sqrt(c.u^2 + c.v^2), h)
@@ -573,7 +573,7 @@ cnvt(::Type{LCHuv{T}}, c::Color3) where {T} = cnvt(LCHuv{T}, convert(Luv{T}, c))
573573
# -------------------
574574

575575
function cnvt(::Type{LCHab{T}}, c::Lab) where T
576-
h = rad2deg(atan2(c.b, c.a))
576+
h = rad2deg(atan(c.b, c.a))
577577
while h > 360; h -= 360; end
578578
while h < 0; h += 360; end
579579
LCHab{T}(c.l, sqrt(c.a^2 + c.b^2), h)
@@ -656,8 +656,8 @@ function cnvt(::Type{DIN99d{T}}, c::XYZ{T}) where T
656656

657657
# Calculate hue/chroma
658658
C = 22.5*log(1+0.06*G)
659-
# FIXME: Clean this up (why is there no atan2d?)
660-
h = rad2deg(atan2(f,ee)) + 50
659+
# FIXME: Clean this up (why is there no atand?)
660+
h = rad2deg(atan(f,ee)) + 50
661661
while h > 360; h -= 360; end
662662
while h < 0; h += 360; end
663663

@@ -692,7 +692,7 @@ function cnvt(::Type{DIN99o{T}}, c::Lab) where T
692692

693693
# Temporary value for chroma
694694
go = sqrt(eo^2 + fo^2)
695-
ho = atan2(fo,eo)
695+
ho = atan(fo,eo)
696696
# rotation of the color space by 26°
697697
h = rad2deg(ho) + 26
698698

src/parse.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ const col_pat_hsla = r"hsla\((\d+%?),(\d+%?),(\d+%?),(\d+(?:\.\d*)?%?)\)"
1515
# Parse a number used in the "rgb()" or "hsl()" color.
1616
function parse_rgb(num::AbstractString)
1717
if num[end] == '%'
18-
return clamp(parse(Int, num[1:end-1], 10) / 100, 0, 1)
18+
return clamp(parse(Int, num[1:end-1], base=10) / 100, 0, 1)
1919
else
20-
return clamp(parse(Int, num, 10) / 255, 0, 1)
20+
return clamp(parse(Int, num, base=10) / 255, 0, 1)
2121
end
2222
end
2323

2424
function parse_hsl_hue(num::AbstractString)
2525
if num[end] == '%'
2626
error("hue cannot end in %")
2727
else
28-
return parse(Int, num, 10)
28+
return parse(Int, num, base=10)
2929
end
3030
end
3131

3232
function parse_hsl_sl(num::AbstractString)
3333
if num[end] != '%'
3434
error("saturation and lightness must end in %")
3535
else
36-
return parse(Int, num[1:end-1], 10) / 100
36+
return parse(Int, num[1:end-1], base=10) / 100
3737
end
3838
end
3939

@@ -48,19 +48,19 @@ end
4848

4949

5050
function _parse_colorant(desc::AbstractString)
51-
desc_ = replace(desc, " ", "")
51+
desc_ = replace(desc, " " => "")
5252
mat = match(col_pat_hex2, desc_)
5353
if mat != nothing
54-
return RGB{N0f8}(parse(Int, mat.captures[2], 16) / 255,
55-
parse(Int, mat.captures[3], 16) / 255,
56-
parse(Int, mat.captures[4], 16) / 255)
54+
return RGB{N0f8}(parse(Int, mat.captures[2], base=16) / 255,
55+
parse(Int, mat.captures[3], base=16) / 255,
56+
parse(Int, mat.captures[4], base=16) / 255)
5757
end
5858

5959
mat = match(col_pat_hex1, desc_)
6060
if mat != nothing
61-
return RGB{N0f8}(parse(Int, mat.captures[2], 16) / 15,
62-
parse(Int, mat.captures[3], 16) / 15,
63-
parse(Int, mat.captures[4], 16) / 15)
61+
return RGB{N0f8}(parse(Int, mat.captures[2], base=16) / 15,
62+
parse(Int, mat.captures[3], base=16) / 15,
63+
parse(Int, mat.captures[4], base=16) / 15)
6464
end
6565

6666
mat = match(col_pat_rgb, desc_)

src/utilities.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ hex(c::Colorant) = hex(convert(ARGB, c))
3535
"""
3636
weighted_color_mean(w1, c1, c2)
3737
38-
Returns the color `w1*c1 + (1-w1)*c2` that is the weighted mean of `c1` and
38+
Returns the color `w1*c1 + (1-w1)*c2` that is the weighted mean of `c1` and
3939
`c2`, where `c1` has a weight 0 ≤ `w1` ≤ 1.
4040
"""
4141
function weighted_color_mean(w1::Real, c1::Colorant, c2::Colorant)
@@ -49,15 +49,18 @@ function weighted_color_mean(w1::Real, c1::Gray{Bool}, c2::Gray{Bool})
4949
end
5050

5151
"""
52-
linspace(c1::Color, c2::Color, n=100)
52+
range(start::Color; stop::Color, length=100)
5353
54-
Generates `n`>2 colors in a linearly interpolated ramp from `c1` to`c2`,
54+
Generates `n`>2 colors in a linearly interpolated ramp from `start` to`stop`,
5555
inclusive, returning an `Array` of colors.
5656
"""
57-
function linspace(c1::T, c2::T, n::Integer=100) where T<:Colorant
58-
return T[weighted_color_mean(w1, c1, c2) for w1 in linspace(1.0,0.0,n)]
57+
function range(start::T; stop::T, length::Integer=100) where T<:Colorant
58+
return T[weighted_color_mean(w1, start, stop) for w1 in range(1.0,stop=0.0,length=length)]
5959
end
6060

61+
import Base: linspace
62+
Base.@deprecate linspace(start::Colorant, stop::Colorant, n::Integer=100) range(start, stop=stop, length=n)
63+
6164
#Double quadratic Bezier curve
6265
function Bezier(t::T, p0::T, p2::T, q0::T, q1::T, q2::T) where T<:Real
6366
B(t,a,b,c)=a*(1.0-t)^2.0+2.0b*(1.0-t)*t+c*t^2.0

test/algorithms.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using Base.Test, Colors
1+
using Test, Colors
22

3-
@test isconcrete(eltype(colormap("Grays")))
3+
@test isconcretetype(eltype(colormap("Grays")))
44

55
@test_throws ArgumentError colormap("Grays", N=10)
66

77
col = distinguishable_colors(10)
8-
@test isconcrete(eltype(col))
8+
@test isconcretetype(eltype(col))
99
mindiff = Inf
1010
for i = 1:10
1111
for j = i+1:10
12-
mindiff = min(mindiff, colordiff(col[i], col[j]))
12+
global mindiff = min(mindiff, colordiff(col[i], col[j]))
1313
end
1414
end
1515
@test mindiff > 8

0 commit comments

Comments
 (0)