Skip to content

Commit

Permalink
Fix projection from clip to data space (#3909)
Browse files Browse the repository at this point in the history
* Fix undefined variable in `project` when passing a `Scene`

See https://github.com/HolyLab/FlyThroughPaths.jl/actions/runs/9246991707/job/25435166970?pr=6#step:8:45 for the original error message.

* Add tests to make sure all projections work

* Add changelog

---------

Co-authored-by: Frederic Freyer <[email protected]>
  • Loading branch information
asinghvi17 and ffreyer authored Jul 12, 2024
1 parent c4e3b7b commit b9bfa87
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Correct a bug in the `project` function when projecting using a `Scene`. [#3909](https://github.com/MakieOrg/Makie.jl/pull/3909).

## [0.21.5] - 2024-07-07

- Fixed tuple argument for `WGLMakie.activate!(resize_to=(:parent, nothing))` [#4009](https://github.com/MakieOrg/Makie.jl/pull/4009).
Expand Down
2 changes: 1 addition & 1 deletion src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function project(scenelike::SceneLike, input_space::Symbol, output_space::Symbol
output_from_clip = clip_to_space(cam, output_space)
output_f32c = inv_f32_convert_matrix(scenelike, output_space)

p4d = to_ndim(Point4{T}, to_ndim(Point3{T}, transformed, 0), 1)
p4d = to_ndim(Point4{T}, to_ndim(Point3{T}, pos, 0), 1)
transformed = output_f32c * output_from_clip * clip_from_input * input_f32c * p4d
return Point3{T}(transformed[Vec(1, 2, 3)] ./ transformed[4])
end
33 changes: 31 additions & 2 deletions test/projection_math.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
using Makie

@testset "Projection math" begin
@test eltype(Makie.rotationmatrix_x(1)) == Float64
@test eltype(Makie.rotationmatrix_x(1f0)) == Float32
@testset "Rotation matrix" begin
@test eltype(Makie.rotationmatrix_x(1)) == Float64
@test eltype(Makie.rotationmatrix_x(1f0)) == Float32
end
@testset "Projection between spaces in 3D" begin
# Set up an LScene and some points there
sc = Scene(size = (650, 400), camera = cam3d!)
corner_points_px = [Point3f(0, 0, 0), Point3f(650, 400, 0)]

@testset "Clip space and pixel space equivalence" begin
far_bottom_left_clip = Point3f(-1)
near_top_right_clip = Point3f(1)

fbl_px = Makie.project(sc, :clip, :pixel, far_bottom_left_clip)
ntr_px = Makie.project(sc, :clip, :pixel, near_top_right_clip)
@test Point2f(fbl_px) == Point2f(0, 0)
@test Point2f(ntr_px) == Point2f(650, 400)
end

@testset "No warnings in projections between spaces" begin
for (source, dest) in unique(Iterators.product(Makie.spaces(), Makie.spaces()))
source == dest && continue
current_space_points = Makie.project.(sc, :pixel, source, corner_points_px)
@testset "$source$dest" begin
@test_nowarn Makie.project.(sc, source, dest, current_space_points)
end
end
end
end
end

0 comments on commit b9bfa87

Please sign in to comment.