fn split_node(&mut self, index: Index) {
        // Get all of the children of the current node
        let children = self.get_node_mut(index).clear_children();

        // Partition the leave indexes using the QuadraticSplit strategy
        let (left, right, left_mbr, right_mbr) = self.quadratic_partition(children);

        // check that everything has the correct size
        debug_assert!(left.len() >= self.min_children);
        debug_assert!(right.len() >= self.min_children);

        // If we're splitting the root node, collect all children of the root node into two groups
        // which will be our new root children.
        //
        //       root     =>    root
        //      / | \          /    \
        //     /  |  \       left  right
        //
        if index == self.root {
            // insert a new left node
            let left_node = Node::new_internal_node(left_mbr, Some(index));
            let left_index = self.nodes.insert(left_node);
            self.set_children_safe(left_index, left);

            // insert a new right node
            let right_node = Node::new_internal_node(right_mbr, Some(index));
            let right_index = self.nodes.insert(right_node);
            self.set_children_safe(right_index, right);

            // Add the left and right nodes as children of the current node.
            // This call is safe because:
            // - The current node has no children,
            // - The nodes corresponding to `left_index` and `right_index` both have their `parent`
            //   attribute set to `Some(index)`, i.e. the index of the current node.
            self.get_node_mut(index)
                .set_children_unsafe(vec![left_index, right_index]);
        } else {
            // Otherwise we apply the transformation:
            //
            //     parent            parent
            //       |               /   \
            //      node    =>    node    right
            //     / | \          /  \    /  \
            //    /  |  \        /    \  /    \
            //
            let parent = self.get_node(index).get_parent().unwrap();

            // the current node will become our new left node
            let left_node = self.get_node_mut(index);

            // This is safe as `left_node` has no children, and all of the children
            // in `left` already have their parent attribute set to `Some(index)`.
            // Finally, all of the children are contained in `left_mbr` by its construction.
            left_node.set_minimum_bounding_region_unsafe(left_mbr);
            left_node.set_children_unsafe(left);

            // make a new empty right node
            let right_index = self
                .nodes
                .insert(Node::new_internal_node(right_mbr, Some(parent)));

            // add the right as children (safely) of the right node
            self.set_children_safe(right_index, right.iter().cloned());

            // This call is fine here because `right_index` refers to a node in this tree
            // whose parent attribute is set to `Some(parent)`.
            self.get_node_mut(parent).add_child_unsafe(right_index);

            if self.nodes[parent].child_count() >= self.max_children {
                self.split_node(parent);
            }
        }
    }
/// Splits the overfull node corresponding to `index`.
Splits the overfull node corresponding to `index`.
Splits the overfull node corresponding to ` index ` .
fn split_node(&mut self, index: Index) {
        // Get all of the children of the current node
        let children = self.get_node_mut(index).clear_children();
        // Partition the leave indexes using the QuadraticSplit strategy
        let (left, right, left_mbr, right_mbr) = self.quadratic_partition(children);
        // check that everything has the correct size
        debug_assert!(left.len() >= self.min_children);
        debug_assert!(right.len() >= self.min_children);
        // If we're splitting the root node, collect all children of the root node into two groups
        // which will be our new root children.
        //
        //       root     =>    root
        //      / | \          /    \
        //     /  |  \       left  right
        //
        if index == self.root {
            // insert a new left node
            let left_node = Node::new_internal_node(left_mbr, Some(index));
            let left_index = self.nodes.insert(left_node);
            self.set_children_safe(left_index, left);
            // insert a new right node
            let right_node = Node::new_internal_node(right_mbr, Some(index));
            let right_index = self.nodes.insert(right_node);
            self.set_children_safe(right_index, right);
            // Add the left and right nodes as children of the current node.
            // This call is safe because:
            // - The current node has no children,
            // - The nodes corresponding to `left_index` and `right_index` both have their `parent`
            //   attribute set to `Some(index)`, i.e. the index of the current node.
            self.get_node_mut(index)
                .set_children_unsafe(vec![left_index, right_index]);
        } else {
            // Otherwise we apply the transformation:
            //
            //     parent            parent
            //       |               /   \
            //      node    =>    node    right
            //     / | \          /  \    /  \
            //    /  |  \        /    \  /    \
            //
            let parent = self.get_node(index).get_parent().unwrap();
            // the current node will become our new left node
            let left_node = self.get_node_mut(index);
            // This is safe as `left_node` has no children, and all of the children
            // in `left` already have their parent attribute set to `Some(index)`.
            // Finally, all of the children are contained in `left_mbr` by its construction.
            left_node.set_minimum_bounding_region_unsafe(left_mbr);
            left_node.set_children_unsafe(left);
            // make a new empty right node
            let right_index = self
                .nodes
                .insert(Node::new_internal_node(right_mbr, Some(parent)));
            // add the right as children (safely) of the right node
            self.set_children_safe(right_index, right.iter().cloned());
            // This call is fine here because `right_index` refers to a node in this tree
            // whose parent attribute is set to `Some(parent)`.
            self.get_node_mut(parent).add_child_unsafe(right_index);
            if self.nodes[parent].child_count() >= self.max_children {
                self.split_node(parent);
            }
        }
    }
