Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check converted as well as input args in polygon drawing in CairoMakie #3605

Merged
merged 6 commits into from
Feb 7, 2024

Conversation

asinghvi17
Copy link
Member

@asinghvi17 asinghvi17 commented Feb 6, 2024

Description

CairoMakie decided whether or not to draw polygons as meshes based on the type of the input arguments. However, this excluded types which are later converted to polygons via convert_arguments from the direct polygon drawing path, forcing them to be meshed and rasterized.

This PR enables CairoMakie to decide whether to use meshes or not based on both the input and converted argument types. It first checks whether there is an available draw_poly method for the input types (plot.args...), if there is then it proceeds. If not, it checks whether there is an available draw_poly method for the converted types (plot.converted...), and proceeds there. The last/base case is of course a call to draw_poly_as_mesh.

This has eliminated the generic fallback for draw_poly(scene, screen, plot) as the decision-making is now done in draw_plot.

As an example: Rect, BezierPath, Vector{<: Point}, or Polygon input will be processed directly. Inputs from other geometry packages like ArchGDAL, GeoJSON, etc which were previously interpreted as requiring meshing will now be drawn as polygons, since after conversion they are usually GeometryBasics.Polygon or similar which have dispatches in draw_poly.

I also added some tests to make sure this behaviour stays consistent!

Type of change

Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

Fixes #3600
Fixes MakieOrg/GeoMakie.jl#181

@asinghvi17 asinghvi17 added the CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. label Feb 6, 2024
@asinghvi17 asinghvi17 changed the title Check converted as well as input args in polygon drawing Check converted as well as input args in polygon drawing in CairoMakie Feb 6, 2024
@asinghvi17 asinghvi17 requested review from SimonDanisch and jkrumbiegel and removed request for SimonDanisch February 6, 2024 14:14
@asinghvi17 asinghvi17 self-assigned this Feb 6, 2024
@MakieBot
Copy link
Collaborator

MakieBot commented Feb 6, 2024

Compile Times benchmark

Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than the base branch. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running:

using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(fig)
using create display create display
GLMakie 3.46s (3.39, 3.55) 0.06+- 391.22ms (380.73, 409.77) 10.86+- 469.88ms (462.62, 483.23) 6.91+- 7.25ms (7.06, 7.63) 0.21+- 25.49ms (25.26, 25.92) 0.27+-
master 3.49s (3.39, 3.58) 0.07+- 392.22ms (380.32, 400.29) 8.25+- 480.62ms (460.91, 532.33) 24.63+- 7.40ms (7.08, 7.59) 0.22+- 25.58ms (25.25, 26.07) 0.30+-
evaluation 1.01x invariant, -0.03s (-0.47d, 0.40p, 0.07std) 1.00x invariant, -1.01ms (-0.10d, 0.85p, 9.56std) 1.02x invariant, -10.74ms (-0.59d, 0.30p, 15.77std) 1.02x invariant, -0.15ms (-0.67d, 0.23p, 0.22std) 1.00x invariant, -0.09ms (-0.31d, 0.57p, 0.29std)
CairoMakie 3.16s (3.10, 3.26) 0.05+- 342.35ms (327.07, 354.21) 9.78+- 147.93ms (141.62, 155.31) 5.35+- 7.64ms (7.41, 7.95) 0.18+- 618.73μs (613.72, 621.81) 2.66+-
master 3.16s (3.07, 3.25) 0.06+- 340.94ms (323.10, 349.78) 9.37+- 146.43ms (145.16, 148.10) 0.91+- 7.57ms (7.46, 7.70) 0.10+- 607.46μs (602.28, 618.45) 5.78+-
evaluation 1.00x invariant, 0.0s (0.01d, 0.99p, 0.05std) 1.00x invariant, 1.41ms (0.15d, 0.79p, 9.58std) 0.99x invariant, 1.5ms (0.39d, 0.49p, 3.13std) 0.99x invariant, 0.07ms (0.48d, 0.39p, 0.14std) 0.98x slower X, 11.27μs (2.50d, 0.00p, 4.22std)
WGLMakie 3.92s (3.82, 4.01) 0.07+- 334.36ms (323.39, 345.97) 7.73+- 9.13s (8.93, 9.35) 0.19+- 9.49ms (9.33, 9.76) 0.14+- 76.70ms (68.12, 85.71) 5.92+-
master 3.74s (3.64, 3.87) 0.10+- 483.65ms (328.84, 566.42) 103.38+- 9.11s (8.96, 9.27) 0.11+- 9.39ms (9.07, 9.62) 0.21+- 72.64ms (68.07, 77.85) 4.02+-
evaluation 0.95x slower X, 0.18s (2.07d, 0.00p, 0.09std) 1.45x faster✅, -149.29ms (-2.04d, 0.01p, 55.55std) 1.00x invariant, 0.02s (0.11d, 0.84p, 0.15std) 0.99x invariant, 0.1ms (0.57d, 0.31p, 0.18std) 0.95x noisy🤷‍♀️, 4.07ms (0.80d, 0.16p, 4.97std)

@jkrumbiegel
Copy link
Member

Ah interesting, it used to be that the conversion went down to meshes, which is why I didn't use it at the time. But if it stops at Polygons now, that's useful.

@asinghvi17 asinghvi17 merged commit 4c5265c into master Feb 7, 2024
18 checks passed
@asinghvi17 asinghvi17 deleted the as/cairomakie_polygon_rasterization branch February 7, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo.
Projects
None yet
3 participants