Skip to content

Commit

Permalink
Merge pull request #78 from JuliaGizmos/teh/cairo
Browse files Browse the repository at this point in the history
Revert "Perform unit conversions manually from cairomatrix"
  • Loading branch information
timholy authored Sep 20, 2018
2 parents 71f2689 + 0e16fe2 commit 0798153
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
17 changes: 2 additions & 15 deletions src/graphics_interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ Base.promote_rule(::Type{U}, ::Type{D}) where {U<:UserUnit,D<:DeviceUnit} =
error("UserUnit and DeviceUnit are incompatible, promotion not defined")

function convertunits(::Type{UserUnit}, c, x::DeviceUnit, y::DeviceUnit)
# For some unknown reason, the following doesn't seem to work
# over a remote X connection:
# xu, yu = device_to_user(getgc(c), x.val, y.val)
# So just do the inversion directly (see https://www.cairographics.org/manual/cairo-cairo-matrix-t.html#cairo-matrix-t)
m = Cairo.get_matrix(getgc(c))
Δx, Δy = x.val - m.x0, y.val - m.y0
det = m.xx * m.yy - m.yx * m.xy # manually do inverse of 2x2 matrix
xu, yu = (m.yy * Δx - m.xy * Δy)/det, (-m.yx * Δx + m.xx * Δy)/det

xu, yu = device_to_user(getgc(c), x.val, y.val)
UserUnit(xu), UserUnit(yu)
end
function convertunits(::Type{UserUnit}, c, x::UserUnit, y::UserUnit)
Expand All @@ -77,12 +69,7 @@ function convertunits(::Type{DeviceUnit}, c, x::DeviceUnit, y::DeviceUnit)
x, y
end
function convertunits(::Type{DeviceUnit}, c, x::UserUnit, y::UserUnit)
# See above
# xd, yd = user_to_device(getgc(c), x.val, y.val)
m = Cairo.get_matrix(getgc(c))
xd = m.xx * x.val + m.xy * y.val + m.x0
yd = m.yx * x.val + m.yy * y.val + m.y0

xd, yd = user_to_device(getgc(c), x.val, y.val)
DeviceUnit(xd), DeviceUnit(yd)
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ end
(ZoomRegion((5:10, 3:5)), (UserUnit(5), UserUnit(10))),
((-1:1, 101:110), (UserUnit(110), UserUnit(1))))
set_coordinates(c, coords)
@test all(GtkReactive.convertunits(UserUnit, c, corner_dev...) .≈ corner_usr)
@test GtkReactive.convertunits(UserUnit, c, corner_dev...) == corner_usr
@test GtkReactive.convertunits(DeviceUnit, c, corner_dev...) == corner_dev
@test GtkReactive.convertunits(UserUnit, c, corner_usr...) == corner_usr
@test GtkReactive.convertunits(DeviceUnit, c, corner_usr...) == corner_dev
Expand Down

0 comments on commit 0798153

Please sign in to comment.