Beispiel #1
0
    public static void BuildRecursively(CQuadTreeNode node)
    {
        float subWidth   = node.Bound.width * 0.5f;
        float subHeight  = node.Bound.height * 0.5f;
        bool  isPartible = subWidth >= CQuadTreeConfig.CellSizeThreshole && subHeight >= CQuadTreeConfig.CellSizeThreshole;

        CreateNode _nodeCreator = (bnd) => { return(new CQuadTreeNode(bnd)); };
        CreateNode creator      = _nodeCreator;

        node.SetChildrenNode(new CQuadTreeNode[CQuadTreeNode.chilren] {
            creator(new Rect(node.Bound.xMin, node.Bound.yMin, subWidth, subHeight)),
            creator(new Rect(node.Bound.xMin + subWidth, node.Bound.yMin, subWidth, subHeight)),
            creator(new Rect(node.Bound.xMin, node.Bound.yMin + subHeight, subWidth, subHeight)),
            creator(new Rect(node.Bound.xMin + subWidth, node.Bound.yMin + subHeight, subWidth, subHeight)),
        });

        if (isPartible)
        {
            foreach (var sub in node._chilren)
            {
                BuildRecursively(sub);
            }
        }
    }
Beispiel #2
0
 public CPatchQuadTree(Rect bound)
 {
     _root = new CQuadTreeNode(bound);
     C2DBoxUilty.BuildRecursively(_root);
 }