Skip to content

Commit 2449575

Browse files
authored
Merge pull request #62 from bjarthur/bja/typeminmax
added typemin/max for AbstractGray
2 parents e9b086d + e2584b5 commit 2449575

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ColorVectorSpace.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Base: ==, +, -, *, /, .+, .-, .*, ./, ^, .^, <, ~
99
import Base: abs, abs2, clamp, convert, copy, div, eps, isfinite, isinf,
1010
isnan, isless, length, mapreduce, norm, one, promote_array_type,
1111
promote_op, promote_rule, zero, trunc, floor, round, ceil, bswap,
12-
mod, rem, atan2, hypot, max, min, varm, real
12+
mod, rem, atan2, hypot, max, min, varm, real, typemin, typemax
1313

1414
export nan
1515

@@ -460,4 +460,6 @@ histrange{T}(v::AbstractArray{Gray{T}}, n::Integer) = histrange(convert(Array{Fl
460460
promote_array_type{T<:Real,C<:MathTypes}(F, ::Type{T}, ::Type{C}) = base_colorant_type(C){Base.promote_array_type(F, T, eltype(C))}
461461
promote_rule{T<:Real,C<:AbstractGray}(::Type{T}, ::Type{C}) = promote_type(T, eltype(C))
462462

463+
typemin{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemin(eltype(T)))
464+
typemax{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemax(eltype(T)))
463465
end

test/runtests.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,18 @@ end
340340
@test isapprox(dotc(xc, yc) , dotc(convert(Gray, xc), convert(Gray, yc)), atol=1e-6)
341341
@test dotc(RGB(1,0,0), RGB(0,1,1)) == 0
342342
end
343-
end
344343

344+
@testset "typemin/max" begin
345+
for T in (Normed{UInt8,8}, Normed{UInt8,6}, Normed{UInt16,16}, Normed{UInt16,14}, Float32, Float64)
346+
@test typemin(Gray{T}) === Gray{T}(typemin(T))
347+
@test typemax(Gray{T}) === Gray{T}(typemax(T))
348+
@test typemin(Gray{T}(0.5)) === Gray{T}(typemin(T))
349+
@test typemax(Gray{T}(0.5)) === Gray{T}(typemax(T))
350+
A = maximum(Gray{T}.([1 0 0; 0 1 0]), 1) # see PR#44 discussion
351+
@test isa(A, Matrix{Gray{T}})
352+
@test size(A) == (1,3)
353+
end
354+
end
355+
end
345356

346357
end

0 commit comments

Comments
 (0)