-
-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
src/lib/overloads.jl
Outdated
imin = isnothing(left) ? p.left : match_longitude(p, left) | ||
jmax = isnothing(top) ? p.top : match_latitude(p, top) | ||
jmin = isnothing(bottom) ? p.bottom : match_latitude(p, bottom) | ||
function Base.getindex(p::T; left::Union{N,A}=nothing, right::Union{N,A}=nothing, top::Union{N,A}=nothing, bottom::Union{N,A}=nothing) where {T <: SimpleSDMLayer, N <: Nothing, A <: AbstractFloat} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to make the types work? They have to be "independent", so that one can be Nothing
while the others are AbstractFloat
. The previous code only worked if they were all Nothing
or all AbstractFloat
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we can always not be specific about the types here, since there is an isnothing
on one side, and the getindex
measures do not have methods for anything other than a float in this case... would it fix the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it already works like this. I was just wondering if there was a cleaner way to call the types.
It works the same if we're not specific about them, as match_longitude
is specific for floats.
I think this should simplify the declaration substantially |
Yes, that's great! |
Cropping a layer while omitting to specify one of the limits did not work properly. For example:
I fixed it with two tweaks to the
getindex
overload (thematch_longitude
calls and the types).While at it, I also added an overload to crop based on a
NamedTuple
. I think it's useful as it allows to crop with a variable, which can be reused easily.I've added tests for both of these.