Skip to content

Commit

Permalink
removed julia-0.7 depwarns, testing loads from JLD2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristof Cools committed Jul 18, 2018
1 parent 3f428bb commit e72010a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ os:
- linux
- osx
julia:
- 0.5
- nightly
- 0.7
#- nightly
notifications:
email: false
# uncomment the following lines to override the default test script
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.5
julia 0.7
Compat 0.18
23 changes: 11 additions & 12 deletions src/octree.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

type Box
mutable struct Box
data::Vector{Int}
children::Vector{Box}
end
Expand All @@ -10,7 +10,7 @@ Box() = Box(Int[], Box[])
T: type of the coordinates
P: type of the points stored in the Octree.
"""
type Octree{T,P}
mutable struct Octree{T,P}
center::P
halfsize::T
rootbox::Box
Expand All @@ -29,7 +29,7 @@ end
Compute the bounding cube/square for a Array of Point. The return values
are the center of the bounding box and the half size of the cube.
"""
function boundingbox{P}(v::Vector{P})
function boundingbox(v::Vector{P}) where {P}
#P are points values (x,y) in 2D or (x,y,z) in 3D
ll = minimum(v)
ur = maximum(v)
Expand Down Expand Up @@ -68,26 +68,26 @@ function boxesoverlap(c1, hs1, c2, hs2)
return true
end

function Octree{T}(points::Vector, radii::Vector{T}, expanding_ratio=1.0, splitcount = 10, minhalfsize = zero(T))
function Octree(points::Vector, radii::Vector{T}, expanding_ratio=1.0, splitcount = 10, minhalfsize = zero(T)) where {T}

n_points = length(points)
n_dims = length(eltype(points))

# compute the bounding box taking into account
# the radius of the objects to be inserted
radius = maximum(radii)

@assert !isempty(points)
ll = points[1]
ur = points[1]
for i in 2:length(points)
ll = min.(ll, points[i])
ur = max.(ur, points[i])
end

ll = ll .- radius
ur = ur .+ radius

#ll = minimum(points) - radius
#ur = maximum(points) + radius

Expand Down Expand Up @@ -122,7 +122,6 @@ end
Insert zero radius objects at positions `points` in an Octree
"""

Octree(points) = Octree(points, zeros(eltype(eltype(points)), length(points)))


Expand Down Expand Up @@ -223,7 +222,7 @@ point: the point at which to insert
radius: the radius of the item to insert
id: a unique id that identifies the inserted item uniquely
"""
function insert!{P,T}(tree, box, center::P, halfsize::T, point::P, radius::T, id)
function insert!(tree, box, center::P, halfsize::T, point::P, radius::T, id) where {T,P}

