Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/RegionTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export Cell,
initial_data,
allcells,
allleaves,
allparents,
adaptivesampling!

include("twosarray.jl")
Expand Down
14 changes: 14 additions & 0 deletions src/cell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,17 @@ function allleaves(cell::Cell)
end
end
end

function allparents(cell::Cell)
Channel() do c
queue = [cell]
while !isempty(queue)
current = pop!(queue)
p = parent(current)
if ! (p === nothing)
put!(c, p)
push!(queue, p)
end
end
end
end
21 changes: 21 additions & 0 deletions test/cell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ end
@test findleaf(cell, SVector(-0.01, -0.01, -0.01)) === cell[1,1,1]
@test findleaf(cell, SVector(0.01, -0.01, -0.01)) === cell[2,1,1]
end

@testset "find parents" begin
cell2D = Cell(SVector(0., 0), SVector(1., 1))
split!(cell2D)
split!(cell2D[1,1])
parents2D = [p for p in allparents(cell2D[1,1][1,2])]

@test parents2D[1] === cell2D[1,1]
@test parents2D[2] === cell2D

cell3D = Cell(SVector(-1., -2, -3), SVector(2., 4, 6), 0)
split!(cell3D)
split!(cell3D[2,2,2])
parents3D = [p for p in allparents(cell3D[2,2,2][1,1,1])]

@test parents3D[1] === cell3D[2,2,2]
@test parents3D[2] === cell3D

noparents = [p for p in allparents(cell2D)]
@test length(noparents) == 0
end