Skip to content

Commit f0d6da4

Browse files
committed
Fix imrotate for Irrational θ
1 parent 516dbf6 commit f0d6da4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/warp.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,19 @@ mosaicview([imgr for _ in 1:9]; nrow=3)
244244
"""
245245
function imrotate(img::AbstractArray{T}, θ::Real, inds::Union{Tuple, Nothing} = nothing; kwargs...) where T
246246
# TODO: expose rotation center as a keyword
247-
Δ = eps(θ)
248-
θ = mod2pi(θ)
247+
Δ = eps(float(θ))
248+
θ = _mod2pi(θ)
249249
if abs(θ) <= Δ || abs- 2π) <= Δ
250250
θ = zero(θ)
251251
end
252-
tform = recenter(RotMatrix{2}(θ), center(img))
252+
tform = recenter(rotmtrx2(θ), center(img))
253253
# Use the `nothing` trick here because moving the `autorange` as default value is not type-stable
254254
inds = isnothing(inds) ? autorange(img, inv(tform)) : inds
255255
warp(img, tform, inds; kwargs...)
256256
end
257+
_mod2pi(θ) = mod2pi(θ)
258+
_mod2pi::Irrational{:π}) = θ
259+
_mod2pi::Irrational) = mod2pi(float(θ))
260+
261+
rotmtrx2(θ) = RotMatrix{2}(θ)
262+
rotmtrx2::Irrational{:π}) = @SMatrix [-1 0; 0 1]

test/warp.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,5 +465,11 @@ NaN NaN NaN NaN NaN NaN NaN
465465
@test !any(isnan, imrotate(img, π/3, axes(img); fillvalue=0.0))
466466
@test !any(isnan, imrotate(img, π/3, axes(img), fillvalue=0.0))
467467
end
468+
469+
@testset "Examples from #79" begin
470+
@test axes(imrotate(img_camera, pi/2)) == axes(img_camera)
471+
@test imrotate(imrotate(imrotate(imrotate(img_camera, pi/2), pi/2), pi/2), pi/2) img_camera
472+
@test imrotate(imrotate(img_camera, pi), pi) == img_camera
473+
end
468474
end
469475
end

0 commit comments

Comments
 (0)