Example #1
0
        public IPart_Edit RemovePart(int x, int y)
        {
            IPart_Edit tempPosition = array[y, x];

            array[y, x] = null;
            return(tempPosition);
        }
Example #2
0
        /// <summary>
        /// 如果该点所在的分块已经存在则返回该分块的指针,否则创建该分块并返回该分块的指针
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        //[MethodImplAttribute(MethodImplOptions.Synchronized)]
        public IPart_Edit GOCPartRefByPoint(IPosition point)
        {
            //lock (this)
            {
                int x, y;
                x = ConvertRealValueToPartSequenceX(point.GetX());
                y = ConvertRealValueToPartSequenceY(point.GetY());

                IPart_Edit queryPart = queryTable.GetPartRef(x, y);

                //lock (queryTable)
                {
                    if (queryPart == null)
                    {
                        queryPart = queryTable.CreateAndGetPartRef(x, y);
                        queryPart.SetX(x);
                        queryPart.SetY(y);

                        //把引起part被创建的一点设定为该part的代表点.
                        queryPart.SetDeputyPoint(point);
                    }
                }

                return(queryPart);
            }
        }
        public void Insert(IPosition point)
        {
            IPosition NewPosition = point;

            for (int levelSequrence = LevelList.Count - 1; levelSequrence >= 0; levelSequrence--)
            {
                IPart_Edit currentPart = LevelList[levelSequrence].GOCPartRefByPoint(point);

                Monitor.Enter(currentPart);
                currentPart.AddToSubPositionList(NewPosition);

                //更新不同层里面该点所在的part中点的数目
                currentPart.SubPointNumIncrease(1);
                Monitor.Exit(currentPart);

                if (currentPart.GetSubPositionNum() == 1)
                {
                    //如果part里面只有一个point,说明这个part也是新建的,它所属的宏观分块也必须把它包含.
                    NewPosition = currentPart;
                }
                else
                {
                    break;
                }
            }
        }
Example #4
0
        /// <summary>
        /// 创建该分块并返回该分块的指针
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public IPart_Edit CreateAndGetPartRef(int x, int y)
        {
            IPart_Edit temp = array[y, x];

            array[y, x] = partInstance.Create();
            return(array[y, x]);
        }
        /// <summary>
        /// 创建该分块并返回该分块的指针
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public IPart_Edit CreateAndGetPartRef(int x, int y)
        {
            IPart_Edit part   = partInstance.Create();
            int        tableX = x / scale;
            int        tableY = y / scale;
            LinkedList l      = Part_list[tableX, tableY];

            if (l == null)
            {
                l = new LinkedList(part, null);
                Part_list[tableX, tableY] = l;
                return(part);
            }

            if (l.part == null)
            {
                l.part = part;
            }
            else
            {
                LinkedList newHead = new LinkedList(part, null);
                LinkedList temp    = l.next;
                newHead.next = temp;
                l.next       = newHead;
            }
            return(part);
        }
Example #6
0
        public IPart_Edit RemovePart(int x, int y)
        {
            int        key          = y * this.width + x;
            IPart_Edit tempPosition = (IPart_Edit)ht_Part[key];

            ht_Part.Remove(key);
            return(tempPosition);
        }
Example #7
0
        /// <summary>
        /// 创建该分块并返回该分块的指针
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public IPart_Edit CreateAndGetPartRef(int x, int y)
        {
            int        key  = y * this.width + x;
            IPart_Edit part = partInstance.Create();

            ht_Part.Add(key, part);
            return(part);
        }
        public IPart_Edit RemovePart(int x, int y)
        {
            LinkedList tempPartList = GetList(x, y);
            IPart_Edit part         = GetPart(tempPartList, x, y);

            if (part != null)
            {
                //删除链表中的某一结点
                LinkedList currentList = tempPartList.next;
                LinkedList tempList    = tempPartList;
                while (currentList != null)
                {
                    if (currentList.part.GetX() == part.GetX() && currentList.part.GetY() == part.GetY())
                    {
                        tempList         = currentList.next;
                        currentList.next = null;
                    }
                    tempList    = currentList;
                    currentList = currentList.next;
                }
            }
            return(part);
        }
