// insert a new node, such as start or target, to the abstract graph and
// returns the id of the newly created node in the abstract graph
// x and y are the positions where I want to put the node
private int InsertStal(HierarchicalMap map, int nodeId, Position pos, int start)
{
// If the node already existed (for instance, it was the an entrance point already
// existing in the graph, we need to keep track of the previous status in order
// to be able to restore it once we delete this STAL
if (map.AbsNodeIds[nodeId] != Constants.NO_NODE)
{
m_stalLevel[start] = map.AbstractGraph.GetNodeInfo(map.AbsNodeIds[nodeId]).Level;
m_stalEdges[start] = map.GetNodeEdges(nodeId);
m_stalUsed[start] = true;
return map.AbsNodeIds[nodeId];
}
m_stalUsed[start] = false;
var cluster = map.FindClusterForPosition(pos);
// create global entrance
var absNodeId = map.NrNodes;
var localEntranceIdx = cluster.AddEntrance(absNodeId, new Position(pos.X - cluster.Origin.X, pos.Y - cluster.Origin.Y));
cluster.UpdatePaths(localEntranceIdx);
map.AbsNodeIds[nodeId] = absNodeId;
var info = new AbsTilingNodeInfo(
absNodeId,
1,
cluster.Id,
pos,
nodeId,
localEntranceIdx);
map.AbstractGraph.AddNode(absNodeId, info);
// add new edges to the abstract graph
for (var k = 0; k < cluster.GetNrEntrances() - 1; k++)
{
if (cluster.AreConnected(localEntranceIdx, k))
{
map.AddEdge(
cluster.GetGlobalAbsNodeId(k),
cluster.GetGlobalAbsNodeId(localEntranceIdx),
cluster.GetDistance(localEntranceIdx, k));
map.AddEdge(
cluster.GetGlobalAbsNodeId(localEntranceIdx),
cluster.GetGlobalAbsNodeId(k),
cluster.GetDistance(k, localEntranceIdx));
}
}
return absNodeId;
}