@@ -7,7 +7,7 @@ import StatsBase: histrange
77
88import Base: == , + , - , * , / , ^ , < , ~
99import Base: abs, abs2, clamp, convert, copy, div, eps, isfinite, isinf,
10- isnan, isless, length, mapreduce, norm, one , promote_array_type,
10+ isnan, isless, length, mapreduce, norm, oneunit , promote_array_type,
1111 promote_op, promote_rule, zero, trunc, floor, round, ceil, bswap,
1212 mod, rem, atan2, hypot, max, min, varm, real, typemin, typemax
1313
@@ -82,7 +82,7 @@ dotc(x::Real, y::Real) = dotc(promote(x, y)...)
8282# Return types for arithmetic operations
8383multype {A,B} (:: Type{A} , :: Type{B} ) = coltype (typeof (zero (A)* zero (B)))
8484sumtype {A,B} (:: Type{A} , :: Type{B} ) = coltype (typeof (zero (A)+ zero (B)))
85- divtype {A,B} (:: Type{A} , :: Type{B} ) = coltype (typeof (zero (A)/ one (B)))
85+ divtype {A,B} (:: Type{A} , :: Type{B} ) = coltype (typeof (zero (A)/ oneunit (B)))
8686powtype {A,B} (:: Type{A} , :: Type{B} ) = coltype (typeof (zero (A)^ zero (B)))
8787multype (a:: Colorant , b:: Colorant ) = multype (eltype (a),eltype (b))
8888sumtype (a:: Colorant , b:: Colorant ) = sumtype (eltype (a),eltype (b))
@@ -120,19 +120,19 @@ copy(c::AbstractRGB) = c
120120(* )(f:: Real , c:: AbstractRGB ) = base_colorant_type (c){multype (typeof (f),eltype (c))}(f* red (c), f* green (c), f* blue (c))
121121(* )(f:: Real , c:: TransparentRGB ) = base_colorant_type (c){multype (typeof (f),eltype (c))}(f* red (c), f* green (c), f* blue (c), f* alpha (c))
122122function (* ){T<: Normed }(f:: Real , c:: AbstractRGB{T} )
123- fs = f* (1 / reinterpret (one (T)))
123+ fs = f* (1 / reinterpret (oneunit (T)))
124124 base_colorant_type (c){multype (typeof (f),T)}(fs* reinterpret (red (c)), fs* reinterpret (green (c)), fs* reinterpret (blue (c)))
125125end
126126function (* ){T<: Normed }(f:: Normed , c:: AbstractRGB{T} )
127- fs = reinterpret (f)* (1 / widen (reinterpret (one (T)))^ 2 )
127+ fs = reinterpret (f)* (1 / widen (reinterpret (oneunit (T)))^ 2 )
128128 base_colorant_type (c){multype (typeof (f),T)}(fs* reinterpret (red (c)), fs* reinterpret (green (c)), fs* reinterpret (blue (c)))
129129end
130130function (/ ){T<: Normed }(c:: AbstractRGB{T} , f:: Real )
131- fs = (one (f)/ reinterpret (one (T)))/ f
131+ fs = (one (f)/ reinterpret (oneunit (T)))/ f
132132 base_colorant_type (c){divtype (typeof (f),T)}(fs* reinterpret (red (c)), fs* reinterpret (green (c)), fs* reinterpret (blue (c)))
133133end
134134function (/ ){T<: Normed }(c:: AbstractRGB{T} , f:: Integer )
135- fs = (1 / reinterpret (one (T)))/ f
135+ fs = (1 / reinterpret (oneunit (T)))/ f
136136 base_colorant_type (c){divtype (typeof (f),T)}(fs* reinterpret (red (c)), fs* reinterpret (green (c)), fs* reinterpret (blue (c)))
137137end
138138(+ ){S,T}(a:: AbstractRGB{S} , b:: AbstractRGB{T} ) = color_rettype (a, b){sumtype (S,T)}(red (a)+ red (b), green (a)+ green (b), blue (a)+ blue (b))
@@ -164,13 +164,15 @@ abs2(c::TransparentRGB) = (ret = abs2(color(c)); ret + convert(typeof(ret), alph
164164norm (c:: AbstractRGB ) = sqrt (abs2 (c))
165165norm (c:: TransparentRGB ) = sqrt (abs2 (c))
166166
167- one {C<:AbstractRGB} (:: Type{C} ) = C (1 ,1 ,1 )
168- one {C<:TransparentRGB} (:: Type{C} ) = C (1 ,1 ,1 ,1 )
167+ oneunit {C<:AbstractRGB} (:: Type{C} ) = C (1 ,1 ,1 )
168+ oneunit {C<:TransparentRGB} (:: Type{C} ) = C (1 ,1 ,1 ,1 )
169+
169170zero {C<:AbstractRGB} (:: Type{C} ) = C (0 ,0 ,0 )
170171zero {C<:TransparentRGB} (:: Type{C} ) = C (0 ,0 ,0 ,0 )
171172zero {C<:YCbCr} (:: Type{C} ) = C (0 ,0 ,0 )
172173zero {C<:HSV} (:: Type{C} ) = C (0 ,0 ,0 )
173- one (p:: Colorant ) = one (typeof (p))
174+ oneunit (p:: Colorant ) = oneunit (typeof (p))
175+ Base. one (c:: Colorant ) = Base. one (typeof (c))
174176zero (p:: Colorant ) = zero (typeof (p))
175177
176178# These constants come from squaring the conversion to grayscale
@@ -272,7 +274,7 @@ function Base.isapprox{Cx<:MathTypes,Cy<:MathTypes}(x::AbstractArray{Cx},
272274end
273275
274276zero {C<:TransparentGray} (:: Type{C} ) = C (0 ,0 )
275- one {C<:TransparentGray} (:: Type{C} ) = C (1 ,1 )
277+ oneunit {C<:TransparentGray} (:: Type{C} ) = C (1 ,1 )
276278
277279dotc {T<:AbstractGray} (x:: T , y:: T ) = acc (gray (x))* acc (gray (y))
278280dotc (x:: AbstractGray , y:: AbstractGray ) = dotc (promote (x, y)... )
@@ -285,14 +287,6 @@ float{T<:Gray}(::Type{T}) = typeof(float(zero(T)))
285287
286288Compat. @dep_vectorize_2arg Gray max
287289Compat. @dep_vectorize_2arg Gray min
288- for f in (:min , :max )
289- @eval begin
290- @deprecate ($ f {T<:Gray} (x:: Number , y:: AbstractArray{T} ),
291- @compat $ f .(x, y))
292- @deprecate ($ f {T<:Gray} (x:: AbstractArray{T} , y:: Number ),
293- @compat $ f .(x, y))
294- end
295- end
296290
297291# Arrays
298292+ {C<: MathTypes }(A:: AbstractArray{C} ) = A
@@ -343,4 +337,18 @@ typemax{T<:ColorTypes.AbstractGray}(::Type{T}) = T(typemax(eltype(T)))
343337typemin {T<:ColorTypes.AbstractGray} (:: T ) = T (typemin (eltype (T)))
344338typemax {T<:ColorTypes.AbstractGray} (:: T ) = T (typemax (eltype (T)))
345339
340+ # deprecations
341+ function Base. one (:: Type{C} ) where {C<: Union{TransparentGray,AbstractRGB,TransparentRGB} }
342+ Base. depwarn (" one($C ) will soon switch to returning 1; you might need to switch to `oneunit`" , :one )
343+ C (_onetuple (C)... )
344+ end
345+ _onetuple (:: Type{C} ) where {C<: Colorant{T,N} } where {T,N} = ntuple (d-> 1 , Val (N))
346+
347+ for f in (:min , :max )
348+ @eval begin
349+ @deprecate ($ f {T<:Gray} (x:: Number , y:: AbstractArray{T} ), $ f .(x, y))
350+ @deprecate ($ f {T<:Gray} (x:: AbstractArray{T} , y:: Number ), $ f .(x, y))
351+ end
352+ end
353+
346354end
0 commit comments