Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit d460a60

Browse files
authored
Merge pull request #351 from JuliaPlots/sd/geometrybasics
switch to geometrybasics
2 parents bb99b60 + 9edc07b commit d460a60

24 files changed

+492
-415
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test:
1717
- apt-get install -y cmake xorg-dev mesa-utils # glfw
1818
script:
1919
- mkdir -p $JULIA_DEPOT_PATH # Pkg.jl#325
20-
- julia --project -e 'using Pkg; pkg"add GLMakie#master"; Pkg.test(; coverage=true)'
20+
- julia --project -e 'using Pkg; pkg"add Packing#master MeshIO#master FreeTypeAbstraction#master https://github.com/SimonDanisch/GridLayoutBase.jl.git#sd/geometrybasics GLMakie#sd/geometrybasics StatsMakie#sd/geometrybasics MakieGallery#master; build"; Pkg.test(; coverage=true)'
2121
after_script:
2222
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit_local(process_folder(), ".")'
2323
artifacts:

Project.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AbstractPlotting"
22
uuid = "537997a7-5e4e-5d89-9595-2241ea00577e"
3-
version = "0.9.27"
3+
version = "0.10.0"
44

55
[deps]
66
AbstractNumbers = "85c772de-338a-5e7f-b815-41e76c26ac1f"
@@ -15,7 +15,7 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
1515
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
1616
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
1717
FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9"
18-
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
18+
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
1919
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
2020
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
2121
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -45,21 +45,23 @@ DocStringExtensions = "0.8"
4545
FFMPEG = "0.2, 0.3"
4646
FileIO = "1.1"
4747
FixedPointNumbers = "0.6, 0.7, 0.8"
48-
FreeType = "2.1, 3.0"
49-
FreeTypeAbstraction = "0.6"
50-
GeometryTypes = "0.8.1"
48+
FreeType = "3.0"
49+
FreeTypeAbstraction = "0.6, 0.7"
50+
GLMakie = "0.18, 0.1"
51+
GeometryBasics = "0.2.2"
5152
ImageMagick = "0.7, 1.0"
5253
IntervalSets = "0.3, 0.4"
54+
MakieGallery = "0.2"
55+
MeshIO = "0.3, 0.4"
5356
Observables = "0.3.1"
54-
Packing = "0.3"
57+
Packing = "0.3, 0.4"
5558
PlotUtils = "^0.6.2"
5659
Showoff = "0.3"
5760
SignedDistanceFields = "0.4"
5861
StaticArrays = "0.12"
5962
StructArrays = "0.3.0, 0.4"
6063
UnicodeFun = "0.4"
6164
julia = "1.0"
62-
MakieGallery = "0.1.9"
6365

6466
[extras]
6567
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/AbstractPlotting.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
module AbstractPlotting
22

3+
using Random
34
using FFMPEG # get FFMPEG on any system!
4-
using Observables, GeometryTypes, StaticArrays, IntervalSets, PlotUtils
5+
using Observables, GeometryBasics, StaticArrays, IntervalSets, PlotUtils
56
using ColorBrewer, ColorTypes, Colors, ColorSchemes
67
using FixedPointNumbers, Packing, SignedDistanceFields
78
using Markdown, DocStringExtensions # documentation
89
using Serialization # serialize events
910
using StructArrays
11+
# conflicting identifiers
12+
using GeometryBasics: widths, positive_widths
13+
1014
# Text related packages
1115
using FreeType, FreeTypeAbstraction, UnicodeFun
1216
using LinearAlgebra, Statistics
@@ -39,6 +43,8 @@ include("utilities/texture_atlas.jl")
3943
include("interaction/nodes.jl")
4044
include("interaction/liftmacro.jl")
4145

46+
include("colorsampler.jl")
47+
4248
# Basic scene/plot/recipe interfaces + types
4349
include("scenes.jl")
4450
include("theming.jl")
@@ -159,8 +165,6 @@ export (..), GLNormalUVMesh
159165
# Exports of units
160166
export px
161167

162-
# conflicting identifiers
163-
using GeometryTypes: widths, positive_widths
164168
export widths, decompose
165169

166170
# building blocks for series recipes
@@ -176,7 +180,6 @@ export save
176180
# colormap stuff from PlotUtils, and showlibrary, showgradients
177181
export clibraries, cgradients, clibrary, showlibrary, showgradients
178182

