Skip to content

Commit

Permalink
Merge pull request #47 from mronian/approxARGB
Browse files Browse the repository at this point in the history
Adds isapprox for TransparentColor, Tests for isapprox
  • Loading branch information
timholy authored Jul 20, 2016
2 parents 210fe8f + d28b99a commit 550b26e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ColorVectorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ isless(g1::AbstractGray, g2::AbstractGray) = isless(gray(g1), gray(g2))
isless(c::AbstractGray, r::Real) = isless(gray(c), r)
isless(r::Real, c::AbstractGray) = isless(r, gray(c))
Base.isapprox(x::AbstractGray, y::AbstractGray; kwargs...) = isapprox(gray(x), gray(y); kwargs...)
Base.isapprox(x::TransparentGray, y::TransparentGray; kwargs...) = isapprox(gray(x), gray(y); kwargs...) && isapprox(alpha(x), alpha(y); kwargs...)
Base.isapprox(x::AbstractRGB, y::AbstractRGB; kwargs...) = isapprox(red(x), red(y); kwargs...) && isapprox(green(x), green(y); kwargs...) && isapprox(blue(x), blue(y); kwargs...)
Base.isapprox(x::TransparentRGB, y::TransparentRGB; kwargs...) = isapprox(alpha(x), alpha(y); kwargs...) && isapprox(red(x), red(y); kwargs...) && isapprox(green(x), green(y); kwargs...) && isapprox(blue(x), blue(y); kwargs...)

zero{C<:TransparentGray}(::Type{C}) = C(0,0)
zero{C<:Gray}(::Type{C}) = C(0)
Expand Down
23 changes: 22 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ facts("Colortypes") do
@fact @inferred(max(g1, 0.1)) --> 0.2
@fact @inferred(min(g1, g2)) --> g1
@fact @inferred(min(g1, 0.1)) --> 0.1
a = Gray{Float64}(0.9999999999999999)
b = Gray{Float64}(1.0)

@fact isapprox(a, b) --> true
a = Gray{Float64}(0.99)
@fact isapprox(a, b, rtol = 0.01) --> false
@fact isapprox(a, b, rtol = 0.1) --> true
end

context("Unary operations with Gray") do
Expand Down Expand Up @@ -144,6 +151,14 @@ facts("Colortypes") do

a = GrayA{U8}[GrayA(0.8,0.7), GrayA(0.5,0.2)]
@fact sum(a) --> GrayA(u8sum(0.8,0.5), u8sum(0.7,0.2))
a = AGray{Float64}(1.0, 0.9999999999999999)
b = AGray{Float64}(1.0, 1.0)

@fact isapprox(a, b) --> true
a = AGray{Float64}(1.0, 0.99)
@fact isapprox(a, b, rtol = 0.01) --> false
@fact isapprox(a, b, rtol = 0.1) --> true

end

context("Arithemtic with RGB") do
Expand Down Expand Up @@ -204,7 +219,6 @@ facts("Colortypes") do
a = RGB{Float64}(1.0, 1.0, 0.99)
@fact isapprox(a, b, rtol = 0.01) --> false
@fact isapprox(a, b, rtol = 0.1) --> true

end

context("Arithemtic with RGBA") do
Expand Down Expand Up @@ -263,6 +277,13 @@ facts("Colortypes") do

a = RGBA{U8}[RGBA(1,0,0,0.8), RGBA(0.7,0.8,0,0.9)]
@fact sum(a) --> RGBA(u8sum(1,0.7),0.8,0,u8sum(0.8,0.9))
a = ARGB{Float64}(1.0, 1.0, 1.0, 0.9999999999999999)
b = ARGB{Float64}(1.0, 1.0, 1.0, 1.0)

@fact isapprox(a, b) --> true
a = ARGB{Float64}(1.0, 1.0, 1.0, 0.99)
@fact isapprox(a, b, rtol = 0.01) --> false
@fact isapprox(a, b, rtol = 0.1) --> true
end
end

Expand Down

0 comments on commit 550b26e

Please sign in to comment.