예제 #1
0
    public void DeleteNodeIfEmpty()
    {
        if (_parent == null)
        {
            return;
        }

        CQuadLeaf parent = _parent;

        if (_objects.Count == 0 && !HaveChilds())
        {
            _parent.DeleteChild(_quad_index);
        }

        parent.DeleteNodeIfEmpty();
    }
예제 #2
0
파일: QuadMap.cs 프로젝트: nigglev/QuadTree
    public void DeleteObjectByMousePos(Vector3 in_mouse_position)
    {
        _deleted_objects_id.Clear();

        int comparator = 1;
        int depth      = _tree_depth;
        int x          = (int)((in_mouse_position.x - _origin.x) / _unity_meters_in_piece);
        int y          = (int)((in_mouse_position.z - _origin.z) / _unity_meters_in_piece);

        CQuadLeaf current_quad = _initial_quad;
        CQuadLeaf prev_quad    = null;

        while (current_quad != null)
        {
            if (current_quad.GetQuadObjectectsCount() != 0)
            {
                current_quad.DeleteObjectByMousePosition(in_mouse_position, _deleted_objects_id);
                for (int i = 0; i < _deleted_objects_id.Count; i++)
                {
                    _objs_ht.Remove(_deleted_objects_id[i]);
                }
            }


            depth--;

            int k     = comparator << depth;
            int x_bin = (k & x) > 0 ? 1 : 0;
            int y_bin = (k & y) > 0 ? 1 : 0;
            int index = (y_bin << 1) + x_bin;

            prev_quad    = current_quad;
            current_quad = current_quad.GetQuad(index);
        }

        prev_quad.DeleteNodeIfEmpty();
    }