Пример #1
0
        public static int LookupChildPartition(Point p, PartitionNode parent_node)
        {
            int offset = parent_node.getNodeSize() / 4;
            int x1     = parent_node.getCenter().X - offset;
            int x2     = parent_node.getCenter().X + offset;
            int y1     = parent_node.getCenter().Y - offset;
            int y2     = parent_node.getCenter().Y + offset;

            int childNum = -1;

            if (p.X < x1)
            {
                if (p.Y < y1)
                {
                    childNum = 0;
                }
                else if (p.Y < y2)
                {
                    childNum = 3;
                }
                else
                {
                    childNum = 6;
                }
            }
            else if (p.X < x2)
            {
                if (p.Y < y1)
                {
                    childNum = 1;
                }
                else if (p.Y < y2)
                {
                    childNum = 4;
                }
                else
                {
                    childNum = 7;
                }
            }
            else
            {
                if (p.Y < y1)
                {
                    childNum = 2;
                }
                else if (p.Y < y2)
                {
                    childNum = 5;
                }
                else
                {
                    childNum = 8;
                }
            }
            return(childNum);
        }
Пример #2
0
        public static Point GetChildCenter(PartitionNode parent, int child_num)
        {
            int children_size = parent.getNodeSize() / 2;
            int x1            = parent.getCenter().X - children_size;
            int x2            = x1 + children_size;
            int x3            = x2 + children_size;
            int y1            = parent.getCenter().Y - children_size;
            int y2            = y1 + children_size;
            int y3            = y2 + children_size;

            switch (child_num)
            {
            case 0:
                return(new Point(x1, y1));

            case 1:
                return(new Point(x2, y1));

            case 2:
                return(new Point(x3, y1));

            case 3:
                return(new Point(x1, y2));

            case 4:
                return(new Point(x2, y2));

            case 5:
                return(new Point(x3, y2));

            case 6:
                return(new Point(x1, y3));

            case 7:
                return(new Point(x2, y3));

            case 8:
                return(new Point(x3, y3));

            default:
                return(new Point(0, 0));
            }
        }