Repository: bevyengine/bevy
File: crates/bevy_input_focus/src/directional_navigation.rs (Rust)

Code before:
                };
                if entities.contains(entity) {
                    *neighbor = NavNeighbor::Unset;
                }
            }
        }
    }

    /// Completely clears the navigation map, removing all entities and connections.
    pub fn clear(&mut self) {
        self.neighbors.clear();
    }

    /// Adds an edge between two entities in the navigation map.
    /// Any existing edge from A in the provided direction will be overwritten.
    ///
    /// The reverse edge will not be added, so navigation will only be possible in one direction.
    /// If you want to add a symmetrical edge, use [`add_symmetrical_edge`](Self::add_symmetrical_edge) instead.
    pub fn add_edge(&mut self, a: Entity, b: Entity, direction: CompassOctant) {
        self.neighbors
            .entry(a)
            .or_insert(NavNeighbors::EMPTY)
            .set(direction, b);
    }

    /// Adds an edge blocking automatic naviation from an entity in a direction.
    /// Any existing edge from A in the provided direction will be overwritten.
    ///
    /// The reverse block will not be added, so navigation will only be possible from other entities
    /// in the direction.
    /// If you want to add a symmetrical block, use [`block_symmetrical_edge`](Self::block_symmetrical_edge) instead.
    ///
    /// Note that blocking a primary cardinal direction will not block intermediates.
    /// In other words, blocking `North` will still allow navigation towards `NorthEast`.
    pub fn block_edge(&mut self, a: Entity, direction: CompassOctant) {
        self.neighbors
            .entry(a)
            .or_insert(NavNeighbors::EMPTY)
            .block(direction);
    }

    /// Adds a symmetrical edge between two entities in the navigation map.
    /// The A -> B path will use the provided direction, while B -> A will use the [`CompassOctant::opposite`] variant.
    ///
    /// Any existing connections between the two entities will be overwritten.
    pub fn add_symmetrical_edge(&mut self, a: Entity, b: Entity, direction: CompassOctant) {
        self.add_edge(a, b, direction);
        self.add_edge(b, a, direction.opposite());
    }

    // TODO: not quite sure if this is necessary

Review comment (suggestion):
```suggestion
    /// Adds an edge blocking automatic navigation from an entity in a direction.
```

Code after:
                };
                if entities.contains(entity) {
                    *neighbor = NavNeighbor::Auto;
                }
            }
        }
    }

    /// Completely clears the navigation map, removing all entities and connections.
    pub fn clear(&mut self) {
        self.neighbors.clear();
    }

    /// Adds an edge between two entities in the navigation map.
    /// Any existing edge from A in the provided direction will be overwritten.
    ///
    /// The reverse edge will not be added, so navigation will only be possible in one direction.
    /// If you want to add a symmetrical edge, use [`add_symmetrical_edge`](Self::add_symmetrical_edge) instead.
    pub fn add_edge(&mut self, a: Entity, b: Entity, direction: CompassOctant) {
        self.neighbors
            .entry(a)
            .or_insert(NavNeighbors::EMPTY)
            .set(direction, b);
    }

    /// Adds an edge blocking automatic navigation from an entity in a direction.
    /// Any existing edge from A in the provided direction will be overwritten.
    ///
    /// The reverse block will not be added, so navigation will still be possible from other entities
    /// in the direction.
    /// If you want to add a symmetrical block, use [`block_symmetrical_edge`](Self::block_symmetrical_edge) instead.
    ///
    /// Note that blocking a primary cardinal direction will not block intermediates.
    /// In other words, blocking `North` will still allow navigation towards `NorthEast`.
    pub fn block_edge(&mut self, a: Entity, direction: CompassOctant) {
        self.neighbors
            .entry(a)
            .or_insert(NavNeighbors::EMPTY)
            .block(direction);
    }

    /// Adds a symmetrical edge between two entities in the navigation map.
    /// The A -> B path will use the provided direction, while B -> A will use the [`CompassOctant::opposite`] variant.
    ///
    /// Any existing connections between the two entities will be overwritten.
    pub fn add_symmetrical_edge(&mut self, a: Entity, b: Entity, direction: CompassOctant) {
        self.add_edge(a, b, direction);
        self.add_edge(b, a, direction.opposite());
    }

    /// Adds a symmetrical blocking edge between two entities in the navigation map.