Skip to content

Commit

Permalink
fix tests, add test for tight limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Sep 12, 2023
1 parent 7c8f0bb commit e647c45
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions ReferenceTests/src/tests/figures_and_makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ end
ax = PolarAxis(f[1, 1])
zs = [r*cos(phi) for phi in range(0, 4pi, length=100), r in range(1, 2, length=100)]
p = surface!(ax, 0..2pi, 0..10, zs, shading = false, colormap = :coolwarm, colorrange=(-2, 2))
rlims!(ax, 0, 11) # verify that r = 10 doesn't end up at r > 10
translate!(p, 0, 0, -200)
Colorbar(f[1, 2], p)
f
Expand Down
4 changes: 2 additions & 2 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1690,9 +1690,9 @@ end
"Controls the argument order of the Polar transform. If `theta_as_x = true` it is (θ, r), otherwise (r, θ)."
theta_as_x::Bool = true
"The relative margins added to the autolimits in r direction."
rautolimitmargin::Tuple{Float64, Float64} = (0.05f0, 0.05f0)
rautolimitmargin::Tuple{Float64, Float64} = (0.05, 0.05)
"The relative margins added to the autolimits in theta direction."
thetaautolimitmargin::Tuple{Float64, Float64} = (0.05f0, 0.05f0)
thetaautolimitmargin::Tuple{Float64, Float64} = (0.05, 0.05)

# Spine

Expand Down
33 changes: 33 additions & 0 deletions test/PolarAxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
ax = PolarAxis(fig[1, 1])
p = scatter!(ax, Point2f(0))

# verify defaults
@test ax.rautolimitmargin[] == (0.05, 0.05)
@test ax.thetaautolimitmargin[] == (0.05, 0.05)

# default should have mostly set default limits
@test ax.rlimits[] == (0.0, nothing)
@test ax.thetalimits[] == (0.0, 2pi)
Expand All @@ -65,13 +69,15 @@

# but we want to test automatic limits here
autolimits!(ax)
reset_limits!(ax) # needed because window isn't open
@test ax.rlimits[] == (nothing, nothing)
@test ax.thetalimits[] == (nothing, nothing)
@test ax.target_rlims[] == (0.0, 10.0)
@test ax.target_thetalims[] == (0.0, 2pi)

# derived r, default theta
scatter!(ax, Point2f(0, 1))
reset_limits!(ax)
@test ax.target_rlims[] == (0.0, 1.05)
@test ax.target_thetalims[] == (0.0, 2pi)

Expand All @@ -83,25 +89,52 @@

# default r, derived theta
scatter!(ax, Point2f(0.5pi, 1))
reset_limits!(ax)
@test ax.target_rlims[] == (0.0, 10.0)
@test all(isapprox.(ax.target_thetalims[], (-0.025pi, 0.525pi), rtol=1e-6))

# derive both
scatter!(ax, Point2f(pi, 2))
reset_limits!(ax)
@test all(isapprox.(ax.target_rlims[], (0.95, 2.05), rtol=1e-6))
@test all(isapprox.(ax.target_thetalims[], (-0.05pi, 1.05pi), rtol=1e-6))

# set limits
rlims!(ax, 0.0, 3.0)
reset_limits!(ax)
@test ax.rlimits[] == (0.0, 3.0)
@test ax.target_rlims[] == (0.0, 3.0)
@test all(isapprox.(ax.target_thetalims[], (-0.05pi, 1.05pi), rtol=1e-6))

thetalims!(ax, 0.0, 2pi)
reset_limits!(ax)
@test ax.rlimits[] == (0.0, 3.0)
@test ax.target_rlims[] == (0.0, 3.0)
@test ax.thetalimits[] == (0.0, 2pi)
@test ax.target_thetalims[] == (0.0, 2pi)

# surface should result in tight limits (indirectly tests tightlimits!())
fig = Figure()
ax = PolarAxis(fig[1, 1])
surface!(ax, 0.5pi..pi, 2..5, rand(10, 10))

@test ax.rautolimitmargin[] == (0.0, 0.0)
@test ax.thetaautolimitmargin[] == (0.0, 0.0)

# with default limits
reset_limits!(ax)
@test ax.rlimits[] == (0.0, nothing)
@test ax.thetalimits[] == (0.0, 2pi)
@test ax.target_rlims[] == (0.0, 5.0)
@test ax.target_thetalims[] == (0.0, 2pi)

# with fully automatic limits
autolimits!(ax)
reset_limits!(ax)
@test ax.rlimits[] == (nothing, nothing)
@test ax.thetalimits[] == (nothing, nothing)
@test ax.target_rlims[] == (2.0, 5.0)
@test all(isapprox.(ax.target_thetalims[], (0.5pi, 1.0pi), rtol=1e-6))
end

@testset "Radial Distortion" begin
Expand Down

0 comments on commit e647c45

Please sign in to comment.