Ejemplo n.º 1
0
        bool CanSimplify(SimpleNode newNode, int zoomLevel, int zoomLevelsCount)
        {
            if (IsEmpty)
            {
                return(false);
            }
            double minDistance = (double)zoomLevel / (2 * zoomLevelsCount);

            if (zoomLevel == 1)
            {
                return(false);
            }
            return(Math.Abs(RefinedX - newNode.RefinedX) < minDistance && Math.Abs(RefinedY - newNode.RefinedY) < minDistance);
        }
Ejemplo n.º 2
0
        public static Tuple <Range, Range> GetWholeRange(QuadtreeNode startNode)
        {
            QuadtreeNode ne = GetEdgeNode(startNode, QuadtreeNodeTypes.NE);
            QuadtreeNode nw = GetEdgeNode(startNode, QuadtreeNodeTypes.NW);
            QuadtreeNode se = GetEdgeNode(startNode, QuadtreeNodeTypes.SE);
            QuadtreeNode sw = GetEdgeNode(startNode, QuadtreeNodeTypes.SW);

            return(new Tuple <Range, Range>(
                       new Range()
            {
                Min = SimpleNode.GetMin(nw.X, sw.X), Max = SimpleNode.GetMax(ne.X, se.X)
            },
                       new Range()
            {
                Min = SimpleNode.GetMin(sw.Y, se.Y), Max = SimpleNode.GetMax(ne.Y, nw.Y)
            }));
        }
Ejemplo n.º 3
0
        public QuadtreeNode Connect(SimpleNode newNode, byte zoomLevel, int zoomLevelsCount)
        {
            QuadtreeNode whereToAdd = null;

            if (IsEmpty)
            {
                whereToAdd = this;
            }
            else
            {
                if (CanSimplify(newNode, zoomLevel, zoomLevelsCount))
                {
                    whereToAdd = this;
                }
                else
                {
                    whereToAdd = GetChildNode(CalculateOrientation(newNode.X, newNode.Y), true);
                }
            }
            if (whereToAdd != null)
            {
                if (whereToAdd.IsEmpty)
                {
                    whereToAdd.X           = newNode.X;
                    whereToAdd.Y           = newNode.Y;
                    whereToAdd.SourceIndex = newNode.SourceIndex;
                    whereToAdd.ZoomLevel   = zoomLevel;
                }
                else
                {
                    if (whereToAdd != this)
                    {
                        return(whereToAdd);
                    }
                }
            }
            return(null);
        }