From e2584b5d4db0c4ea380ed54d0e4954eb4e34e68f Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Sun, 13 Nov 2016 07:29:20 -0500 Subject: [PATCH] added typemin/max for AbstractGray --- src/ColorVectorSpace.jl | 4 +++- test/runtests.jl | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ColorVectorSpace.jl b/src/ColorVectorSpace.jl index 196e5f1..47bc773 100644 --- a/src/ColorVectorSpace.jl +++ b/src/ColorVectorSpace.jl @@ -9,7 +9,7 @@ import Base: ==, +, -, *, /, .+, .-, .*, ./, ^, .^, <, ~ import Base: abs, abs2, clamp, convert, copy, div, eps, isfinite, isinf, isnan, isless, length, mapreduce, norm, one, promote_array_type, promote_op, promote_rule, zero, trunc, floor, round, ceil, bswap, - mod, rem, atan2, hypot, max, min, varm, real + mod, rem, atan2, hypot, max, min, varm, real, typemin, typemax export nan @@ -460,4 +460,6 @@ histrange{T}(v::AbstractArray{Gray{T}}, n::Integer) = histrange(convert(Array{Fl promote_array_type{T<:Real,C<:MathTypes}(F, ::Type{T}, ::Type{C}) = base_colorant_type(C){Base.promote_array_type(F, T, eltype(C))} promote_rule{T<:Real,C<:AbstractGray}(::Type{T}, ::Type{C}) = promote_type(T, eltype(C)) +typemin{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemin(eltype(T))) +typemax{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemax(eltype(T))) end diff --git a/test/runtests.jl b/test/runtests.jl index 4fb91f4..0c74312 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -340,7 +340,18 @@ end @test isapprox(dotc(xc, yc) , dotc(convert(Gray, xc), convert(Gray, yc)), atol=1e-6) @test dotc(RGB(1,0,0), RGB(0,1,1)) == 0 end -end + @testset "typemin/max" begin + for T in (Normed{UInt8,8}, Normed{UInt8,6}, Normed{UInt16,16}, Normed{UInt16,14}, Float32, Float64) + @test typemin(Gray{T}) === Gray{T}(typemin(T)) + @test typemax(Gray{T}) === Gray{T}(typemax(T)) + @test typemin(Gray{T}(0.5)) === Gray{T}(typemin(T)) + @test typemax(Gray{T}(0.5)) === Gray{T}(typemax(T)) + A = maximum(Gray{T}.([1 0 0; 0 1 0]), 1) # see PR#44 discussion + @test isa(A, Matrix{Gray{T}}) + @test size(A) == (1,3) + end + end +end end