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

Add origin to Transformation #4472

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Oct 10, 2024

Description

Related: #4445, #2637

This adds an origin to Transformation so that rotate!() and scale!() can be relative to something other than Vec3(0). It can be set with translate_origin!() just like translate!().

Example:

p = rand(Point2f)
rect = Rect2f(p .- 0.1, Vec2f(0.2))

fig = Figure()
sl = Slider(fig[1, 1], range = range(0, 2pi, length=101))
ax = Axis(fig[2, 1], aspect = DataAspect())
p1 = poly!(ax, rect, color = :orange)
p2 = lines!(ax, rect, color = :red)
xlims!(ax, -1.5, 1.5)
ylims!(ax, -1.1, 1.1)

on(sl.value) do angle
    center = to_ndim(Vec3f, p, 0)

    R = Makie.rotationmatrix_z(angle)
    T = Makie.translationmatrix(-center)
    Tinv = Makie.translationmatrix(center)
    p1.transformation.model[] = Tinv * R * T # Did we break setting plot.model?
    
    translate_origin!(p2, p)
    Makie.rotate!(p2, angle)
end

fig

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Added an entry in CHANGELOG.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.

@MakieBot
Copy link
Collaborator

MakieBot commented Oct 10, 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 5.04s (4.98, 5.07) 0.03+- 109.12ms (107.87, 112.46) 1.58+- 414.27ms (410.25, 418.08) 2.86+- 9.54ms (9.34, 9.81) 0.17+- 25.69ms (25.63, 25.73) 0.03+-
master 5.05s (4.99, 5.10) 0.04+- 109.24ms (108.23, 110.36) 0.80+- 647.38ms (641.41, 656.41) 5.52+- 8.28ms (8.18, 8.38) 0.07+- 25.83ms (25.73, 26.14) 0.15+-
evaluation 1.00x invariant, -0.01s (-0.21d, 0.70p, 0.04std) 1.00x invariant, -0.12ms (-0.10d, 0.86p, 1.19std) 1.56x faster✅, -233.11ms (-53.03d, 0.00p, 4.19std) 0.87x slower❌, 1.26ms (9.70d, 0.00p, 0.12std) 1.01x faster ✓, -0.14ms (-1.36d, 0.04p, 0.09std)
CairoMakie 4.86s (4.83, 4.90) 0.03+- 110.93ms (109.97, 113.67) 1.25+- 168.75ms (166.57, 172.22) 1.92+- 9.57ms (9.32, 9.74) 0.17+- 1.19ms (1.15, 1.23) 0.04+-
master 4.88s (4.84, 4.90) 0.02+- 110.04ms (109.38, 110.76) 0.47+- 167.98ms (166.64, 170.41) 1.44+- 9.44ms (9.39, 9.50) 0.05+- 1.16ms (1.15, 1.17) 0.01+-
evaluation 1.00x invariant, -0.02s (-0.65d, 0.25p, 0.02std) 0.99x invariant, 0.89ms (0.95d, 0.12p, 0.86std) 1.00x invariant, 0.77ms (0.45d, 0.41p, 1.68std) 0.99x invariant, 0.13ms (1.08d, 0.08p, 0.11std) 0.97x invariant, 0.03ms (1.15d, 0.07p, 0.02std)
WGLMakie 5.48s (5.31, 5.64) 0.13+- 113.65ms (109.32, 115.94) 2.49+- 5.27s (5.17, 5.39) 0.10+- 13.28ms (12.83, 15.18) 0.84+- 118.65ms (116.45, 122.03) 1.93+-
master 5.43s (5.31, 5.53) 0.09+- 112.60ms (107.44, 123.93) 6.16+- 5.29s (4.95, 5.73) 0.27+- 12.00ms (11.40, 12.94) 0.56+- 119.76ms (113.22, 125.36) 4.40+-
evaluation 0.99x invariant, 0.06s (0.51d, 0.36p, 0.11std) 0.99x invariant, 1.05ms (0.22d, 0.69p, 4.32std) 1.00x invariant, -0.02s (-0.09d, 0.87p, 0.19std) 0.90x slower❌, 1.28ms (1.79d, 0.01p, 0.70std) 1.01x invariant, -1.11ms (-0.33d, 0.56p, 3.16std)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Work in progress
Development

Successfully merging this pull request may close these issues.

2 participants