@@ -249,33 +249,17 @@ function sortcolorscheme(colorscheme::Vector{C}, field = :l; kwargs...) where {C
249
249
end
250
250
251
251
"""
252
- get(cscheme, x)
253
252
254
- Find the nearest color in a colorscheme ` cscheme` corresponding to a point `x` between 0 and 1.
253
+ get( cscheme, inData, rangescale)
255
254
256
- Returns a single color.
257
- """
258
- function get (cscheme:: Vector{C} , x, rangescale) where {C<: Colorant }
259
- if rangescale== :clamp
260
- get (cscheme, x, (0.0 , 1.0 ))
261
- elseif (rangescale== :extrema )
262
- get (cscheme, x, extrema (x))
263
- else
264
- error (" rangescale ($rangescale ) not supported, should be :clamp, :extrema or tuple (minVal, maxVal)" )
265
- end
266
- end
267
-
268
- """
269
-
270
- get(cscheme, inData :: Array{Number, 2}, rangescale=:clamp)
271
- get(cscheme, inData :: Array{Number, 2}, rangescale=(minVal, maxVal))
272
-
273
- Return an RGB image generated by applying the colorscheme to the 2D input data.
255
+ Return an RGB image generated by applying the colorscheme to the `inData`.
274
256
275
- If `rangescale` is `:clamp` the colorscheme is applied to values between 0.0-1.0, and values
276
- outside this range get clamped to the ends of the colorscheme.
257
+ If `rangescale` is `:clamp` the colorscheme is applied to values between
258
+ 0.0-1.0, and values outside this range get clamped to the ends of the
259
+ colorscheme.
277
260
278
- Else, if `rangescale` is `:extrema`, the colorscheme is applied to the range `minimum(indata)..maximum(indata)`.
261
+ Else, if `rangescale` is `:extrema`, the colorscheme is applied to the range
262
+ `minimum(indata)..maximum(indata)`.
279
263
280
264
# Examples
281
265
@@ -291,7 +275,17 @@ using PerceptualColourMaps
291
275
img4 = get(PerceptualColourMaps.cmap("R1"), rand(10,10))
292
276
```
293
277
"""
294
- function get (cscheme:: Vector{C} , x, rangescale :: Tuple{Number, Number} = (0.0 , 1.0 )) where {C<: Colorant }
278
+ function get (cscheme:: Vector{<:Colorant} ,
279
+ x:: Union{<:Real, Array{<:Real}, AbstractRange{<:Real}} ,
280
+ rangescale:: Union{Symbol, NTuple{2, <:Real}} = (0.0 , 1.0 ))
281
+
282
+ # NOTE: the Union type for `x` is needed to avoid ambiguity with Base.get
283
+ # when using ranges
284
+
285
+ rangescale == :clamp && (rangescale = (0.0 , 1.0 ))
286
+ rangescale == :extrema && (rangescale = extrema (x))
287
+ (rangescale isa NTuple{2 , Number}) || error (" rangescale ($rangescale ) not supported, should be :clamp, :extrema or tuple (minVal, maxVal)" )
288
+ x isa AbstractRange && (x = collect (x))
295
289
x = clamp .(x, rangescale... )
296
290
before_fp = remap (x, rangescale... , 1 , length (cscheme))
297
291
before = round .(Int, before_fp, RoundDown)
0 commit comments