Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 07137d0

Browse files
authored
fix color resampling (#343)
1 parent dcd1513 commit 07137d0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utilities/utilities.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ You can use `norm`, to change the range of 0..1 to whatever you want.
77
"""
88
function interpolated_getindex(cmap::AbstractArray{T}, value::AbstractFloat, norm = (0.0, 1.0)) where T
99
cmin, cmax = norm
10+
if cmin == cmax
11+
return cmap[1]
12+
end
1013
i01 = clamp((value - cmin) / (cmax - cmin), 0.0, 1.0)
1114
i1len = (i01 * (length(cmap) - 1)) + 1
1215
down = floor(Int, i1len)
1316
up = ceil(Int, i1len)
1417
down == up && return cmap[down]
1518
interp_val = i1len - down
1619
downc, upc = cmap[down], cmap[up]
17-
convert(T, (downc * (1.0 - interp_val)) + (upc * interp_val))
20+
return convert(T, (downc * (1.0 - interp_val)) + (upc * interp_val))
1821
end
1922

2023
function to_image(image::AbstractMatrix{<: AbstractFloat}, colormap::AbstractVector{<: Colorant}, colorrange)
21-
interpolated_getindex.((to_value(colormap),), image, (to_value(colorrange),))
24+
return interpolated_getindex.((to_value(colormap),), image, (to_value(colorrange),))
2225
end
2326

2427
"""
@@ -27,7 +30,7 @@ Resample a vector with linear interpolation to have length `len`
2730
"""
2831
function resample(A::AbstractVector, len::Integer)
2932
length(A) == len && return A
30-
interpolated_getindex.((A,), range(0.0, stop=1.0, length=len))
33+
return interpolated_getindex.((A,), range(0.0, stop=1.0, length=len))
3134
end
3235

3336
"""

0 commit comments

Comments
 (0)