Skip to content

Commit

Permalink
add test for project(scene, point)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Nov 25, 2024
1 parent fabf49e commit 838d04d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,34 @@ using Makie
@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!)
update_cam!(sc, Vec3d(0, 1, 0), Vec3d(0))
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)
@test fbl_px == Point3f(0, 0, 10_000)
@test ntr_px == Point3f(650, 400, -10_000)

# These tests are sensitive to camera settings. If the projectionview
# check fails the rest probably needs to be recalculated.
pv = Mat4d(-1.4856698845372893, 0.0, 0.0, 0.0, 0.0, 0.0, -1.024204047037133, -1.0, 0.0, 2.4142135623730954, 0.0, 0.0, 0.0, 0.0, 0.8217836423334196, 1.0)
@test pv sc.camera.projectionview[] atol = 1e-10

bottom_left_data = Vec3d(0.13302875, 0.8023632, -0.08186384)
top_righ_data = Vec3d(-0.13302875, 0.8023632, 0.08186384)
@test Makie.project(sc, bottom_left_data) Point2f(0, 0) atol = 1e-4
@test Makie.project(sc, top_righ_data) Point2f(650, 400) atol = 1e-4

@test Makie.project(sc, :pixel, :data, Vec2f(0, 0)) bottom_left_data
@test Makie.project(sc, :pixel, :data, Vec2f(650, 400)) top_righ_data
end

@testset "No warnings in projections between spaces" begin
Expand All @@ -29,6 +44,7 @@ using Makie
end
end
end

end
end

Expand Down

0 comments on commit 838d04d

Please sign in to comment.