Skip to content

Commit 880b5ef

Browse files
authored
Fix ScaleKeepAspect scaling to wrong size (#100)
Addresses ScaleKeepAspect not scaling to the requested size due to floating point imprecision. This also adds an example case to the unit tests.
1 parent 254a0a0 commit 880b5ef

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/projective/affine.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
function projectionbounds(tfm::ScaleKeepAspect{N}, P, bounds::Bounds{N}; randstate = nothing) where N
6161
origsz = length.(bounds.rs)
6262
ratio = maximum((tfm.minlengths) ./ origsz)
63-
sz = floor.(Int,ratio .* origsz)
63+
sz = round.(Int, ratio .* origsz)
6464
bounds_ = transformbounds(bounds, P)
6565
bs_ = offsetcropbounds(sz, bounds_, ntuple(_ -> 0.5, N))
6666
return bs_

test/projective/affine.jl

+3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ include("../imports.jl")
9494

9595
@testset ExtendedTestSet "ScaleKeepAspect" begin
9696
tfm = ScaleKeepAspect((32, 32))
97+
9798
img = rand(RGB{N0f8}, 64, 96)
9899
@test apply(tfm, Image(img)) |> itemdata |> size == (32, 48)
99100

101+
img = rand(RGB{N0f8}, 196, 196)
102+
@test apply(tfm, Image(img)) |> itemdata |> size == (32, 32)
100103
end
101104
end
102105

0 commit comments

Comments
 (0)