/// <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); } }
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); }