Skip to content

Commit

Permalink
Add and subtract for XY; < and > for CairoUnit (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswanson33 authored and timholy committed Aug 9, 2017
1 parent 7f122fe commit ef10f00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/graphics_interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using Gtk.GConstants.GdkEventMask: KEY_PRESS, SCROLL

Base.:+{U<:CairoUnit}(x::U, y::U) = U(x.val + y.val)
Base.:-{U<:CairoUnit}(x::U, y::U) = U(x.val - y.val)
Base.:<{U<:CairoUnit}(x::U, y::U) = Bool(x.val < y.val)
Base.:>{U<:CairoUnit}(x::U, y::U) = Bool(x.val > y.val)
Base.abs{U<:CairoUnit}(x::U) = U(abs(x.val))
Base.min{U<:CairoUnit}(x::U, y::U) = U(min(x.val, y.val))
Base.max{U<:CairoUnit}(x::U, y::U) = U(max(x.val, y.val))
Expand Down Expand Up @@ -100,6 +102,9 @@ Base.show(io::IO, xy::XY) = print(io, "XY(", xy.x, ", ", xy.y, ')')
Base.convert{T}(::Type{XY{T}}, xy::XY{T}) = xy
Base.convert{T}(::Type{XY{T}}, xy::XY) = XY(T(xy.x), T(xy.y))

Base.:+{T}(xy1::XY{T}, xy2::XY{T}) = XY{T}(xy1.x+xy2.x,xy1.y+xy2.y)
Base.:-{T}(xy1::XY{T}, xy2::XY{T}) = XY{T}(xy1.x-xy2.x,xy1.y-xy2.y)

"""
MouseButton(position, button, clicktype, modifiers)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ end
@test x+x === UserUnit(0.2+0.2)
@test x-x === UserUnit(0.0)
y = UserUnit(-0.3)
@test x > y
@test y < x
@test abs(x) === x
@test abs(y) === UserUnit(0.3)
@test min(x, y) === y
Expand All @@ -249,6 +251,8 @@ end
@test XY(5, 5) === XY{Int}(5, 5)
@test XY(5, 5.0) === XY{Float64}(5.0, 5.0)
@test XY{UserUnit}(5, 5.0) === XY{UserUnit}(5.0, 5.0) === XY{UserUnit}(UserUnit(5), UserUnit(5))
@test XY(5.0, 5)+XY(4, 4.1) === XY(9, 9.1)
@test XY(5, 5)-XY(4, 4) === XY(1, 1)

@test isa(MouseButton{UserUnit}(), MouseButton{UserUnit})
@test isa(MouseButton{DeviceUnit}(), MouseButton{DeviceUnit})
Expand Down

0 comments on commit ef10f00

Please sign in to comment.