Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] committed Aug 17, 2017
1 parent 56da33a commit aa61cb3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/circle2d.jl
@@ -1,9 +1,9 @@
#CirclePointRadius methods

CirclePointRadius{T<:Real}(x::Int, y::Int, ρ::T) = CirclePointRadius(Point(x,y), ρ)
CirclePointRadius{T<:Real}(p::CartesianIndex{2}, ρ::T) = CirclePointRadius(Point(p), ρ)
CirclePointRadius(x::Int, y::Int, ρ::T) where {T<:Real} = CirclePointRadius(Point(x,y), ρ)
CirclePointRadius(p::CartesianIndex{2}, ρ::T) where {T<:Real} = CirclePointRadius(Point(p), ρ)

draw!{T<:Colorant}(img::AbstractArray{T, 2}, circle::CirclePointRadius, color::T) = draw!(img, Ellipse(circle), color)
draw!(img::AbstractArray{T, 2}, circle::CirclePointRadius, color::T) where {T<:Colorant} = draw!(img, Ellipse(circle), color)

#CircleThreePoints methods

Expand All @@ -12,7 +12,7 @@ CircleThreePoints(x1::Int, y1::Int, x2::Int, y2::Int, x3::Int, y3::Int) =
CircleThreePoints(p1::CartesianIndex{2}, p2::CartesianIndex{2}, p3::CartesianIndex{2}) =
CircleThreePoints(Point(p1), Point(p2), Point(p3))

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, circle::CircleThreePoints, color::T)
function draw!(img::AbstractArray{T, 2}, circle::CircleThreePoints, color::T) where T<:Colorant
ind = indices(img)
x1 = circle.p1.x; y1 = circle.p1.y
x2 = circle.p2.x; y2 = circle.p2.y
Expand Down
36 changes: 18 additions & 18 deletions src/core.jl
@@ -1,21 +1,21 @@
"""
Type representing any object drawable on image
"""
@compat abstract type Drawable end
abstract type Drawable end

"""
p = Point(x,y)
p = Point(c)
A `Drawable` point on the image
"""
immutable Point <: Drawable
struct Point <: Drawable
x::Int
y::Int
end

@compat abstract type Line <: Drawable end
@compat abstract type Circle <: Drawable end
abstract type Line <: Drawable end
abstract type Circle <: Drawable end