# if not saturated: insert here
# if saturated and not internal : create children and redistribute
Expand Down Expand Up @@ -279,7 +278,7 @@ function insert!{P,T}(tree, box, center::P, halfsize::T, point::P, radius::T, id
end

# Create an array of childboxes
box.children = Array{Box}(nch)
box.children = Array{Box}(undef,nch)
for i in 1:nch
box.children[i] = Box(Int[], Box[])
end
Expand Down Expand Up @@ -381,12 +380,12 @@ function length(tree::Octree)
end


type BoxIterator{T,P,F}
mutable struct BoxIterator{T,P,F}
predicate::F
tree::Octree{T,P}
end

type BoxIteratorStage{T,P}
mutable struct BoxIteratorStage{T,P}
box::Box
sct::Int
center::P
Expand Down
2 changes: 1 addition & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
StaticArrays 0.3.0
JLD 0.6.3
JLD2 0.0.6
Binary file added test/assets/back.jld2
Binary file not shown.
Binary file added test/assets/front.jld2
Binary file not shown.
Binary file added test/center_sizes.jld2
Binary file not shown.
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using StaticArrays

module MyPkgTests

using Base.Test
using LinearAlgebra
using Test
using StaticArrays
using JLD2
import CollisionDetection

include("test_core.jl")
Expand Down
44 changes: 25 additions & 19 deletions test/test_core.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CollisionDetection
using StaticArrays
using Base.Test
using JLD
#using Test
#using StaticArrays
#using CollisionDetection
#using JLD2
CD = CollisionDetection

@test CD.childsector([1,1,1],[0,0,0]) == 7
Expand All @@ -25,21 +25,21 @@ tree = CD.Octree(data, radii)
println("Testing allways true iterator")
sz = 0
for box in CD.boxes(tree)
sz += length(box)
global sz += length(box)
end
@test sz == n

println("Testing allways false iterator")
sz = 0
for box in CD.boxes(tree, (c,s)->false)
sz += length(box.data)
global sz += length(box.data)
end
@test sz == 0

println("Testing query for box in sector [7,0]")
sz = 0
for box in CD.boxes(tree, (c,s)->CD.fitsinbox([1,1,1]/8,0,c,s))
sz += length(box)
global sz += length(box)
end
@show sz

Expand All @@ -53,46 +53,52 @@ tree = CD.Octree(data, radii)
println("Testing allways true iterator [2D]")
sz = 0
for box in CD.boxes(tree)
sz += length(box)
global sz += length(box)
end
@test sz == n

println("Testing allways false iterator [2D]")
sz = 0
for box in CD.boxes(tree, (c,s)->false)
sz += length(box.data)
global sz += length(box.data)
end
@test sz == 0

println("Testing query for box in sector [7,0], [2D]")
sz = 0
for box in CD.boxes(tree, (c,s)->CD.fitsinbox([1,1]/8,0,c,s))
sz += length(box)
global sz += length(box)
end
@show sz


## Test the case of degenerate bounding boxes
fn = joinpath(dirname(@__FILE__),"assets","front.jld")
V,F = jldopen(fn,"r") do file
read(file, "V"), read(file, "F")
fn = joinpath(dirname(@__FILE__),"assets","back.jld2")
jldopen(fn,"r") do file
global U = file["V"]
global G = file["F"]
#read(file, "V"), read(file, "F")
end

fn = joinpath(dirname(@__FILE__),"assets","back.jld")
U,G = jldopen(fn,"r") do file
read(file, "V"), read(file, "F")
fn = joinpath(dirname(@__FILE__),"assets","front.jld2")
jldopen(fn,"r") do file
global V = file["V"]
global F = file["F"]
#read(file, "V"), read(file, "F")
end

@assert eltype(V) <: SVector

radii = zeros(length(V))
tree = Octree(V, radii)
tree = CD.Octree(V, radii)

tree_ctr, tree_hs = tree.center, tree.halfsize

u = U[3]
atol = sqrt(eps())
@test norm(u-V[4]) < atol
pred(c,s) = fitsinbox(Array(u), 0.0, c, s+atol)
pred(c,s) = CD.fitsinbox(Array(u), 0.0, c, s+atol)
@test pred(tree_ctr, tree_hs)
it = boxes(tree, pred)
it = CD.boxes(tree, pred)
st = start(it)
@test !done(it, st)
32 changes: 9 additions & 23 deletions test/test_searcheq.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
using CollisionDetection
using StaticArrays
using JLD
using Base.Test
#using CollisionDetection
#using StaticArrays
#using JLD2
#using Test

fn = normpath(joinpath(dirname(@__FILE__),"center_sizes.jld"))
d = load(fn)
fn = normpath(joinpath(dirname(@__FILE__),"center_sizes.jld2"))
d = JLD2.jldopen(fn,"r")

tmp = d["ctrs"]
ctrs = [SVector(q...) for q in tmp]
rads = d["rads"]

tree = Octree(ctrs, rads)
tree = CD.Octree(ctrs, rads)

# extract all the triangles that (potentially) intersect octant (+,+,+)
pred(i) = all(ctrs[i].+rads[i] .> 0)
bb = SVector(0.5, 0.5, 0.5), 0.5
ids = collect(searchtree(pred, tree, bb))
@test length(ids) == 154

# using MATLAB
# A = [c[i] for i in 1:3, c in ctrs].'
# @mput A rads
# @matlab begin
# plot3(A[:,1],A[:,2],A[:,3],".")
# end
#
# B = [ctrs[j][i] for i in 1:3, j in ids].'
# @mput B
# @matlab begin
# hold("on")
# plot3(B[:,1],B[:,2],B[:,3],"or")
# end
ids = collect(CD.searchtree(pred, tree, bb))
@test length(ids) == 178
23 changes: 13 additions & 10 deletions test/test_searcheq_gen.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using CollisionDetection
using CompScienceMeshes
using JLD
# using CollisionDetection
# using CompScienceMeshes
# using JLD2

m = meshsphere(1.0, 0.2)
@show numcells(m)

centroid(ch) = cartesian(meshpoint(ch, [1,1]/3))
#centroid(ch) = cartesian(meshpoint(ch, [1,1]/3))

ctrs = [centroid(simplex(cellvertices(m,i))) for i in 1:numcells(m)]
rads = [maximum(norm(v-ctrs[i]) for v in cellvertices(m,i)) for i in eachindex(ctrs)]
#ctrs = [centroid(simplex(cellvertices(m,i))) for i in 1:numcells(m)]
ctrs = cartesian.(center.(chart.(m,cells(m))))
#rads = [maximum(norm(v-ctrs[i]) for v in cellvertices(m,i)) for i in eachindex(ctrs)]
rads = [maximum(norm(v-ctrs[i]) for v in vertices(m,c)) for (i,c) in enumerate(cells(m))];
tree = Octree(ctrs, rads)

fn = joinpath(@__FILE__,"..","center_sizes.jld")
save(fn,
"ctrs", ctrs,
"rads", rads)
fn = joinpath(@__FILE__,"..","center_sizes.jld2")
JLD2.@save fn ctrs rads
# save(fn,
# "ctrs", ctrs,
# "rads", rads)

0 comments on commit e72010a

Please sign in to comment.