Skip to content

Commit

Permalink
Fix ScaleKeepAspect scaling to wrong size (#100)
Browse files Browse the repository at this point in the history
Addresses ScaleKeepAspect not scaling to the requested size due to
floating point imprecision. This also adds an example case to the unit
tests.
  • Loading branch information
paulnovo authored Oct 20, 2024
1 parent 254a0a0 commit 880b5ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/projective/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
function projectionbounds(tfm::ScaleKeepAspect{N}, P, bounds::Bounds{N}; randstate = nothing) where N
origsz = length.(bounds.rs)
ratio = maximum((tfm.minlengths) ./ origsz)
sz = floor.(Int,ratio .* origsz)
sz = round.(Int, ratio .* origsz)
bounds_ = transformbounds(bounds, P)
bs_ = offsetcropbounds(sz, bounds_, ntuple(_ -> 0.5, N))
return bs_
Expand Down
3 changes: 3 additions & 0 deletions test/projective/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ include("../imports.jl")

@testset ExtendedTestSet "ScaleKeepAspect" begin
tfm = ScaleKeepAspect((32, 32))

img = rand(RGB{N0f8}, 64, 96)
@test apply(tfm, Image(img)) |> itemdata |> size == (32, 48)

img = rand(RGB{N0f8}, 196, 196)
@test apply(tfm, Image(img)) |> itemdata |> size == (32, 32)
end
end

Expand Down

0 comments on commit 880b5ef

Please sign in to comment.