Skip to content

Commit

Permalink
fix strong type conversion of markers
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 24, 2023
1 parent a1d85a1 commit c3a01e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GLMakie/src/GLAbstraction/GLUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Needed to match the lazy gl_convert exceptions.
`x`: the variable that gets matched
"""
matches_target(::Type{Target}, x::T) where {Target, T} = applicable(gl_convert, Target, x) || T <: Target # it can be either converted to Target, or it's already the target
matches_target(::Type{Target}, x::Observable{T}) where {Target, T} = applicable(gl_convert, Target, x) || T <: Target
matches_target(::Type{Target}, x::Observable{T}) where {Target, T} = applicable(gl_convert, Target, x) || T <: Target
matches_target(::Function, x) = true
matches_target(::Function, x::Nothing) = false

Expand Down
8 changes: 4 additions & 4 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,10 @@ struct FastPixel end
Vector of anything that is accepted as a single marker will give each point it's own marker.
Note that it needs to be a uniform vector with the same element type!
"""
to_spritemarker(marker::AbstractVector) = map(to_spritemarker, marker)
function to_spritemarker(marker::AbstractVector{T}) where T
spritemarker = map(to_spritemarker, marker)
convert(Vector{Union{T,eltype(spritemarker)}}, spritemarker) # retain original type T
end
to_spritemarker(marker::AbstractVector{Char}) = marker # Don't dispatch to the above!
to_spritemarker(x::FastPixel) = x
to_spritemarker(x::Circle) = x
Expand Down Expand Up @@ -1688,9 +1691,6 @@ function to_spritemarker(marker::Symbol)
end
end




convert_attribute(value, ::key"marker", ::key"scatter") = to_spritemarker(value)
convert_attribute(value, ::key"isovalue", ::key"volume") = Float32(value)
convert_attribute(value, ::key"isorange", ::key"volume") = Float32(value)
Expand Down
9 changes: 9 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,12 @@ end
@test isapprox(Makie.angle2align(pi/4), Vec2f(1, 1), atol = 1e-12)
@test isapprox(Makie.angle2align(5pi/4), Vec2f(0, 0), atol = 1e-12)
end

@testset "markers conversion" begin
T = Union{Char, Symbol}
marker = Observable(T[:cross, :cross])
marker_converted = Observable(convert_attribute(marker[], key"marker"(), key"scatter"()))
@test T <: eltype(marker_converted[])
marker[][1] = 'x'
marker_converted[] = marker[]
end

0 comments on commit c3a01e7

Please sign in to comment.