Skip to content

Commit

Permalink
Restrict clamp01 to gray & RGB (#181)
Browse files Browse the repository at this point in the history
The 0-to-1 colorscale does not have meaning for colors like HSV,
so supporting arbitrary colorants seems wrong.
  • Loading branch information
timholy authored Jul 20, 2023
1 parent eadeca1 commit 0046ec7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ channel separately.
See also: [`clamp01!`](@ref), [`clamp01nan`](@ref).
"""
clamp01(x::Union{N0f8,N0f16}) = x
clamp01(x::Number) = clamp(x, zero(x), oneunit(x))
clamp01(c::Colorant) = mapc(clamp01, c)
clamp01(x::NumberLike) = clamp(x, zero(x), oneunit(x))
clamp01(c::Union{TransparentGray,AbstractRGB,TransparentRGB}) = mapc(clamp01, c)

"""
clamp01!(array::AbstractArray)
Expand All @@ -35,8 +35,8 @@ Similar to `clamp01`, except that any `NaN` values are changed to 0.
See also: [`clamp01nan!`](@ref), [`clamp01`](@ref).
"""
clamp01nan(x) = clamp01(x)
clamp01nan(x::AbstractFloat) = ifelse(isnan(x), zero(x), clamp01(x))
clamp01nan(c::Colorant) = mapc(clamp01nan, c)
clamp01nan(x::Union{AbstractFloat,AbstractGray{<:AbstractFloat}}) = ifelse(isnan(x), zero(x), clamp01(x))
clamp01nan(c::Union{TransparentGray,AbstractRGB,TransparentRGB}) = mapc(clamp01nan, c)

"""
clamp01nan!(array::AbstractArray)
Expand Down

0 comments on commit 0046ec7

Please sign in to comment.