ncollide3d/partitioning/
visitor.rs

1/// The status of the spatial partitioning structure traversal.
2pub enum VisitStatus {
3    /// The traversal should continue on the children of the currently visited nodes.
4    Continue,
5    /// The traversal should not be executed on the children of the currently visited nodes.
6    Stop,
7    /// The traversal should exit immediately.
8    ExitEarly,
9}
10
11/// Trait implemented by visitor called during the traversal of a spatial partitioning data structure.
12pub trait Visitor<T, BV> {
13    /// Execute an operation on the content of a node of the spatial partitioning structure.
14    ///
15    /// Returns whether the traversal should continue on the node's children, if it should not continue
16    /// on those children, or if the whole traversal should be exited early.
17    fn visit(&mut self, bv: &BV, data: Option<&T>) -> VisitStatus;
18}
19
20/// Trait implemented by visitor called during a simultaneous spatial partitioning data structure tarversal.
21pub trait SimultaneousVisitor<T, BV> {
22    /// Execute an operation on the content of two nodes, one from each structure.
23    ///
24    /// Returns whether the traversal should continue on the nodes children, if it should not continue
25    /// on those children, or if the whole traversal should be exited early.
26    fn visit(
27        &mut self,
28        left_bv: &BV,
29        left_data: Option<&T>,
30        right_bv: &BV,
31        right_data: Option<&T>,
32    ) -> VisitStatus;
33}
34
35/// The next action to be taken by a BVH traversal algorithm after having visited a node with some data.
36pub enum BestFirstVisitStatus<N, Res> {
37    /// The traversal continues recursively, associating the given cost to the visited node and some associated result.
38    Continue {
39        /// The cost associated to this node.
40        cost: N,
41        /// The result, if any, associated to this cost.
42        result: Option<Res>,
43    },
44    /// The traversal does not continue recursively on the visited node's children.
45    Stop,
46    /// The traversal aborts.
47    ///
48    /// If a data is provided, then it is returned as the result of the traversal.
49    /// If no result is provided, then the last best result found becomes the result of the traversal.
50    ExitEarly(Option<Res>),
51}
52
53/// Trait implemented by cost functions used by the best-first search on a `BVT`.
54pub trait BestFirstVisitor<N, T, BV> {
55    /// The result of a best-first traversal.
56    type Result;
57
58    /// Compute the next action to be taken by the best-first-search after visiting a node containing the given bounding volume.
59    fn visit(
60        &mut self,
61        best_cost_so_far: N,
62        bv: &BV,
63        value: Option<&T>,
64    ) -> BestFirstVisitStatus<N, Self::Result>;
65}