179-
180183
# default icon for Makie
181184
function icon()
182185
path = joinpath(dirname(pathof(AbstractPlotting)), "..", "assets", "icons")

src/basic_recipes/axis.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ default_labels(x::AbstractVector{<: AbstractString}, ranges, formatter::Function
249249
default_labels(x::AbstractVector{<: AbstractString}, ranges::AbstractVector, formatter::Function) = x
250250

251251
function convert_arguments(::Type{<: Axis2D}, limits::Rect)
252-
e = (minimum(limits), maximum(limits))
252+
e = extrema(limits)
253253
(((e[1][1], e[2][1]), (e[1][2], e[2][2])),)
254254
end
255255

@@ -332,7 +332,7 @@ function draw_frame(
332332

333333
mini = minimum.(limits)
334334
maxi = maximum.(limits)
335-
rect = HyperRectangle(Vec(mini), Vec(maxi .- mini))
335+
rect = Rect(Vec(mini), Vec(maxi .- mini))
336336
origin = Vec{N}(0.0)
337337
if (origin in rect) && axis_position == :origin
338338
for i = 1:N
@@ -592,13 +592,6 @@ function labelposition(ranges, dim, dir, tgap, origin::StaticVector{N}) where N
592592
origin .+ (halfaxis .+ (normalize(dir) * tgap))
593593
end
594594

595-
596-
function GeometryTypes.widths(x::AbstractRange)
597-
mini, maxi = Float32.(extrema(x))
598-
maxi - mini
599-
end
600-
601-
602595
_widths(x::Tuple{<: Number, <: Number}) = x[2] - x[1]
603596
_widths(x) = Float32(maximum(x) - minimum(x))
604597

src/basic_recipes/basic_recipes.jl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Plots a polygon based on the arguments given.
88
When vertices and indices are given, it functions similarly to `mesh`.
99
When 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
@@ -40,11 +40,10 @@ end
4040
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: AbstractMesh}) = (v,)
4141
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: VecTypes}) = (v,)
4242
convert_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,)
4444
convert_arguments(::Type{<: Poly}, args...) = ([convert_arguments(Scatter, args...)[1]],)
4545
convert_arguments(::Type{<: Poly}, vertices::AbstractArray, indices::AbstractArray) = convert_arguments(Mesh, vertices, indices)
4646

47-
4847
function 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
)
5958
end
59+
6060
# Poly conversion
61-
poly_convert(geometries) = GLNormalMesh.(geometries)
61+
poly_convert(geometries) = triangle_mesh.(geometries)
6262
poly_convert(meshes::AbstractVector{<:AbstractMesh}) = meshes
6363

6464
function poly_convert(polygon::AbstractVector{<: VecTypes})
@@ -68,10 +68,10 @@ end
6868
function 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)
7575
end
7676

7777
function to_line_segments(meshes)
@@ -94,7 +94,7 @@ function to_line_segments(polygon::AbstractVector{<: VecTypes})
9494
return result
9595
end
9696

97-
const PolyElements = Union{Circle, Rectangle, HyperRectangle, AbstractMesh, VecTypes, AbstractVector{<:VecTypes}}
97+
const PolyElements = Union{Circle, Rect, AbstractMesh, VecTypes, AbstractVector{<:VecTypes}}
9898

9999
function 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)
263269
end
@@ -266,9 +272,9 @@ end
266272
function 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)
274280
end
@@ -323,7 +329,6 @@ end
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
)
568574
end
@@ -572,7 +578,7 @@ convert_arguments(::Type{<: Band}, x, ylower, yupper) = (Point2f0.(x, ylower), P
572578
function band_connect(n)
573579
ns = 1:n-1
574580
ns2 = n+1:2n-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)]
576582
end
577583

578584
function 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
)
632639
end
@@ -643,7 +650,6 @@ $(ATTRIBUTES)
643650
default_theme(scene, Contour)
644651
end
645652

646-
647653
function 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
673679
end
674680

675-
676681
to_levels(x::AbstractVector{<: Number}, cnorm) = x
682+
677683
function to_levels(n::Integer, cnorm)
678684
zmin, zmax = cnorm
679685
dz = (zmax - zmin) / (n + 1)
680686
range(zmin + dz; step = dz, length = n)
681687
end
688+
682689
conversion_trait(::Type{<: Contour3d}) = SurfaceLike()
683690
conversion_trait(::Type{<: Contour}) = SurfaceLike()
684691
conversion_trait(::Type{<: Contour{<: Tuple{X, Y, Z, Vol}}}) where {X, Y, Z, Vol} = VolumeLike()
685692
conversion_trait(::Type{<: Contour{<: Tuple{<: AbstractArray{T, 3}}}}) where T = VolumeLike()
686693

