Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Perform unit conversions manually from cairomatrix" #78

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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