Skip to content

Commit

Permalink
Version 0.9.4 (#163)
Browse files Browse the repository at this point in the history
This adds the support for ColorTypes v0.11.
  • Loading branch information
kimikage authored Apr 27, 2021
1 parent 4b69dc1 commit bf6a78a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TensorCore = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50"

[compat]
ColorTypes = "0.10"
ColorTypes = "0.10, 0.11"
FixedPointNumbers = "0.8.2"
SpecialFunctions = "0.8, 0.9, 0.10, 1"
TensorCore = "0.1"
Expand Down
23 changes: 12 additions & 11 deletions src/ColorVectorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export RGBRGB, complement, nan, dotc, dot, ⋅, hadamard, ⊙, tensor, ⊗, norm
MathTypes{T,C} = Union{AbstractRGB{T},TransparentRGB{C,T},AbstractGray{T},TransparentGray{C,T}}

## Version compatibility with ColorTypes
### TODO: Remove the definitons other than `one` when dropping ColorTypes v0.10 support

if !hasmethod(zero, (Type{TransparentGray},))
zero(::Type{C}) where {C<:TransparentGray} = C(0,0)
Expand All @@ -40,7 +41,7 @@ if !hasmethod(zero, (Type{TransparentGray},))
zero(p::Colorant) = zero(typeof(p))
end

if !hasmethod(one, (Type{TransparentGray},))
if !hasmethod(one, (Type{TransparentGray},)) # specification change is planned for ColorTypes v0.12
Base.one(::Type{C}) where {C<:TransparentGray} = C(1,1)
Base.one(::Type{C}) where {C<:AbstractRGB} = C(1,1,1)
Base.one(::Type{C}) where {C<:TransparentRGB} = C(1,1,1,1)
Expand All @@ -53,6 +54,16 @@ if !hasmethod(isfinite, (Colorant,))
isnan(c::Colorant) = mapreducec(isnan, |, false, c)
end

if which(<, Tuple{AbstractGray,AbstractGray}).module === Base
(<)(g1::AbstractGray, g2::AbstractGray) = gray(g1) < gray(g2)
(<)(c::AbstractGray, r::Real) = gray(c) < r
(<)(r::Real, c::AbstractGray) = r < gray(c)
end
if !hasmethod(isless, Tuple{AbstractGray,Real})
isless(c::AbstractGray, r::Real) = isless(gray(c), r)
isless(r::Real, c::AbstractGray) = isless(r, gray(c))
end

if isdefined(ColorTypes, :nan)
using ColorTypes: nan
else
Expand Down Expand Up @@ -291,16 +302,6 @@ min(a::AbstractGray, b::Number) = min(promote(a,b)...)
atan(x::AbstractGray, y::AbstractGray) = atan(gray(x), gray(y))
hypot(x::AbstractGray, y::AbstractGray) = hypot(gray(x), gray(y))

if which(<, Tuple{AbstractGray,AbstractGray}).module === Base # planned for ColorTypes 0.11
(<)(g1::AbstractGray, g2::AbstractGray) = gray(g1) < gray(g2)
(<)(c::AbstractGray, r::Real) = gray(c) < r
(<)(r::Real, c::AbstractGray) = r < gray(c)
end
if !hasmethod(isless, Tuple{AbstractGray,Real}) # planned for ColorTypes 0.11
isless(c::AbstractGray, r::Real) = isless(gray(c), r)
isless(r::Real, c::AbstractGray) = isless(r, gray(c))
end

dotc(x::C, y::C) where {C<:AbstractGray} = acc(gray(x))*acc(gray(y))
dotc(x::AbstractGray, y::AbstractGray) = dotc(promote(x, y)...)

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
@test complement(Gray(0.2)) === Gray(0.8)
@test complement(AGray(0.2f0, 0.7f0)) === AGray(0.8f0, 0.7f0)
@test complement(GrayA{N0f8}(0.2, 0.7)) === GrayA{N0f8}(0.8, 0.7)
@test_broken complement(Gray24(0.2)) === Gray24(0.8)
@test_broken complement(AGray32(0.2, 0.7)) === AGray32(0.8, 0.7)
@test complement(Gray24(0.2)) === Gray24(0.8)
@test complement(AGray32(0.2, 0.7)) === AGray32(0.8, 0.7)

@test complement(RGB(0, 0.3, 1)) === RGB(1, 0.7, 0)
@test complement(ARGB(0, 0.3f0, 1, 0.7f0)) === ARGB(1, 0.7f0, 0, 0.7f0)
Expand Down

0 comments on commit bf6a78a

Please sign in to comment.