Beispiel #1
0
    public void buttonClicked()
    {
        Kd_Node tree = calculateTree(Names);

        output = "";
        PrintTree(tree, "");
        sceneText.text = output;
    }
Beispiel #2
0
 public void PrintTree(Kd_Node tree, string indent)
 {
     if (tree == null)
     {
         return;
     }
     output += indent + "+- " + tree.point.alias + "\n";
     indent += "|  ";
     PrintTree(tree.left, indent);
     PrintTree(tree.right, indent);
 }
Beispiel #3
0
    public Kd_Node makeTree(List <DotWithName> SX, List <DotWithName> SY, bool xCheck)
    {
        int     count = SX.Count;
        Kd_Node node  = new Kd_Node();

        if (xCheck)
        {
            node.point = SX [SX.Count / 2];
        }
        else
        {
            node.point = SY [SY.Count / 2];
        }


        List <DotWithName> leftByX  = new List <DotWithName> ();
        List <DotWithName> rightByX = new List <DotWithName> ();

        List <DotWithName> leftByY  = new List <DotWithName> ();
        List <DotWithName> rightByY = new List <DotWithName> ();

        if (xCheck)
        {
            Geometry.SplitListByPointByX(node.point, SY, ref leftByY, ref rightByY);
            Geometry.SplitListByPointByX(node.point, SX, ref leftByX, ref rightByX);
        }
        else
        {
            Geometry.SplitListByPointByY(node.point, SY, ref leftByY, ref rightByY);
            Geometry.SplitListByPointByY(node.point, SX, ref leftByX, ref rightByX);
        }

        if (rightByX.Count > 0)
        {
            node.right = makeTree(rightByX, rightByY, !xCheck);
        }
        else
        {
            node.right = null;
        }
        if (leftByX.Count > 0)
        {
            node.left = makeTree(leftByX, leftByY, !xCheck);
        }
        else
        {
            node.left = null;
        }
        return(node);
    }