Skip to content

Commit

Permalink
fix vector of shapes (#3517)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastyBlacksmith authored May 20, 2021
1 parent 827462d commit ce530ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function coords(shape::Shape)
end

#coords(shapes::AVec{Shape}) = unzip(map(coords, shapes))
function coords(shapes::AVec{Shape})
function coords(shapes::AVec{<:Shape})
c = map(coords, shapes)
x = [q[1] for q in c]
y = [q[2] for q in c]
Expand Down
6 changes: 3 additions & 3 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,9 @@ end
coords(shape)
end

@recipe function f(shapes::AVec{Shape})
@recipe function f(shapes::AVec{<:Shape})
seriestype --> :shape
# For backwards compatibility, column vectors of segmenting attributes are
# For backwards compatibility, column vectors of segmenting attributes are
# interpreted as having one element per shape
for attr in union(_segmenting_array_attributes, _segmenting_vector_attributes)
v = get(plotattributes, attr, nothing)
Expand All @@ -1443,7 +1443,7 @@ end
coords(shapes)
end

@recipe function f(shapes::AMat{Shape})
@recipe function f(shapes::AMat{<:Shape})
seriestype --> :shape
for j in axes(shapes, 2)
@series coords(vec(shapes[:, j]))
Expand Down
11 changes: 11 additions & 0 deletions test/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Plots, Test
@testset "Type" begin
square = Shape([(0,0.0),(1,0.0),(1,1.0),(0,1.0)])
@test isa(square, Shape{Int64, Float64})
@test coords(square) isa Tuple{Vector{S}, Vector{T}} where {T,S}
end

@testset "Copy" begin
Expand Down Expand Up @@ -47,6 +48,16 @@ using Plots, Test
@test square2.x coords[1,:]
@test square2.y coords[2,:]
end

@testset "Plot" begin
ang = range(0, 2π, length = 60)
ellipse(x, y, w, h) = Shape(w*sin.(ang).+x, h*cos.(ang).+y)
myshapes = [ellipse(x,rand(),rand(),rand()) for x = 1:4]
@test coords(myshapes) isa Tuple{Vector{Vector{S}}, Vector{Vector{T}}} where {T,S}
local p
@test_nowarn p = plot(myshapes)
@test p[1][1][:seriestype] == :shape
end
end

@testset "Brush" begin
Expand Down

0 comments on commit ce530ef

Please sign in to comment.