Skip to content

Commit

Permalink
fix issue #3, grid crossings outside of grid
Browse files Browse the repository at this point in the history
  • Loading branch information
WilCrofter committed Jan 30, 2016
1 parent dc53830 commit b1f43db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/GenS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ function gridCrossings(u::Array{Float64,1}, v::Array{Float64,1}, width::Int, hei
else
return Array(Float64,0,2)
end
crossings = hcat(u[1] + lambda[idx]*(v[1]-u[1]),
u[2] + lambda[idx]*(v[2]-u[2]));
return crossings
cx = u[1] + lambda[idx]*(v[1]-u[1]);
cy = u[2] + lambda[idx]*(v[2]-u[2]);
idx = (0.0 .<= cx .<= kx[end]) & (0.0 .<= cy .<= ky[end]);
return hcat(cx[idx,:],cy[idx,:]);
end

"""
Expand All @@ -68,7 +69,7 @@ function segmentLengths(u::Array{Float64,1}, v::Array{Float64,1}, width::Int, he
return 1+floor(Int, (crossings[1:(n-1),:]+crossings[2:n,:])/(2*gridsize)), # indices
sqrt((crossings[2:n,:]-crossings[1:(n-1),:]).^2 * vcat(1,1)); # lengths
else
return Array(int,0,2), Array(Float64,0,1);
return Array(Int,0,2), Array(Float64,0,1);
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/TestGenS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ function testCellIO(filepath::AbstractString)
test_rwSData(filepath);
end

include("issue3.jl")

function test_all()
vcat(test_wCrossings(), test_gridCrossings(), test_segmentLengths(),
test_probePos(), test_rwSData(), test_genS(128));
test_probePos(), test_rwSData(), test_genS(128), issue3());
end

end
Expand Down
14 changes: 14 additions & 0 deletions test/issue3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

function issue3()
r2 = Float64[-.1 8.1; -.1 -0.1; 8.1 -0.1; 8.1 8.1]
grid = 0.5
width = height = 8;
xmitr,rcvr = probePos(8,r2)
data = genS(width,height,grid,xmitr,rcvr)
for (j in 1:height)
for (i in 1:width)
Base.Test.@test all(1 .<= data[i,j][1] .<= 8)
end #i
end #j
Any["All crossings inside grid" true];
end #function
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ using GenS
using Base.Test
include("TestGenS.jl")

# write your own tests here
info(TestGenS.test_all())

0 comments on commit b1f43db

Please sign in to comment.