fix vector of shapes (#3517)

This commit is contained in:
Simon Christ 2021-05-20 20:42:31 +02:00 committed by GitHub
parent 827462dc21
commit ce530ef518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -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]

View File

@ -1428,7 +1428,7 @@ 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
# interpreted as having one element per shape
@ -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]))

View File

@ -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
@ -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