687-
688694
function 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)

src/basic_recipes/legend.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,9 @@ function plot!(plot::ColorLegend)
200200
)
201201
)
202202
vertices = Point3f0[(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)]
203-
mesh = GLNormalUVMesh(
204-
vertices = copy(vertices),
205-
faces = GLTriangle[(1, 2, 3), (3, 4, 1)],
206-
texturecoordinates = UV{Float32}[(0, 1), (0, 0), (0, 0), (0, 1)]
203+
mesh = GeometryBasics.Mesh(
204+
meta(vertices, uv=Vec2f0[(0, 1), (0, 0), (0, 0), (0, 1)]),
205+
GLTriangleFace[(1, 2, 3), (3, 4, 1)],
207206
)
208207

209208
cmap_node = lift(colormap) do cmap
@@ -242,7 +241,7 @@ function plot!(plot::ColorLegend)
242241
rect
243242
end
244243
meshnode = lift(width, padding, textsize) do w, pad, ts
245-
mesh.vertices .= broadcast(vertices) do v
244+
mesh.position .= broadcast(vertices) do v
246245
Point3f0(((Point2f0(v[1], v[2]) .* Point2f0(w)) .+ Point2f0(0, ts/2) .+ pad)..., 0.0)
247246
end
248247
mesh

src/camera/camera2d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ end
239239

240240

241241

242-
function add_restriction!(cam, window, rarea::SimpleRectangle, minwidths::Vec)
242+
function add_restriction!(cam, window, rarea::Rect2D, minwidths::Vec)
243243
area_ref = Base.RefValue(cam[Area])
244244
restrict_action = paused_action(1.0) do t
245245
o = lerp(origin(area_ref[]), origin(cam[Area]), t)

src/camera/projection_math.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ end
109109
projection ratio in terms of the rectangular view size `rect` rather
110110
than the aspect ratio.
111111
"""
112-
function perspectiveprojection(wh::SimpleRectangle, fov::T, near::T, far::T) where T
112+
function perspectiveprojection(wh::Rect2D, fov::T, near::T, far::T) where T
113113
perspectiveprojection(fov, T(wh.w/wh.h), near, far)
114114
end
115115
function perspectiveprojection(
116-
::Type{T}, wh::SimpleRectangle, fov::Number, near::Number, far::Number
116+
::Type{T}, wh::Rect2D, fov::Number, near::Number, far::Number
117117
) where T
118118
perspectiveprojection(T(fov), T(wh.w/wh.h), T(near), T(far))
119119
end
@@ -141,11 +141,11 @@ end
141141
function lookat(::Type{T}, eyePos::Vec{3}, lookAt::Vec{3}, up::Vec{3}) where T
142142
lookat(Vec{3,T}(eyePos), Vec{3,T}(lookAt), Vec{3,T}(up))
143143
end
144-
function orthographicprojection(wh::SimpleRectangle, near::T, far::T) where T
144+
function orthographicprojection(wh::Rect2D, near::T, far::T) where T
145145
orthographicprojection(zero(T), T(wh.w), zero(T), T(wh.h), near, far)
146146
end
147147
function orthographicprojection(
148-
::Type{T}, wh::SimpleRectangle, near::Number, far::Number
148+
::Type{T}, wh::Rect2D, near::Number, far::Number
149149
) where T
150150
orthographicprojection(wh, T(near), T(far))
151151
end
@@ -176,8 +176,6 @@ function orthographicprojection(::Type{T},
176176
)
177177
end
178178

179-
180-
181179
mutable struct Pivot{T}
182180
origin ::Vec{3, T}
183181
xaxis ::Vec{3, T}
@@ -188,7 +186,7 @@ mutable struct Pivot{T}
188186
scale ::Vec{3, T}
189187
end
190188

191-
GeometryTypes.origin(p::Pivot) = p.origin
189+
GeometryBasics.origin(p::Pivot) = p.origin
192190

193191
rotationmatrix4(q::Quaternion{T}) where {T} = Mat4{T}(q)
194192

0 commit comments

Comments
 (0)