Skip to content

Commit

Permalink
Merge branch 'master' into ff/standardize_view_projection
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer authored Feb 19, 2024
2 parents 69a5f72 + fe320c0 commit 0bc2d33
Show file tree
Hide file tree
Showing 53 changed files with 571 additions and 181 deletions.
1 change: 0 additions & 1 deletion .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
pull_request:
branches:
- master
- sd/beta-20
push:
tags:
- '*'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*.md'
branches:
- master
- sd/beta-20
push:
tags:
- '*'
Expand Down Expand Up @@ -48,6 +47,6 @@ jobs:
Pkg.test("Makie"; coverage=true)
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info
1 change: 0 additions & 1 deletion .github/workflows/compilation-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*.md'
branches:
- master
- sd/beta-20
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/enforce_news.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Enforce changelog"
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dangoslen/changelog-enforcer@v3
with:
changeLogPath: 'CHANGELOG.md'
skipLabels: 'skip-changelog'
6 changes: 3 additions & 3 deletions .github/workflows/reference_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
if: ${{ env.TESTS_SUCCESSFUL != 'true' }}
run: exit 1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info

Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
if: ${{ env.TESTS_SUCCESSFUL != 'true' }}
run: exit 1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info

Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
if: ${{ env.TESTS_SUCCESSFUL != 'true' }}
run: exit 1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/rprmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*.md'
branches:
- master
- sd/beta-20
push:
tags:
- '*'
Expand Down Expand Up @@ -58,6 +57,6 @@ jobs:
if: ${{ env.TESTS_SUCCESSFUL != 'true' }}
run: exit 1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info
163 changes: 120 additions & 43 deletions NEWS.md → CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CairoMakie"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <sdanisch@gmail.com>"]
version = "0.11.5"
version = "0.11.8"

[deps]
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
Expand All @@ -24,7 +24,7 @@ FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
LinearAlgebra = "1.0, 1.6"
Makie = "=0.20.4"
Makie = "=0.20.7"
PrecompileTools = "1.0"
julia = "1.3"

Expand Down
9 changes: 1 addition & 8 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ function openurl(url::String)
@warn("Can't find a way to open a browser, open $(url) manually!")
end

function display_path(type::String)
if !(type in ("svg", "png", "pdf", "eps"))
error("Only \"svg\", \"png\", \"eps\" and \"pdf\" are allowed for `type`. Found: $(type)")
end
return abspath(joinpath(@__DIR__, "display." * type))
end

function Base.display(screen::Screen, scene::Scene; connect=false)
# Nothing to do, since drawing is done in the other functions
# TODO write to file and implement upenurl
return screen
end

