예제 #1
0
        public static ulong GetLocation(RectangleShape extent, BaseShape shape, int level)
        {
            RectangleShape extentBoundingBox = SquaredExtent(extent);
            RectangleShape shapeBoundingBox  = shape.GetBoundingBox();

            ulong location = 1;

            if (shapeBoundingBox.IsWithin(extentBoundingBox))
            {
                int currentlevel = 1;

                while (currentlevel < level)
                {
                    RectangleShape upperLeft   = GetUpperLeftQuater(extentBoundingBox);
                    RectangleShape uppperRight = GetUpperRightQuater(extentBoundingBox);
                    RectangleShape lowerLeft   = GetLowerLeftQuater(extentBoundingBox);
                    RectangleShape lowerRight  = GetLowerRightQuater(extentBoundingBox);

                    if (shapeBoundingBox.IsWithin(upperLeft))
                    {
                        location = (location << 1) | 1;
                        currentlevel++;
                        extentBoundingBox = upperLeft;
                    }
                    else if (shapeBoundingBox.IsWithin(uppperRight))
                    {
                        location = (location << 2) | 1;
                        currentlevel++;
                        extentBoundingBox = uppperRight;
                    }
                    else if (shapeBoundingBox.IsWithin(lowerLeft))
                    {
                        location = (location << 3) | 1;
                        currentlevel++;
                        extentBoundingBox = lowerLeft;
                    }
                    else if (shapeBoundingBox.IsWithin(lowerRight))
                    {
                        location = (location << 4) | 1;
                        currentlevel++;
                        extentBoundingBox = lowerRight;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(location);
        }
예제 #2
0
        public static int GetAppropriateLevel(RectangleShape extent, BaseShape shape)
        {
            RectangleShape currentBoundingBox = SquaredExtent(extent);
            RectangleShape shapeBoundingBox   = shape.GetBoundingBox();

            int level = 0;

            if (shapeBoundingBox.IsWithin(currentBoundingBox))
            {
                while (true)
                {
                    level++;
                    RectangleShape upperLeft   = GetUpperLeftQuater(currentBoundingBox);
                    RectangleShape uppperRight = GetUpperRightQuater(currentBoundingBox);
                    RectangleShape lowerLeft   = GetLowerLeftQuater(currentBoundingBox);
                    RectangleShape lowerRight  = GetLowerRightQuater(currentBoundingBox);

                    if (shapeBoundingBox.IsWithin(upperLeft))
                    {
                        currentBoundingBox = upperLeft;
                    }
                    else if (shapeBoundingBox.IsWithin(uppperRight))
                    {
                        currentBoundingBox = uppperRight;
                    }
                    else if (shapeBoundingBox.IsWithin(lowerLeft))
                    {
                        currentBoundingBox = lowerLeft;
                    }
                    else if (shapeBoundingBox.IsWithin(lowerRight))
                    {
                        currentBoundingBox = lowerRight;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(level);
        }