Example #9
0
 public QueryTableByArray(Type partType)
 {
     partInstance = (IPart_Edit)Activator.CreateInstance(partType);
 }
        public void Remove_NotTestYet(IPosition point)
        {
            //更新不同层里面该点所在的part中点的数目
            for (int levelSequrence = LevelList.Count - 2; levelSequrence >= 0; levelSequrence--)
            {
                ((IPart_Edit)LevelList[levelSequrence + 1].GetPartRefByPoint(point)).SubPointNumDecrease(1);
            }

            IPosition RemovePosition = point;

            for (int levelSequrence = LevelList.Count - 1; levelSequrence >= -1; levelSequrence--)
            {
                if (levelSequrence == -1)
                {
                    ((IPart_Edit)LevelList[0].GetPartRefByPoint(point)).RemoveFormSubPositionList(RemovePosition);
                    break;
                }

                IPart_Edit currentPart = (IPart_Edit)(LevelList[levelSequrence].GetPartRefByPoint(point));

                if (currentPart == null)
                {
                    throw new Exception("不存在该分块的指针!(指定删除的点是否已经存在?)");
                }

                currentPart.RemoveFormSubPositionList(RemovePosition);

                if (currentPart.GetSubPositionNum() == 0)
                {
                    //如果part里面一个点都没有,应该把该part从表格中删除.
                    LevelList[levelSequrence].RemovePartByPoint(point);
                    //同时也应该从包含该分块的宏观分块中删除该分块.
                    RemovePosition = currentPart;
                }
                else
                {
                    IPosition newDeputyPoint  = null;
                    int       levelSequrence2 = levelSequrence;
                    IPosition deputyPoint     = LevelList[levelSequrence2].GetPartRefByPoint(point).GetRandomOneFormDescendantPoint();
                    if (point == deputyPoint)
                    {
                        newDeputyPoint = currentPart.GetRandomPointFormBottomLevel();
                    }

                    //如果该part里面超过一个点则可以结束删除工作,不过需要判断一下该part以及其所属宏观part的代表点是否是已删除点,如果是,需要更新.
                    for (levelSequrence2 = levelSequrence; levelSequrence2 >= 0; levelSequrence2--)
                    {
                        deputyPoint = LevelList[levelSequrence2].GetPartRefByPoint(point).GetRandomOneFormDescendantPoint();
                        if (point == deputyPoint)
                        {
                            ((IPart_Edit)(LevelList[levelSequrence2].GetPartRefByPoint(point))).SetDeputyPoint(newDeputyPoint);
                        }
                        else
                        {
                            //如果到了某层的代表点已经不是已删除点,则不需要继续向上查询.
                            break;
                        }
                    }

                    break;
                }
            }
        }
        private void DiffuseFromOriginByPartInSpecialLevel(IPosition targetPoint, int targetPartLevelSequence)
        {
            CurrentNearestPoint = null;

            CurrentNearestDistanceSquare = float.MaxValue;
            CurrentNearestDistance       = float.MaxValue;

            ILevel targetPartLevel = m2mStructure.GetLevel(targetPartLevelSequence);

            HorizontalSearchPriority horizontalSearchPriority;
            VerticalSearchPriority   verticalSearchPriority;

            int targetPartX = targetPartLevel.ConvertRealValueToPartSequenceX(targetPoint.GetX());
            int targetPartY = targetPartLevel.ConvertRealValueToPartSequenceY(targetPoint.GetY());

            #region code for algorithm demo
            if (GetQueryPart != null)
            {
                IPart_Edit temp = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0).Create();
                temp.SetX(targetPartX);
                temp.SetY(targetPartY);
                GetQueryPart(m2mStructure.GetLevel(targetPartLevelSequence), targetPartLevelSequence, temp);
            }
            #endregion

            //计算搜索框

            //如果点在分块的左半部分
            if (targetPoint.GetX() <= targetPartLevel.ConvertPartSequenceXToRealValue(targetPartX) + targetPartLevel.GetGridWidth() / 2)
            {
                leftSearchLine           = targetPartX - 1;
                rightSearchLine          = targetPartX;
                horizontalSearchPriority = HorizontalSearchPriority.right;
            }
            else
            {
                leftSearchLine           = targetPartX;
                rightSearchLine          = targetPartX + 1;
                horizontalSearchPriority = HorizontalSearchPriority.left;
            }

            //如果点在分块的下半部分
            if (targetPoint.GetY() <= targetPartLevel.ConvertPartSequenceYToRealValue(targetPartY) + targetPartLevel.GetGridHeight() / 2)
            {
                bottomSearchLine       = targetPartY - 1;
                topSearchLine          = targetPartY;
                verticalSearchPriority = VerticalSearchPriority.top;
            }
            else
            {
                bottomSearchLine       = targetPartY;
                topSearchLine          = targetPartY + 1;
                verticalSearchPriority = VerticalSearchPriority.bottom;
            }

            //初始化边界
            upperBound = float.MaxValue;
            lowerBound = float.MinValue;
            leftBound  = float.MinValue;
            rightBound = float.MaxValue;

            //把点集边界作为搜索边界
            upperBoundInGrid = targetPartLevel.GetUnitNumInHeight() - 1;
            lowerBoundInGrid = 0;
            leftBoundInGrid  = 0;
            rightBoundInGrid = targetPartLevel.GetUnitNumInWidth() - 1;

            SquareDiffuseFromSearchLineToSearchBoundInGrid(targetPoint, targetPartLevelSequence, targetPartLevel, horizontalSearchPriority, verticalSearchPriority);
        }
 public LinkedList(IPart_Edit part, LinkedList next)
 {
     this.part = part;
     this.next = next;
 }
 public LinkedList()
 {
     this.part = null;
     this.next = null;
 }