fn split_node ( & mut self , index : Index ) { // Get all of the children of the current node let children = self . get_node_mut ( index ) . clear_children ( ) ; // Partition the leave indexes using the QuadraticSplit strategy let ( left , right , left_mbr , right_mbr ) = self . quadratic_partition ( children ) ; // check that everything has the correct size debug_assert ! ( left len ( ) self min_children ) ; debug_assert ! ( right len ( ) self min_children ) ; // If we're splitting the root node, collect all children of the root node into two groups // which will be our new root children. // //       root     =>    root //      / | \          /    \ //     /  |  \       left  right // if index == self . root { // insert a new left node let left_node = Node :: new_internal_node ( left_mbr , Some ( index ) ) ; let left_index = self . nodes . insert ( left_node ) ; self . set_children_safe ( left_index , left ) ; // insert a new right node let right_node = Node :: new_internal_node ( right_mbr , Some ( index ) ) ; let right_index = self . nodes . insert ( right_node ) ; self . set_children_safe ( right_index , right ) ; // Add the left and right nodes as children of the current node. // This call is safe because: // - The current node has no children, // - The nodes corresponding to `left_index` and `right_index` both have their `parent` //   attribute set to `Some(index)`, i.e. the index of the current node. self . get_node_mut ( index ) . set_children_unsafe ( vec ! [ left_index right_index ] ) ; } else { // Otherwise we apply the transformation: // //     parent            parent //       |               /   \ //      node    =>    node    right //     / | \          /  \    /  \ //    /  |  \        /    \  /    \ // let parent = self . get_node ( index ) . get_parent ( ) . unwrap ( ) ; // the current node will become our new left node let left_node = self . get_node_mut ( index ) ; // This is safe as `left_node` has no children, and all of the children // in `left` already have their parent attribute set to `Some(index)`. // Finally, all of the children are contained in `left_mbr` by its construction. left_node . set_minimum_bounding_region_unsafe ( left_mbr ) ; left_node . set_children_unsafe ( left ) ; // make a new empty right node let right_index = self . nodes . insert ( Node :: new_internal_node ( right_mbr , Some ( parent ) ) ) ; // add the right as children (safely) of the right node self . set_children_safe ( right_index , right . iter ( ) . cloned ( ) ) ; // This call is fine here because `right_index` refers to a node in this tree // whose parent attribute is set to `Some(parent)`. self . get_node_mut ( parent ) . add_child_unsafe ( right_index ) ; if self . nodes [ parent ] . child_count ( ) >= self . max_children { self . split_node ( parent ) ; } } }
Splits the overfull node corresponding to `index`.
Splits the overfull node corresponding to ` index ` .
&mut self
index
Index
&mut self
index
Index