fn insert_at_node(
        &mut self,
        region: Region,
        data: ND,
        index: Index,
    ) -> Result<(), ShapelikeError> {
        // current node under consideration
        let node = &self.nodes[index];

        // If we've reached a node with leaf children, insert here.
        if self.has_child_leaf(index) || !node.has_children() {
            // If we've reached a leaf node, insert this as a leaf of the parent
            // This call is safe as `region` is guaranteed to be contained in the minimum
            // bounding region of this node.
            self._insert(region, data, index);
            return Ok(());
        }

        // Does any child of this node have an MBR containing our input region?
        let mut child_containing_region = None;

        'mbr_search: for (child_index, child_node) in self.child_iter(index) {
            if child_node.get_region().contains_region(&region)? {
                child_containing_region = Some(child_index);
                break 'mbr_search;
            }
        }

        // If we found a child node containing our region, recurse into that node
        if let Some(child_index) = child_containing_region {
            return self.insert_at_node(region, data, child_index);
        }

        // Otherwise there is no child MBR containing our input `region`.  Thus find
        // the bounding box in this node such that enlarging it to contain
        // `minimum_bounding_region` will add the least amount of area.
        if let Some((_, combined_region, child_index)) = self
            .child_iter(index)
            .map(|(child_index, child_node)| {
                let initial_area = child_node.get_region().get_area();
                // TODO: figure out a better error handling path here (perhaps use `filter_map`)
                let combined_region = child_node
                    .get_region()
                    .combine_region(&region)
                    .expect("Failed to combine regions");
                (
                    combined_region.get_area() - initial_area,
                    combined_region,
                    child_index,
                )
            })
            .min_by(|(left_change, _, _), (right_change, _, _)| {
                // TODO: this should be fine, but worth investigating.
                f64::partial_cmp(left_change, right_change).unwrap()
            })
        {
            // Enlarge `child_index`'s bounding box.  This call is safe as `combined_region`
            // is enlarged from the MBR of the child node.
            self.get_node_mut(child_index)
                .set_minimum_bounding_region_unsafe(combined_region);

            // Since the enlarged bounding box now contains our object, recurse into that subtree
            return self.insert_at_node(region, data, child_index);
        }

        panic!("something weird happened");
    }
/// Recursively searches for the internal node whose minimum bounding region contains `region`.
Recursively searches for the internal node whose minimum bounding region contains `region`.
Recursively searches for the internal node whose minimum bounding region contains ` region ` .
fn insert_at_node(
        &mut self,
        region: Region,
        data: ND,
        index: Index,
    ) -> Result<(), ShapelikeError> {
        // current node under consideration
        let node = &self.nodes[index];
        // If we've reached a node with leaf children, insert here.
        if self.has_child_leaf(index) || !node.has_children() {
            // If we've reached a leaf node, insert this as a leaf of the parent
            // This call is safe as `region` is guaranteed to be contained in the minimum
            // bounding region of this node.
            self._insert(region, data, index);
            return Ok(());
        }
        // Does any child of this node have an MBR containing our input region?
        let mut child_containing_region = None;
        'mbr_search: for (child_index, child_node) in self.child_iter(index) {
            if child_node.get_region().contains_region(&region)? {
                child_containing_region = Some(child_index);
                break 'mbr_search;
            }
        }
        // If we found a child node containing our region, recurse into that node
        if let Some(child_index) = child_containing_region {
            return self.insert_at_node(region, data, child_index);
        }
        // Otherwise there is no child MBR containing our input `region`.  Thus find
        // the bounding box in this node such that enlarging it to contain
        // `minimum_bounding_region` will add the least amount of area.
        if let Some((_, combined_region, child_index)) = self
            .child_iter(index)
            .map(|(child_index, child_node)| {
                let initial_area = child_node.get_region().get_area();
                // TODO: figure out a better error handling path here (perhaps use `filter_map`)
                let combined_region = child_node
                    .get_region()
                    .combine_region(&region)
                    .expect("Failed to combine regions");
                (
                    combined_region.get_area() - initial_area,
                    combined_region,
                    child_index,
                )
            })
            .min_by(|(left_change, _, _), (right_change, _, _)| {
                // TODO: this should be fine, but worth investigating.
                f64::partial_cmp(left_change, right_change).unwrap()
            })
        {
            // Enlarge `child_index`'s bounding box.  This call is safe as `combined_region`
            // is enlarged from the MBR of the child node.
            self.get_node_mut(child_index)
                .set_minimum_bounding_region_unsafe(combined_region);
            // Since the enlarged bounding box now contains our object, recurse into that subtree
            return self.insert_at_node(region, data, child_index);
        }
        panic!("something weird happened");
    }
fn insert_at_node ( & mut self , region : Region , data : ND , index : Index , ) -> Result < ( ) , ShapelikeError > { // current node under consideration let node = & self . nodes [ index ] ; // If we've reached a node with leaf children, insert here. if self . has_child_leaf ( index ) || ! node . has_children ( ) { // If we've reached a leaf node, insert this as a leaf of the parent // This call is safe as `region` is guaranteed to be contained in the minimum // bounding region of this node. self . _insert ( region , data , index ) ; return Ok ( ( ) ) ; } // Does any child of this node have an MBR containing our input region? let mut child_containing_region = None ; ' mbr_search : for ( child_index , child_node ) in self . child_iter ( index ) { if child_node . get_region ( ) . contains_region ( & region ) ? { child_containing_region = Some ( child_index ) ; break ' mbr_search ; } } // If we found a child node containing our region, recurse into that node if let Some ( child_index ) = child_containing_region { return self . insert_at_node ( region , data , child_index ) ; } // Otherwise there is no child MBR containing our input `region`.  Thus find // the bounding box in this node such that enlarging it to contain // `minimum_bounding_region` will add the least amount of area. if let Some ( ( _ , combined_region , child_index ) ) = self . child_iter ( index ) . map ( | ( child_index , child_node ) | { let initial_area = child_node . get_region ( ) . get_area ( ) ; // TODO: figure out a better error handling path here (perhaps use `filter_map`) let combined_region = child_node . get_region ( ) . combine_region ( & region ) . expect ( " " ) ; ( combined_region . get_area ( ) - initial_area , combined_region , child_index , ) } ) . min_by ( | ( left_change , _ , _ ) , ( right_change , _ , _ ) | { // TODO: this should be fine, but worth investigating. f64 :: partial_cmp ( left_change , right_change ) . unwrap ( ) } ) { // Enlarge `child_index`'s bounding box.  This call is safe as `combined_region` // is enlarged from the MBR of the child node. self . get_node_mut ( child_index ) . set_minimum_bounding_region_unsafe ( combined_region ) ; // Since the enlarged bounding box now contains our object, recurse into that subtree return self . insert_at_node ( region , data , child_index ) ; } panic ! ( " " ) ; }
Recursively searches for the internal node whose minimum bounding region contains `region`.
Recursively searches for the internal node whose minimum bounding region contains ` region ` .
&mut self
region
Region
data
ND
index
Index
&mut self
region
Region
data
ND
index
Index