"""
Expand All @@ -24,7 +24,7 @@ end
A `Drawable` infinite length line passing through the two points
`p1` and `p2`.
"""
immutable LineTwoPoints <: Line
struct LineTwoPoints <: Line
p1::Point
p2::Point
end
Expand All @@ -36,7 +36,7 @@ A `Drawable` infinte length line having perpendicular length `ρ` from
origin and angle `θ` between the perpendicular and x-axis
"""
immutable LineNormal{T<:Real, U<:Real} <: Line
struct LineNormal{T<:Real, U<:Real} <: Line
ρ::T
θ::U
end
Expand All @@ -46,7 +46,7 @@ end
A `Drawable` circle passing through points `p1`, `p2` and `p3`
"""
immutable CircleThreePoints <: Circle
struct CircleThreePoints <: Circle
p1::Point
p2::Point
p3::Point
Expand All @@ -57,7 +57,7 @@ end
A `Drawable` circle having center `center` and radius `ρ`
"""
immutable CirclePointRadius{T<:Real} <: Circle
struct CirclePointRadius{T<:Real} <: Circle
center::Point
ρ::T
end
Expand All @@ -67,7 +67,7 @@ end
A `Drawable` finite length line between `p1` and `p2`
"""
immutable LineSegment <: Drawable
struct LineSegment <: Drawable
p1::Point
p2::Point
end
Expand All @@ -80,7 +80,7 @@ of points in `[point]`.
!!! note
This will create a non-closed path. For a closed path, see `Polygon`
"""
immutable Path <: Drawable
struct Path <: Drawable
vertices::Vector{Point}
end

Expand All @@ -90,7 +90,7 @@ end
A `Drawable` ellipse with center `center` and parameters `ρx` and `ρy`
"""
immutable Ellipse{T<:Real, U<:Real} <: Drawable
struct Ellipse{T<:Real, U<:Real} <: Drawable
center::Point
ρx::T
ρy::U
Expand All @@ -104,7 +104,7 @@ consecutive points in `[vertex]` along with the first and last point.
!!! note
This will create a closed path. For a non-closed path, see `Path`
"""
immutable Polygon <: Drawable
struct Polygon <: Drawable
vertices::Vector{Point}
end

Expand All @@ -120,7 +120,7 @@ A `Drawable` regular polygon.
* `θ::Real` : orientation of the polygon w.r.t x-axis (in radians)
"""
immutable RegularPolygon{T<:Real, U<:Real} <: Drawable
struct RegularPolygon{T<:Real, U<:Real} <: Drawable
center::Point
side_count::Int
side_length::T
Expand All @@ -134,7 +134,7 @@ end
Draws `drawable` on `img` using color `color` which
defaults to `one(eltype(img))`
"""
draw!{T<:Colorant}(img::AbstractArray{T,2}, object::Drawable) = draw!(img, object, one(T))
draw!(img::AbstractArray{T,2}, object::Drawable) where {T<:Colorant} = draw!(img, object, one(T))


"""
Expand All @@ -147,7 +147,7 @@ corresponding colors from `[color]` which defaults to `one(eltype(img))`
If only a single color `color` is specified then all objects will be
colored with that color.
"""
function draw!{T<:Colorant, U<:Drawable, V<:Colorant}(img::AbstractArray{T,2}, objects::AbstractVector{U}, colors::AbstractVector{V})
function draw!(img::AbstractArray{T,2}, objects::AbstractVector{U}, colors::AbstractVector{V}) where {T<:Colorant, U<:Drawable, V<:Colorant}
colors = copy(colors)
while length(colors) < length(objects)
push!(colors, one(T))
Expand All @@ -156,7 +156,7 @@ function draw!{T<:Colorant, U<:Drawable, V<:Colorant}(img::AbstractArray{T,2}, o
img
end

draw!{T<:Colorant, U<:Drawable}(img::AbstractArray{T,2}, objects::AbstractVector{U}, color::T = one(T)) =
draw!(img::AbstractArray{T,2}, objects::AbstractVector{U}, color::T = one(T)) where {T<:Colorant, U<:Drawable} =
draw!(img, objects, [color for i in 1:length(objects)])

"""
Expand All @@ -167,12 +167,12 @@ Draws the `drawable` object on a copy of image `img` using color
`color`. Can also draw multiple `Drawable` objects when passed
as a `AbstractVector{Drawable}` with corresponding colors in `[color]`
"""
draw{T<:Colorant}(img::AbstractArray{T,2}, args...) = draw!(copy(img), args...)
draw(img::AbstractArray{T,2}, args...) where {T<:Colorant} = draw!(copy(img), args...)

Point::Tuple{Int, Int}) = Point...)
Point(p::CartesianIndex) = Point(p[2], p[1])

function draw!{T<:Colorant}(img::AbstractArray{T,2}, point::Point, color::T)
function draw!(img::AbstractArray{T,2}, point::Point, color::T) where T<:Colorant
if checkbounds(Bool, img, point.y, point.x)
img[point.y, point.x] = color
end
Expand Down
6 changes: 3 additions & 3 deletions src/ellipse2d.jl
@@ -1,10 +1,10 @@
#Ellipse methods

Ellipse{T<:Real, U<:Real}(x::Int, y::Int, ρx::T, ρy::U) = Ellipse(Point(x,y), ρx, ρy)
Ellipse{T<:Real, U<:Real}(p::CartesianIndex{2}, ρx::T, ρy::U) = Ellipse(Point(p), ρx, ρy)
Ellipse(x::Int, y::Int, ρx::T, ρy::U) where {T<:Real, U<:Real} = Ellipse(Point(x,y), ρx, ρy)
Ellipse(p::CartesianIndex{2}, ρx::T, ρy::U) where {T<:Real, U<:Real} = Ellipse(Point(p), ρx, ρy)
Ellipse(circle::CirclePointRadius) = Ellipse(circle.center, circle.ρ, circle.ρ)

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, ellipse::Ellipse, color::T)
function draw!(img::AbstractArray{T, 2}, ellipse::Ellipse, color::T) where T<:Colorant
ys = Int[]
xs = Int[]
for i in ellipse.center.y : ellipse.center.y + ellipse.ρy
Expand Down
24 changes: 12 additions & 12 deletions src/line2d.jl
@@ -1,7 +1,7 @@

#Function to return valid intersections of lines with image boundary

function get_valid_intersections{T<:Real, U<:Real}(intersections::Vector{Tuple{T,U}}, indsx::AbstractUnitRange, indsy::AbstractUnitRange)
function get_valid_intersections(intersections::Vector{Tuple{T,U}}, indsx::AbstractUnitRange, indsy::AbstractUnitRange) where {T<:Real, U<:Real}
valid_intersections = Vector{Tuple{T,U}}(0)
for intersection in intersections
if first(indsx) <= intersection[1] <= last(indsx) && first(indsy) <= intersection[2] <= last(indsy)
Expand All @@ -16,10 +16,10 @@ end
LineTwoPoints(x0::Int, y0::Int, x1::Int, y1::Int) = LineTwoPoints(Point(x0, y0), Point(x1,y1))
LineTwoPoints(p1::CartesianIndex{2}, p2::CartesianIndex{2}) = LineTwoPoints(Point(p1), Point(p2))

draw!{T<:Colorant}(img::AbstractArray{T,2}, line::LineTwoPoints, method::Function = bresenham) =
draw!(img::AbstractArray{T,2}, line::LineTwoPoints, method::Function = bresenham) where {T<:Colorant} =
draw!(img, line, one(T), method)

function draw!{T<:Colorant}(img::AbstractArray{T,2}, line::LineTwoPoints, color::T, method::Function = bresenham)
function draw!(img::AbstractArray{T,2}, line::LineTwoPoints, color::T, method::Function = bresenham) where T<:Colorant
indsy, indsx = indices(img)
x1 = line.p1.x; y1 = line.p1.y
x2 = line.p2.x; y2 = line.p2.y
Expand All @@ -37,12 +37,12 @@ end

# LineNormal methods

LineNormal{T<:Real, U<:Real}::Tuple{T,U}) = LineNormal...)
LineNormal::Tuple{T,U}) where {T<:Real, U<:Real} = LineNormal...)

draw!{T<:Colorant}(img::AbstractArray{T,2}, line::LineNormal, method::Function = bresenham) =
draw!(img::AbstractArray{T,2}, line::LineNormal, method::Function = bresenham) where {T<:Colorant} =
draw!(img, line, one(T), method)

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, line::LineNormal, color::T, method::Function = bresenham)
function draw!(img::AbstractArray{T, 2}, line::LineNormal, color::T, method::Function = bresenham) where T<:Colorant
indsy, indsx = indices(img)
cosθ = cos(line.θ)
sinθ = sin(line.θ)
Expand All @@ -61,15 +61,15 @@ end
LineSegment(x0::Int, y0::Int, x1::Int, y1::Int) = LineSegment(Point(x0, y0), Point(x1,y1))
LineSegment(p1::CartesianIndex, p2::CartesianIndex) = LineSegment(Point(p1), Point(p2))

draw!{T<:Colorant}(img::AbstractArray{T,2}, line::LineSegment, method::Function = bresenham) =
draw!(img::AbstractArray{T,2}, line::LineSegment, method::Function = bresenham) where {T<:Colorant} =
draw!(img, line, one(T), method)

draw!{T<:Colorant}(img::AbstractArray{T,2}, line::LineSegment, color::T, method::Function = bresenham) =
draw!(img::AbstractArray{T,2}, line::LineSegment, color::T, method::Function = bresenham) where {T<:Colorant} =
method(img, line.p1.y, line.p1.x, line.p2.y, line.p2.x, color)

# Methods to draw lines

function bresenham{T<:Colorant}(img::AbstractArray{T, 2}, y0::Int, x0::Int, y1::Int, x1::Int, color::T)
function bresenham(img::AbstractArray{T, 2}, y0::Int, x0::Int, y1::Int, x1::Int, color::T) where T<:Colorant
dx = abs(x1 - x0)
dy = abs(y1 - y0)

Expand All @@ -95,14 +95,14 @@ function bresenham{T<:Colorant}(img::AbstractArray{T, 2}, y0::Int, x0::Int, y1::
img
end

fpart{T}(pixel::T) = pixel - T(trunc(pixel))
rfpart{T}(pixel::T) = one(T) - fpart(pixel)
fpart(pixel::T) where {T} = pixel - T(trunc(pixel))
rfpart(pixel::T) where {T} = one(T) - fpart(pixel)

function swap(x, y)
y, x
end

function xiaolin_wu{T<:Gray}(img::AbstractArray{T, 2}, y0::Int, x0::Int, y1::Int, x1::Int, color::T)
function xiaolin_wu(img::AbstractArray{T, 2}, y0::Int, x0::Int, y1::Int, x1::Int, color::T) where T<:Gray
dx = x1 - x0
dy = y1 - y0

Expand Down
8 changes: 4 additions & 4 deletions src/paths.jl
Expand Up @@ -3,7 +3,7 @@
Path(v::AbstractVector{Tuple{Int, Int}}) = Path([Point(p...) for p in v])
Path(v::AbstractVector{CartesianIndex{2}}) = Path([Point(p) for p in v])

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, path::Path, color::T)
function draw!(img::AbstractArray{T, 2}, path::Path, color::T) where T<:Colorant
vertices = [CartesianIndex(p.y, p.x) for p in path.vertices]
f = CartesianIndex(map(r->first(r)-1, indices(img)))
l = CartesianIndex(map(r->last(r), indices(img)))
Expand All @@ -28,17 +28,17 @@ end
Polygon(v::AbstractVector{Tuple{Int, Int}}) = Polygon([Point(p...) for p in v])
Polygon(v::AbstractVector{CartesianIndex{2}}) = Polygon([Point(p) for p in v])

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, polygon::Polygon, color::T)
function draw!(img::AbstractArray{T, 2}, polygon::Polygon, color::T) where T<:Colorant
draw!(img, Path(polygon.vertices), color)
draw!(img, LineSegment(first(polygon.vertices), last(polygon.vertices)), color)
end

#RegularPolygon methods

RegularPolygon{T<:Real, U<:Real}(point::CartesianIndex{2}, side_count::Int, side_length::T, θ::U) =
RegularPolygon(point::CartesianIndex{2}, side_count::Int, side_length::T, θ::U) where {T<:Real, U<:Real} =
RegularPolygon(Point(point), side_count, side_length, θ)

function draw!{T<:Colorant}(img::AbstractArray{T, 2}, rp::RegularPolygon, color::T)
function draw!(img::AbstractArray{T, 2}, rp::RegularPolygon, color::T) where T<:Colorant
n = rp.side_count
ρ = rp.side_length/(2*sin/n))
polygon = Polygon([ Point(round(Int, rp.center.x + ρ*cos(rp.θ + 2π*k/n)), round(Int, rp.center.y + ρ*sin(rp.θ + 2π*k/n))) for k in 1:n ])
Expand Down

0 comments on commit aa61cb3

Please sign in to comment.