function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false)
path = display_path("png")
path = joinpath(mktempdir(), "display.png")
Makie.push_screen!(scene, screen)
cairo_draw(screen, scene)
Cairo.write_to_png(screen.surface, path)
Expand Down
40 changes: 24 additions & 16 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ complex and slower to draw than standard paths with single color.
"""
function draw_plot(scene::Scene, screen::Screen, poly::Poly)
# dispatch on input arguments to poly to use smarter drawing methods than
# meshes if possible
return draw_poly(scene, screen, poly, to_value.(poly.args)...)
# meshes if possible.
# however, since recipes exist, we can't explicitly handle all cases here
# so, we should also take a look at converted
# First, we check whether a `draw_poly` method exists for the input arguments
# before conversion:
return if Base.hasmethod(draw_poly, Tuple{Scene, Screen, typeof(poly), typeof.(to_value.(poly.args))...})
draw_poly(scene, screen, poly, to_value.(poly.args)...)
# If not, we check whether a `draw_poly` method exists for the arguments after conversion
# (`plot.converted`). This allows anything which decomposes to be checked for.
elseif Base.hasmethod(draw_poly, Tuple{Scene, Screen, typeof(poly), typeof.(to_value.(poly.converted))...})
draw_poly(scene, screen, poly, to_value.(poly.converted)...)
# In the worst case, we return to drawing the polygon as a mesh + lines.
else
draw_poly_as_mesh(scene, screen, poly)
end
end

# Override `is_cairomakie_atomic_plot` to allow `poly` to remain a unit,
# instead of auto-decomposing in lines and mesh.
is_cairomakie_atomic_plot(plot::Poly) = true

"""
Fallback method for args without special treatment.
"""
function draw_poly(scene::Scene, screen::Screen, poly, args...)
draw_poly_as_mesh(scene, screen, poly)
end

function draw_poly_as_mesh(scene, screen, poly)
draw_plot(scene, screen, poly.plots[1])
draw_plot(scene, screen, poly.plots[2])
end


# in the rare case of per-vertex colors redirect to mesh drawing
function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2}, color::AbstractArray, model, strokecolor, strokewidth)
# As a general fallback, draw all polys as meshes.
# This also applies for e.g. per-vertex color.
function draw_poly(scene::Scene, screen::Screen, poly, points, color, model, strokecolor, strokestyle, strokewidth)
draw_poly_as_mesh(scene, screen, poly)
end

Expand All @@ -45,7 +52,7 @@ end
function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2}, color::Union{Colorant, Cairo.CairoPattern},
model, strokecolor, strokestyle, strokewidth)
space = to_value(get(poly, :space, :data))
points = project_position.(Ref(scene), space, points, Ref(model))
points = project_position.(Ref(poly), space, points, Ref(model))
Cairo.move_to(screen.context, points[1]...)
for p in points[2:end]
Cairo.line_to(screen.context, p...)
Expand Down Expand Up @@ -78,7 +85,7 @@ draw_poly(scene::Scene, screen::Screen, poly, bezierpath::BezierPath) = draw_pol
function draw_poly(scene::Scene, screen::Screen, poly, shapes::Vector{<:Union{Rect2,BezierPath}})
model = poly.model[]
space = to_value(get(poly, :space, :data))
projected_shapes = project_shape.(Ref(scene), space, shapes, Ref(model))
projected_shapes = project_shape.(Ref(poly), space, shapes, Ref(model))

color = to_cairo_color(poly.color[], poly)

Expand Down Expand Up @@ -150,6 +157,7 @@ function polypath(ctx, polygon)
end

draw_poly(scene::Scene, screen::Screen, poly, polygon::Polygon) = draw_poly(scene, screen, poly, [polygon])
draw_poly(scene::Scene, screen::Screen, poly, multipolygon::MultiPolygon) = draw_poly(scene, screen, poly, multipolygon.polygons)
draw_poly(scene::Scene, screen::Screen, poly, circle::Circle) = draw_poly(scene, screen, poly, decompose(Point2f, circle))

function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<:Polygon})
Expand All @@ -175,7 +183,7 @@ end
function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<: MultiPolygon})
model = poly.model[]
space = to_value(get(poly, :space, :data))
projected_polys = project_multipolygon.(Ref(scene), space, polygons, Ref(model))
projected_polys = project_multipolygon.(Ref(poly), space, polygons, Ref(model))

color = to_cairo_color(poly.color[], poly)
strokecolor = to_cairo_color(poly.strokecolor[], poly)
Expand Down Expand Up @@ -211,7 +219,7 @@ function draw_plot(scene::Scene, screen::Screen,
points = vcat(lowerpoints, reverse(upperpoints))
model = band.model[]
space = to_value(get(band, :space, :data))
points = project_position.(Ref(scene), space, points, Ref(model))
points = project_position.(Ref(band), space, points, Ref(model))
Cairo.move_to(screen.context, points[1]...)
for p in points[2:end]
Cairo.line_to(screen.context, p...)
Expand Down Expand Up @@ -249,7 +257,7 @@ function draw_plot(scene::Scene, screen::Screen, tric::Tricontourf)
polygons = pol[1][]
model = pol.model[]
space = to_value(get(pol, :space, :data))
projected_polys = project_polygon.(Ref(scene), space, polygons, Ref(model))
projected_polys = project_polygon.(Ref(tric), space, polygons, Ref(model))

function draw_tripolys(polys, colornumbers, colors)
for (i, (pol, colnum, col)) in enumerate(zip(polys, colornumbers, colors))
Expand Down
6 changes: 3 additions & 3 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio
end

if primitive isa Lines && to_value(primitive.args[1]) isa BezierPath
return draw_bezierpath_lines(ctx, to_value(primitive.args[1]), scene, color, space, model, linewidth)
return draw_bezierpath_lines(ctx, to_value(primitive.args[1]), primitive, color, space, model, linewidth)
end

if color isa AbstractArray || linewidth isa AbstractArray
Expand Down Expand Up @@ -728,8 +728,8 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio
# find projected image corners
# this already takes care of flipping the image to correct cairo orientation
space = to_value(get(primitive, :space, :data))
xy = project_position(scene, space, Point2f(first.(imsize)), model)
xymax = project_position(scene, space, Point2f(last.(imsize)), model)
xy = project_position(primitive, space, Point2f(first.(imsize)), model)
xymax = project_position(primitive, space, Point2f(last.(imsize)), model)
w, h = xymax .- xy

can_use_fast_path = !(is_vector && !interpolate) && regular_grid && identity_transform &&
Expand Down
8 changes: 4 additions & 4 deletions CairoMakie/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function _project_position(scene::Scene, space, point, model, yflip::Bool)
return p_0_to_1 .* res
end

function project_position(scenelike, space, point, model, yflip::Bool = true)
function project_position(@nospecialize(scenelike), space, point, model, yflip::Bool = true)
scene = Makie.get_scene(scenelike)
project_position(scene, Makie.transform_func(scenelike), space, point, model, yflip)
end
Expand All @@ -47,13 +47,13 @@ function project_scale(scene::Scene, space, s, model = Mat4f(I))
end
end

function project_shape(scenelike, space, rect::Rect, model)
function project_shape(@nospecialize(scenelike), space, rect::Rect, model)
mini = project_position(scenelike, space, minimum(rect), model)
maxi = project_position(scenelike, space, maximum(rect), model)
return Rect(mini, maxi .- mini)
end

function project_polygon(scenelike, space, poly::P, model) where P <: Polygon
function project_polygon(@nospecialize(scenelike), space, poly::P, model) where P <: Polygon
ext = decompose(Point2f, poly.exterior)
interiors = decompose.(Point2f, poly.interiors)
Polygon(
Expand All @@ -62,7 +62,7 @@ function project_polygon(scenelike, space, poly::P, model) where P <: Polygon
)
end

function project_multipolygon(scenelike, space, multipoly::MP, model) where MP <: MultiPolygon
function project_multipolygon(@nospecialize(scenelike), space, multipoly::MP, model) where MP <: MultiPolygon
return MultiPolygon(project_polygon.(Ref(scenelike), Ref(space), multipoly.polygons, Ref(model)))
end

Expand Down
2 changes: 2 additions & 0 deletions CairoMakie/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[deps]
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoInterfaceMakie = "0edc0954-3250-4c18-859d-ec71c1660c08"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
ReferenceTests = "d37af2e0-5618-4e00-9939-d430db56ee94"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
11 changes: 6 additions & 5 deletions CairoMakie/test/rasterization_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function svg_has_image(x)
save(path, x)
# this is rough but an easy way to catch rasterization,
# if an image element is present in the svg
return !occursin("<image id=", read(path, String))
return occursin("<image id=", read(path, String))
end
end

Expand All @@ -18,13 +18,14 @@ end
pl = poly!(ax, Makie.GeometryBasics.Polygon(pts))

@testset "Unrasterized SVG" begin
@test svg_has_image(fig)
@test !svg_has_image(fig)
end

@testset "Rasterized SVG" begin
lp.rasterize = true
@test !svg_has_image(fig)
@test svg_has_image(fig)
lp.rasterize = 10
@test !svg_has_image(fig)
@test svg_has_image(fig)
end
end

end
15 changes: 15 additions & 0 deletions CairoMakie/test/svg_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ end
@test svg_isnt_rasterized(poly(BezierPath([
MoveTo(0.0, 0.0), LineTo(1.0, 0.0), LineTo(1.0, 1.0), CurveTo(1.0, 1.0, 0.5, 1.0, 0.5, 0.5), ClosePath()
])))
@test !svg_isnt_rasterized(poly(rand(Point2f, 10); color = rand(RGBAf, 10)))

poly1 = Makie.GeometryBasics.Polygon(rand(Point2f, 10))
@test svg_isnt_rasterized(poly(Makie.GeometryBasics.MultiPolygon([poly1, poly1])))
@test svg_isnt_rasterized(poly(Makie.GeometryBasics.MultiPolygon([poly1, poly1]), color = :red))
@test svg_isnt_rasterized(poly(Makie.GeometryBasics.MultiPolygon([poly1, poly1]), color = [:red, :blue]))

@testset "GeoInterface polygons" begin
using GeoInterface, GeoInterfaceMakie
poly2 = GeoInterface.convert(GeoInterface.Wrappers, poly1)
@test svg_isnt_rasterized(poly(poly2))
@test svg_isnt_rasterized(poly(poly2, color = :red))
@test svg_isnt_rasterized(poly(GeoInterface.Wrappers.MultiPolygon([poly2, poly2]), color = [:red, :blue]))
end

end

@testset "reproducable svg ids" begin
Expand Down
4 changes: 2 additions & 2 deletions GLMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GLMakie"
uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
version = "0.9.5"
version = "0.9.8"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down Expand Up @@ -30,7 +30,7 @@ FreeTypeAbstraction = "0.10"
GLFW = "3.3"
GeometryBasics = "0.4.1"
LinearAlgebra = "1.0, 1.6"
Makie = "=0.20.4"
Makie = "=0.20.7"
Markdown = "1.0, 1.6"
MeshIO = "0.4"
ModernGL = "1"
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can find instructions to set that up in:
https://nextjournal.com/sdanisch/GLMakie-nogpu
And for a headless github action:

https://github.com/MakieOrg/Makie.jl/blob/master/.github/workflows/glmakie.yaml
https://github.com/MakieOrg/Makie.jl/blob/master/.github/workflows/reference_tests.yml
If none of these work for you, there is also a Cairo and WebGL backend
for Makie which you can use:

Expand Down
4 changes: 4 additions & 0 deletions GLMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ function Base.display(screen::Screen, scene::Scene; connect=true)
# So, the GLFW window events are not guarantee to fire
# when we close a window, so we ensure this here!
if !Makie.is_displayed(screen, scene)
if !isnothing(screen.root_scene)
delete!(screen, screen.root_scene)
screen.root_scene = nothing
end
display_scene!(screen, scene)
else
@assert screen.root_scene === scene "internal error. Scene already displayed by screen but not as root scene"
Expand Down
5 changes: 3 additions & 2 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,9 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Surface)
end

space = plot.space

gl_attributes[:image] = img
interp = to_value(pop!(gl_attributes, :interpolate, true))
interp = interp ? :linear : :nearest
gl_attributes[:image] = Texture(img; minfilter=interp)

@assert to_value(plot[3]) isa AbstractMatrix
types = map(v -> typeof(to_value(v)), plot[1:2])
Expand Down
Loading

0 comments on commit 0bc2d33

Please sign in to comment.