Merge pull request #3998 from yha/yha/Unzip2

Use Unzip.unzip
This commit is contained in:
Yuval 2021-12-16 17:13:21 +02:00 committed by GitHub
commit d618f2e2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 26 deletions

View File

@ -31,8 +31,9 @@ Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
Unzip = "41fe7b60-77ed-43a1-b4f0-825fd5a5650d"
[compat] [compat]
Contour = "0.5" Contour = "0.5"
@ -55,6 +56,7 @@ Showoff = "0.3.1, 1.0"
StatsBase = "0.32 - 0.33" StatsBase = "0.32 - 0.33"
UnicodeFun = "0.4" UnicodeFun = "0.4"
UnicodePlots = "2.4" UnicodePlots = "2.4"
Unzip = "0.1"
julia = "1.6" julia = "1.6"
[extras] [extras]

View File

@ -19,7 +19,7 @@ const _current_plots_version = VersionNumber(
using Reexport using Reexport
import GeometryBasics import GeometryBasics
using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using Dates, Printf, Statistics, Base64, LinearAlgebra, Random, Unzip
using SparseArrays using SparseArrays
using FFMPEG using FFMPEG
@ -196,7 +196,6 @@ import RecipesPipeline:
pop_kw!, pop_kw!,
scale_func, scale_func,
inverse_scale_func, inverse_scale_func,
unzip,
dateformatter, dateformatter,
datetimeformatter, datetimeformatter,
timeformatter timeformatter

View File

@ -43,13 +43,7 @@ vertices(shape::Shape) = collect(zip(shape.x, shape.y))
"return the vertex points from a Shape or Segments object" "return the vertex points from a Shape or Segments object"
coords(shape::Shape) = shape.x, shape.y coords(shape::Shape) = shape.x, shape.y
#coords(shapes::AVec{Shape}) = unzip(map(coords, shapes)) coords(shapes::AVec{<:Shape}) = unzip(map(coords, shapes))
function coords(shapes::AVec{<:Shape})
c = map(coords, shapes)
x = [q[1] for q in c]
y = [q[2] for q in c]
x, y
end
"get an array of tuples of points on a circle with radius `r`" "get an array of tuples of points on a circle with radius `r`"
partialcircle(start_θ, end_θ, n = 20, r = 1) = partialcircle(start_θ, end_θ, n = 20, r = 1) =

View File

@ -215,20 +215,10 @@ makevec(v::T) where {T} = T[v]
maketuple(x::Real) = (x, x) maketuple(x::Real) = (x, x)
maketuple(x::Tuple{T,S}) where {T,S} = x maketuple(x::Tuple{T,S}) where {T,S} = x
for i in 2:4 RecipesPipeline.unzip(v) = unzip(v)
@eval begin RecipesPipeline.unzip(points::AbstractVector{<:GeometryBasics.Point}) = unzip(Tuple.(points))
RecipesPipeline.unzip( RecipesPipeline.unzip(points::AbstractVector{GeometryBasics.Point{N,T}}) where {N,T} =
v::Union{AVec{<:NTuple{$i,T} where {T}},AVec{<:GeometryBasics.Point{$i}}}, isbitstype(T) && sizeof(T) > 0 ? unzip(reinterpret(NTuple{N,T}, points)) : unzip(Tuple.(points))
) = $(Expr(:tuple, (:([t[$j] for t in v]) for j in 1:i)...))
end
end
RecipesPipeline.unzip(
::Union{AVec{<:GeometryBasics.Point{N}},AVec{<:NTuple{N,T} where {T}}},
) where {N} = error("$N-dimensional unzip not implemented.")
RecipesPipeline.unzip(::Union{AVec{<:GeometryBasics.Point},AVec{<:Tuple}}) =
error("Can't unzip points of different dimensions.")
# given 2-element lims and a vector of data x, widen lims to account for the extrema of x # given 2-element lims and a vector of data x, widen lims to account for the extrema of x
function _expand_limits(lims, x) function _expand_limits(lims, x)

View File

@ -190,8 +190,8 @@ end
[(missing, missing, missing), ("a", "b", "c")], [(missing, missing, missing), ("a", "b", "c")],
) )
for z in zipped for z in zipped
@test isequal(collect(zip(Plots.unzip(z)...)), z) @test isequal(collect(zip(Plots.RecipesPipeline.unzip(z)...)), z)
@test isequal(collect(zip(Plots.unzip(GeometryBasics.Point.(z))...)), z) @test isequal(collect(zip(Plots.RecipesPipeline.unzip(GeometryBasics.Point.(z))...)), z)
end end
op1 = Plots.process_clims((1.0, 2.0)) op1 = Plots.process_clims((1.0, 2.0))
op2 = Plots.process_clims((1, 2.0)) op2 = Plots.process_clims((1, 2.0))