77Plots a polygon based on the arguments given.
88When vertices and indices are given, it functions similarly to `mesh`.
99When points are given, it draws one polygon that connects all the points in order.
10- When a shape is given (essentially anything decomposable by `GeometryTypes `), it will plot `decompose(shape)`.
10+ When a shape is given (essentially anything decomposable by `GeometryBasics `), it will plot `decompose(shape)`.
1111
1212 poly(coordinates, connectivity; kwargs...)
1313
4040convert_arguments (:: Type{<: Poly} , v:: AbstractVector{<: AbstractMesh} ) = (v,)
4141convert_arguments (:: Type{<: Poly} , v:: AbstractVector{<: VecTypes} ) = (v,)
4242convert_arguments (:: Type{<: Poly} , v:: AbstractVector{<: AbstractVector{<: VecTypes}} ) = (v,)
43- convert_arguments (:: Type{<: Poly} , v:: AbstractVector{<: Union{Circle, Rectangle, HyperRectangle }} ) = (v,)
43+ convert_arguments (:: Type{<: Poly} , v:: AbstractVector{<: Union{Circle, Rect }} ) = (v,)
4444convert_arguments (:: Type{<: Poly} , args... ) = ([convert_arguments (Scatter, args... )[1 ]],)
4545convert_arguments (:: Type{<: Poly} , vertices:: AbstractArray , indices:: AbstractArray ) = convert_arguments (Mesh, vertices, indices)
4646
47-
4847function plot! (plot:: Poly{<: Tuple{Union{AbstractMesh, GeometryPrimitive}}} )
4948 mesh! (
5049 plot, plot[1 ],
@@ -57,8 +56,9 @@ function plot!(plot::Poly{<: Tuple{Union{AbstractMesh, GeometryPrimitive}}})
5756 linewidth = plot[:strokewidth ], visible = plot[:visible ], overdraw = plot[:overdraw ]
5857 )
5958end
59+
6060# Poly conversion
61- poly_convert (geometries) = GLNormalMesh .(geometries)
61+ poly_convert (geometries) = triangle_mesh .(geometries)
6262poly_convert (meshes:: AbstractVector{<:AbstractMesh} ) = meshes
6363
6464function poly_convert (polygon:: AbstractVector{<: VecTypes} )
6868function poly_convert (polygons:: AbstractVector{<: AbstractVector{<: VecTypes}} )
6969 polys = Vector{Point2f0}[]
7070 for poly in polygons
71- s = GeometryTypes . split_intersections (poly)
71+ s = GeometryBasics . split_intersections (poly)
7272 append! (polys, s)
7373 end
74- return GLNormalMesh .(polys)
74+ return triangle_mesh .(polys)
7575end
7676
7777function to_line_segments (meshes)
@@ -94,7 +94,7 @@ function to_line_segments(polygon::AbstractVector{<: VecTypes})
9494 return result
9595end
9696
97- const PolyElements = Union{Circle, Rectangle, HyperRectangle , AbstractMesh, VecTypes, AbstractVector{<: VecTypes }}
97+ const PolyElements = Union{Circle, Rect , AbstractMesh, VecTypes, AbstractVector{<: VecTypes }}
9898
9999function plot! (plot:: Poly{<: Tuple{<: AbstractVector{<: PolyElements}}} )
100100 geometries = plot[1 ]
@@ -128,20 +128,26 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: AbstractMe
128128
129129 bigmesh = if color_node[] isa AbstractVector && length (color_node[]) == length (meshes[])
130130 # One color per mesh
131+ real_colors = Observable (RGBAf0[])
132+ attributes[:color ] = real_colors
131133 lift (meshes, color_node, attributes. colormap, attributes. colorrange) do meshes, colors, cmap, crange
132134 # Color are reals, so we need to transform it to colors first
133- real_colors = if colors isa AbstractVector{<: Number }
135+ single_colors = if colors isa AbstractVector{<: Number }
134136 interpolated_getindex .((to_colormap (cmap),), colors, (crange,))
135137 else
136138 to_color .(colors)
137139 end
138- meshes = GeometryTypes. add_attribute .(GLNormalMesh .(meshes), real_colors)
140+ # Map one single color per mesh to each vertex
141+ for (mesh, color) in zip (meshes, single_colors)
142+ append! (real_colors[], Iterators. repeated (RGBAf0 (color), length (coordinates (mesh))))
143+ end
144+ real_colors[] = real_colors[]
139145 return merge (meshes)
140146 end
141147 else
142148 attributes[:color ] = color_node
143149 lift (meshes) do meshes
144- return merge (GLPlainMesh .(meshes))
150+ return merge (triangle_mesh .(meshes))
145151 end
146152 end
147153 mesh! (plot, attributes, bigmesh)
@@ -256,8 +262,8 @@ function plot!(plot::Wireframe{<: Tuple{<: Any, <: Any, <: AbstractMatrix}})
256262 points = vec (Point3f0 .(xvector (x, M), yvector (y, N), z))
257263 # Connect the vetices with faces, as one would use for a 2D Rectangle
258264 # grid with M,N grid points
259- faces = decompose (Face{ 2 , GLIndex}, SimpleRectangle (0 , 0 , 1 , 1 ), (M, N))
260- view (points, faces)
265+ faces = decompose (LineFace{ GLIndex}, Rect2D (0 , 0 , 1 , 1 ), (M, N))
266+ connect (points, faces)
261267 end
262268 linesegments! (plot, Theme (plot), points_faces)
263269end
266272function plot! (plot:: Wireframe{Tuple{T}} ) where T
267273 points = lift (plot[1 ]) do g
268274 # get the point representation of the geometry
269- indices = decompose (Face{ 2 , GLIndex}, g)
275+ indices = decompose (LineFace{ GLIndex}, g)
270276 points = decompose (Point3f0, g)
271- view (points, indices)
277+ return connect (points, indices)
272278 end
273279 linesegments! (plot, Theme (plot), points)
274280end
323329# linesegments!(plot, Theme(plot), lines)
324330# end
325331
326-
327332"""
328333 Series - ?
329334
@@ -563,6 +568,7 @@ $(ATTRIBUTES)
563568@recipe (Band, lowerpoints, upperpoints) do scene
564569 Theme (;
565570 default_theme (scene, Mesh)... ,
571+ colorrange = automatic,
566572 color = RGBAf0 (0.0 ,0 ,0 ,0.2 )
567573 )
568574end
@@ -572,7 +578,7 @@ convert_arguments(::Type{<: Band}, x, ylower, yupper) = (Point2f0.(x, ylower), P
572578function band_connect (n)
573579 ns = 1 : n- 1
574580 ns2 = n+ 1 : 2 n- 1
575- [GLTriangle .(ns, ns .+ 1 , ns2); GLTriangle .(ns .+ 1 , ns2 .+ 1 , ns2)]
581+ [GLTriangleFace .(ns, ns .+ 1 , ns2); GLTriangleFace .(ns .+ 1 , ns2 .+ 1 , ns2)]
576582end
577583
578584function plot! (plot:: Band )
@@ -627,6 +633,7 @@ $(ATTRIBUTES)
627633 colorrange = AbstractPlotting. automatic,
628634 levels = 5 ,
629635 linewidth = 1.0 ,
636+ alpha = 1.0 ,
630637 fillrange = false ,
631638 )
632639end
@@ -643,7 +650,6 @@ $(ATTRIBUTES)
643650 default_theme (scene, Contour)
644651end
645652
646-
647653function contourlines (:: Type{<: Contour} , contours, cols)
648654 result = Point2f0[]
649655 colors = RGBA{Float32}[]
@@ -672,19 +678,19 @@ function contourlines(::Type{<: Contour3d}, contours, cols)
672678 result, colors
673679end
674680
675-
676681to_levels (x:: AbstractVector{<: Number} , cnorm) = x
682+
677683function to_levels (n:: Integer , cnorm)
678684 zmin, zmax = cnorm
679685 dz = (zmax - zmin) / (n + 1 )
680686 range (zmin + dz; step = dz, length = n)
681687end
688+
682689conversion_trait (:: Type{<: Contour3d} ) = SurfaceLike ()
683690conversion_trait (:: Type{<: Contour} ) = SurfaceLike ()
684691conversion_trait (:: Type{<: Contour{<: Tuple{X, Y, Z, Vol}}} ) where {X, Y, Z, Vol} = VolumeLike ()
685692conversion_trait (:: Type {<: Contour{<: Tuple{<: AbstractArray{T, 3}}} }) where T = VolumeLike ()
686693
687-
688694function plot! (plot:: Contour{<: Tuple{X, Y, Z, Vol}} ) where {X, Y, Z, Vol}
689695 x, y, z, volume = plot[1 : 4 ]
690696 @extract plot (colormap, levels, linewidth, alpha)
0 commit comments