Skip to content

Commit

Permalink
Deprecate using AbstractVector as side of ImageLike (#3395)
Browse files Browse the repository at this point in the history
Now that we've clearly separated these concepts for 0.20, I think it
doesn't make sense anymore to just accept whatever AbstractVector as the
side of an ImageLike. Note that `1 .. 10` works and so does `1:10`,
which might feel correct, but this doesn't have to match the pixel count
so it's a source of bugs. And `[10, 1]` works as wells as `[10, 3, 5, 1,
1, 3, 1]` which is just really strange.
  • Loading branch information
SimonDanisch committed Nov 21, 2023
2 parents 7e72ed9 + 8c5bd7b commit 7c40a61
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/conversions.jl
@@ -1,7 +1,7 @@
################################################################################
# Type Conversions #
################################################################################
const RangeLike = Union{AbstractRange, AbstractVector, ClosedInterval}
const RangeLike = Union{AbstractVector, ClosedInterval, Tuple{Any,Any}}

# if no plot type based conversion is defined, we try using a trait
function convert_arguments(T::PlotFunc, args...; kw...)
Expand Down Expand Up @@ -373,9 +373,22 @@ function convert_arguments(::ImageLike, data::AbstractMatrix)
n, m = Float32.(size(data))
return (0f0 .. n, 0f0 .. m, el32convert(data))
end

function print_range_warning(side::String, value)
@warn "Encountered an `AbstractVector` with value $value on side $side in `convert_arguments` for the `ImageLike` trait. Using an `AbstractVector` to specify one dimension of an `ImageLike` is deprecated because `ImageLike` sides always need exactly two values, start and stop. Use interval notation `start .. stop` or a two-element tuple `(start, stop)` instead."
end

function convert_arguments(::ImageLike, xs::RangeLike, ys::RangeLike, data::AbstractMatrix)
x = Float32(minimum(xs)) .. Float32(maximum(xs))
y = Float32(minimum(ys)) .. Float32(maximum(ys))
if xs isa AbstractVector
print_range_warning("x", xs)
end
if ys isa AbstractVector
print_range_warning("y", ys)
end
_interval(v::Union{Interval,AbstractVector}) = Float32(minimum(v)) .. Float32(maximum(v)) # having minimum and maximum here actually invites bugs
_interval(t::Tuple{Any, Any}) = Float32(t[1]) .. Float32(t[2])
x = _interval(xs)
y = _interval(ys)
return (x, y, el32convert(data))
end

Expand Down

0 comments on commit 7c40a61

Please sign in to comment.