Repository: JuliaPlots/Makie.jl (julia)

Issue:
broken edge case: plotting an empty list of polygons
When trying to develop a  Makie plot recipe I found that currently (Makie v0.15.3) `poly!(ax, Vector{Point2f}[])` throws `ERROR: MethodError: no method matching to_vertices(::Vector{Any})`.

Pull request description:

Patch:
diff --git a/src/basic_recipes/poly.jl b/src/basic_recipes/poly.jl
index d8c76a2460d..69981d813c9 100644
--- a/src/basic_recipes/poly.jl
+++ b/src/basic_recipes/poly.jl
@@ -63,7 +63,10 @@ function plot!(plot::Poly{<: Tuple{Union{GeometryBasics.Mesh, GeometryPrimitive}
 end
 
 # Poly conversion
-poly_convert(geometries) = triangle_mesh.(geometries)
+function poly_convert(geometries)
+    isempty(geometries) && return typeof(GeometryBasics.Mesh(Point2f[], GLTriangleFace[]))[]
+    return triangle_mesh.(geometries)
+end
 poly_convert(meshes::AbstractVector{<:AbstractMesh}) = meshes
 poly_convert(polys::AbstractVector{<:Polygon}) = triangle_mesh.(polys)
 function poly_convert(multipolygons::AbstractVector{<:MultiPolygon})
@@ -184,7 +187,11 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{Abst
     else
         attributes[:color] = color_node
         lift(meshes) do meshes
-            return merge(GeometryBasics.mesh.(meshes))
+            if isempty(meshes)
+                return GeometryBasics.Mesh(Point2f[], GLTriangleFace[])
+            else
+                return merge(GeometryBasics.mesh.(meshes))
+            end
         end
     end
     mesh!(plot, attributes, bigmesh)


Test patch:
diff --git a/test/conversions.jl b/test/conversions.jl
index c6081821fa3..9c2fe868028 100644
--- a/test/conversions.jl
+++ b/test/conversions.jl
@@ -248,3 +248,15 @@ end
     @inferred to_colormap(cgrad(:cividis, 8; alpha=0.5))
     @inferred to_colormap(cgrad(:cividis, 8; alpha=0.5, categorical=true))
 end
+
+
+@testset "empty poly" begin
+    f, ax, pl = poly(Rect2f[]);
+    pl[1] = [Rect2f(0, 0, 1, 1)];
+    @test pl.plots[1][1][] == [GeometryBasics.triangle_mesh(Rect2f(0, 0, 1, 1))]
+
+    f, ax, pl = poly(Vector{Point2f}[])
+    points = decompose(Point2f, Circle(Point2f(0),1))
+    pl[1] = [points]
+    @test pl.plots[1][1][] == Makie.poly_convert(points)
+end