Skip to content

Commit

Permalink
expand bounding box to fix coordinate transformation for highly zoome…
Browse files Browse the repository at this point in the history
…d image (#69)
  • Loading branch information
jwahlstrand committed May 25, 2024
1 parent a2941b8 commit 1d0a994
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/GtkObservables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ function Graphics.set_coordinates(c::Union{GraphicsContext,Canvas,GtkCanvas}, zr
end
function Graphics.set_coordinates(c::Union{Canvas,GtkCanvas}, inds::Tuple{AbstractUnitRange,AbstractUnitRange})
y, x = inds
bb = BoundingBox(first(x), last(x), first(y), last(y))
bb = BoundingBox(first(x)-0.5, last(x)+0.5, first(y)-0.5, last(y)+0.5)
set_coordinates(c, bb)
end
function Graphics.BoundingBox(xy::XY)
BoundingBox(minimum(xy.x), maximum(xy.x), minimum(xy.y), maximum(xy.y))
BoundingBox(minimum(xy.x)-0.5, maximum(xy.x)+0.5, minimum(xy.y)-0.5, maximum(xy.y)+0.5)
end

function Base.setindex!(zr::Observable{ZoomRegion{T}}, cv::XY{ClosedInterval{S}}) where {T,S}
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ end
@test isa(MouseScroll{UserUnit}(), MouseScroll{UserUnit})
@test isa(MouseScroll{DeviceUnit}(), MouseScroll{DeviceUnit})

@test BoundingBox(XY(2..4, -15..15)) === BoundingBox(2, 4, -15, 15)
@test BoundingBox(XY(2..4, -15..15)) === BoundingBox(1.5, 4.5, -15.5, 15.5)

c = canvas(208, 207)
win = GtkWindow(c)
Expand All @@ -364,8 +364,8 @@ end
corner_dev = (DeviceUnit(208), DeviceUnit(207))
can_test_coords = (get(ENV, "CI", nothing) != "true" || !Sys.islinux()) && can_test_width
for (coords, corner_usr) in ((BoundingBox(0, 1, 0, 1), (UserUnit(1), UserUnit(1))),
(ZoomRegion((5:10, 3:5)), (UserUnit(5), UserUnit(10))),
((-1:1, 101:110), (UserUnit(110), UserUnit(1))))
(ZoomRegion((5:10, 3:5)), (UserUnit(5.5), UserUnit(10.5))),
((-1:1, 101:110), (UserUnit(110.5), UserUnit(1.5))))
set_coordinates(c, coords)
if can_test_coords
@test GtkObservables.convertunits(DeviceUnit, c, corner_dev...) == corner_dev
Expand Down

0 comments on commit 1d0a994

Please sign in to comment.