Skip to content

Commit

Permalink
lifted state update from while loop for leveltrees
Browse files Browse the repository at this point in the history
  • Loading branch information
krcools committed Feb 8, 2024
1 parent df3b0ec commit cbfe29e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Manifest.toml
*.jl.mem
docs/build/
docs/site
Manifest.toml
.vscode/
dev/
29 changes: 0 additions & 29 deletions examples/Manifest.toml

This file was deleted.

3 changes: 3 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[deps]
ClusterTrees = "5100927d-02aa-593a-b4f9-7235df19f0db"
CompScienceMeshes = "3e66a162-7b8c-5da0-b8f8-124ecd2c3ae1"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2 changes: 1 addition & 1 deletion examples/lvltree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const P = SVector{3,Float64}
mesh = meshsphere(1.0, 0.04)
# points = [rand(P) for i in 1:800]
points = vertices(mesh)
points = [cartesian(CompScienceMeshes.center(chart(mesh, c))) for c in cells(mesh)]
points = [cartesian(CompScienceMeshes.center(chart(mesh, c))) for c in mesh]

root_center = P(0,0,0)
root_size = 1.0
Expand Down
36 changes: 28 additions & 8 deletions examples/pbtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,48 @@ end

import ClusterTrees: start, next, done

# function ClusterTrees.route!(tree::ClusterTrees.PointerBasedTrees.PointerBasedTree, state, target)

# (parent, prev_fat_par, meta) = state
# reached(tree, target, meta) && return state

# meta = directions(tree, target, meta)
# prev_fat_child = prev_fat_par < 1 ? 0 : lastnonemptychild(tree, prev_fat_par)

# chds = children(tree, parent)
# pos = start(chds)
# while !done(chds, pos)
# child, newpos = next(chds, pos)
# isontherighttrack(tree, child, meta) && return (child, prev_fat_child, meta)
# ClusterTrees.haschildren(tree, child) && (prev_fat_child = child)
# pos = newpos
# end

# sector, center, size = meta
# child = insert!(chds, Data(sector), pos)

# return child, prev_fat_child, meta
# end


function ClusterTrees.route!(tree::ClusterTrees.PointerBasedTrees.PointerBasedTree, state, target)

(parent, prev_fat_par, meta) = state
(parent, meta) = state
reached(tree, target, meta) && return state

meta = directions(tree, target, meta)
prev_fat_child = prev_fat_par < 1 ? 0 : lastnonemptychild(tree, prev_fat_par)

chds = children(tree, parent)
pos = start(chds)
while !done(chds, pos)
child, newpos = next(chds, pos)
isontherighttrack(tree, child, meta) && return (child, prev_fat_child, meta)
ClusterTrees.haschildren(tree, child) && (prev_fat_child = child)
isontherighttrack(tree, child, meta) && return (child, meta)
pos = newpos
end

sector, center, size = meta
child = insert!(chds, Data(sector), pos)

return child, prev_fat_child, meta
return child, meta
end

const N = ClusterTrees.PointerBasedTrees.Node{Data}
Expand All @@ -96,10 +117,9 @@ tree = ClusterTrees.PointerBasedTrees.PointerBasedTree(

function update!(f, tree::ClusterTrees.PointerBasedTrees.PointerBasedTree, i::Int, point, sms::Float64)
router! = Router(point, sms)
prev_fat_child = 0
root_sector, root_center, root_size = 0, SVector{3,Float64}(0,0,0), 1.0
root_meta = root_sector, root_center, root_size
root_state = (root(tree), prev_fat_child, root_meta)
root_state = (root(tree), root_meta)
ClusterTrees.update!(f, tree, root_state, i, router!)
end

Expand Down
2 changes: 1 addition & 1 deletion src/leveltree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function ClusterTrees.route!(tree::LevelledTree, state, destination)
# Compute new state
target_sector, target_center, target_size = sector_center_size(point, center, size)
target_sfc_state = hilbert_states[sfc_state][sector+1] + 1
target_pos = hilbert_positions[target_sfc_state][target_sector+1] + 1

chds = ClusterTrees.children(tree, node_idx)
pos = start(chds)
Expand All @@ -177,7 +178,6 @@ function ClusterTrees.route!(tree::LevelledTree, state, destination)

# Did we move past where the destination can be found? It so, give up!
child_sector = ClusterTrees.data(tree,child).sector
target_pos = hilbert_positions[target_sfc_state][target_sector+1] + 1
child_pos = hilbert_positions[target_sfc_state][child_sector+1]+1
target_pos < child_pos && break

Expand Down

0 comments on commit cbfe29e

Please sign in to comment.