Skip to content

Commit

Permalink
Merge pull request #3 from catawbasam/pull-request/f4858961
Browse files Browse the repository at this point in the history
update Float and Array{T} to load and pass tests with Julia 0.6
  • Loading branch information
rawrgrr committed Sep 14, 2017
2 parents 0b4a720 + f485896 commit 458cf77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Bezier.jl
Expand Up @@ -3,7 +3,7 @@ module Bezier
export bezier

# Linear interpolation between two points
function bezier{T<:FloatingPoint}(t::Real, P1::Array{T}, P2::Array{T})
function bezier{T<:AbstractFloat}(t::Real, P1::Array{T}, P2::Array{T})
if 0 t 1
return P1 + t * (P2 - P1)
else
Expand All @@ -14,12 +14,12 @@ function bezier{T<:FloatingPoint}(t::Real, P1::Array{T}, P2::Array{T})
end

# Higher-order interpolation
function bezier{T<:FloatingPoint}(t::Real, points::Vector{Vector{T}})
function bezier{T<:AbstractFloat}(t::Real, points::Vector{Vector{T}})
dimension = size(points, 1)
if dimension 1
return points
else
interpolated_points = Array(Vector{T}, dimension - 1)
interpolated_points = Array{Vector{T}}(dimension - 1)
for i in 2:dimension
interpolated_points[i - 1] = bezier(t, points[i - 1], points[i])
end
Expand All @@ -28,12 +28,12 @@ function bezier{T<:FloatingPoint}(t::Real, points::Vector{Vector{T}})
end

# Each row of the matrix is a point
function bezier{T<:FloatingPoint}(t::Real, points::Matrix{T})
function bezier{T<:AbstractFloat}(t::Real, points::Matrix{T})
rows, cols = size(points)
if rows 1
return points
else
interpolated_points = Array(T, rows - 1, cols)
interpolated_points = Array{T}(rows - 1, cols)
for r in 2:rows
interpolated_point = bezier(t, points[r - 1, :], points[r, :])
for c in 1:cols
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Expand Up @@ -19,7 +19,7 @@ P22 = [2. 3]
@test [2 3] == bezier(1, P21, P22)

# quadratic interpolation with vector of vectors
@test Array[[10, 5]] == bezier(0.5, Vector{FloatingPoint}[[0., 0], [10, 10], [20, 0]])
@test Array[[10, 5]] == bezier(0.5, Vector{Float64}[[0., 0], [10, 10], [20, 0]])

# quadratic interpolation with matrix
@test [[10 5];] == bezier(0.5, [[0. 0]; [10 10]; [20 0]])
Expand All @@ -28,7 +28,7 @@ P22 = [2. 3]
# boundary checks
@test_throws DomainError bezier(prevfloat(0.), [0., 1], [2., 3])
@test_throws DomainError bezier(nextfloat(1.), [0., 1], [2., 3])
@test_throws DomainError bezier(prevfloat(0.), Vector{FloatingPoint}[[0., 1], [2, 3]])
@test_throws DomainError bezier(nextfloat(1.), Vector{FloatingPoint}[[0., 1], [2, 3]])
@test_throws DomainError bezier(prevfloat(0.), Vector{Float64}[[0., 1], [2, 3]])
@test_throws DomainError bezier(nextfloat(1.), Vector{Float64}[[0., 1], [2, 3]])
@test_throws DomainError bezier(prevfloat(0.), [0. 1; 2 3])
@test_throws DomainError bezier(nextfloat(1.), [0. 1; 2 3])

0 comments on commit 458cf77

Please sign in to comment.