pub struct BHQuadtree { /* private fields */ }
Expand description
A Quadtree specially optimized for the Barnes-Hut algorithm
An interactive explanation of the algorithm can be found here
This quadtree is immutable and flat, not recursive. It is optimized to be rebuilt frequently
and supports efficient accumulation of approximated force. Each step, convert your items into
WeightedPoint
and call the build method to clear and reconstruct the tree. Then for each
item you need to accumulate force on, call the accumulate method, passing a custom force
function.
This implementation is heavily inspired by DeadlockCode’s Barnes-Hut implementation
Implementations§
Source§impl BHQuadtree
impl BHQuadtree
Sourcepub fn build(&mut self, items: Vec<WeightedPoint>, node_capacity: usize)
pub fn build(&mut self, items: Vec<WeightedPoint>, node_capacity: usize)
Clear all internal data and reconstruct the tree from a sequence of weighted points
Sourcepub fn accumulate<F: Fn(WeightedPoint) -> Vec2>(
&self,
target: Vec2,
force_fn: F,
) -> Vec2
pub fn accumulate<F: Fn(WeightedPoint) -> Vec2>( &self, target: Vec2, force_fn: F, ) -> Vec2
Accumulate a force vector to act on a target position with an arbitrary force function, approximating weighted points based on the theta parameter.