HPASharp.HierarchicalMap.SetCurrentCluster C# (CSharp) Method

SetCurrentCluster() public method

Defines the bounding box of the cluster we want to process based on a given level and a position in the grid
public SetCurrentCluster ( Position pos, int level ) : void
pos Position
level int
return void
		public void SetCurrentCluster(Position pos, int level)
		{
			// if the level surpasses the MaxLevel, just set the whole map as a cluster
			if (level > MaxLevel)
			{
				this.currentClusterY0 = 0;
				this.currentClusterY1 = this.Height - 1;
				this.currentClusterX0 = 0;
				this.currentClusterX1 = this.Width - 1;
				return;
			}

			var offset = GetOffset(level);
			var nodeY = pos.Y; // nodeId / this.Width;
			var nodeX = pos.X; // nodeId % this.Width;
			this.currentClusterY0 = nodeY - (nodeY % offset);
			this.currentClusterY1 = Math.Min(this.Height - 1, this.currentClusterY0 + offset - 1);
			this.currentClusterX0 = nodeX - (nodeX % offset);
			this.currentClusterX1 = Math.Min(this.Width - 1, this.currentClusterX0 + offset - 1);
		}

Same methods

HierarchicalMap::SetCurrentCluster ( int x, int y, int offset ) : void

Usage Example

		/// <summary>
		/// Inserts a node and creates edges around the local points of the cluster it the
		/// node we try to insert belongs to at each level
		/// </summary>
		private static void InsertStalHEdges(HierarchicalMap map, int nodeId)
		{
			var abstractNodeId = map.AbsNodeIds[nodeId];
			var nodeInfo = map.AbstractGraph.GetNodeInfo(abstractNodeId);
			var oldLevel = nodeInfo.Level;
			nodeInfo.Level = map.MaxLevel;
			for (var level = oldLevel + 1; level <= map.MaxLevel; level++)
			{
				map.SetCurrentLevel(level - 1);
				map.SetCurrentCluster(nodeInfo.Position, level);
				var clusterRectangle = map.GetCurrentClusterRectangle();
				var currentClusterY0 = clusterRectangle.Origin.Y;
				var currentClusterY1 = clusterRectangle.Origin.Y + clusterRectangle.Size.Height;
				var currentClusterX0 = clusterRectangle.Origin.X;
				var currentClusterX1 = clusterRectangle.Origin.X + clusterRectangle.Size.Width;
				for (var y = currentClusterY0; y <= currentClusterY1; y++)
					for (var x = currentClusterX0; x <= currentClusterX1; x++)
					{
						var nodeId2 = y * map.Width + x;
						var abstractNodeId2 = map.AbsNodeIds[nodeId2];
						AddEdgesBetweenAbstractNodes(map, abstractNodeId, abstractNodeId2, level);
					}
			}
		}