in GraphLayout/MSAGL/GraphmapsWithMesh/MeshCreator.cs [939:1076]
public static void ProcessRightRays(Tiling g, Dictionary<int, int> Neighbors1, Dictionary<int, int> Neighbors8, int maxX, int maxY, Dictionary<Point, int> locationtoNode)
{
int a;
//LineSegment l;
for (int i = 0; i < g.N; i++)
{
Vertex CurrentVertex = g.VList[i];
if (CurrentVertex.leftRay == null)
{
Vertex Neighbor = null;
Vertex Neighbor1 = null, Neighbor8 = null;
//find the closest neighbor in C4
double distance1 = double.MaxValue;
if (Neighbors1.ContainsKey(g.VList[i].Id))
{
Neighbor1 = g.VList[Neighbors1[g.VList[i].Id]];
distance1 = Math.Abs(Neighbor1.XLoc - CurrentVertex.XLoc) +
Math.Abs(Neighbor1.YLoc - CurrentVertex.YLoc);
}
//find the closest neighbor in C5
double distance8 = double.MaxValue;
if (Neighbors8.ContainsKey(g.VList[i].Id))
{
Neighbor8 = g.VList[Neighbors8[g.VList[i].Id]];
distance8 = Math.Abs(Neighbor8.XLoc - CurrentVertex.XLoc) +
Math.Abs(Neighbor8.YLoc - CurrentVertex.YLoc);
}
//there is a ray that can stop the left ray
if (distance1 == double.MaxValue && distance8 == double.MaxValue)
Neighbor = g.VList[g.N + 2];
else if (distance1 < distance8) Neighbor = Neighbor1;
else Neighbor = Neighbor8;
//check if the neighbor is on the same y line of current vertex
if (CurrentVertex.YLoc == Neighbor.YLoc)
{
//find the left end vertex starting from the neighbor
Vertex leftneighbor;
do
{
leftneighbor = Neighbor;
for (int j = 0; j < g.DegList[Neighbor.Id]; j++)
{
Vertex Candidate = g.VList[g.EList[Neighbor.Id, j].NodeId];
if (Candidate.XLoc < Neighbor.XLoc)
{
Neighbor = Candidate;
break;
}
}
} while (leftneighbor.Id != Neighbor.Id);
if (leftneighbor.XLoc <= CurrentVertex.XLoc) continue;
//no need to find the right neighbor since this is the first time it is growing
//add the edge
g.AddEdge(CurrentVertex.Id, Neighbor.Id);
if (!VHEdges.ContainsKey(CurrentVertex.YLoc))
VHEdges[CurrentVertex.YLoc] = new List<OrthogonalEdge>();
VHEdges[CurrentVertex.YLoc].Add(new OrthogonalEdge(CurrentVertex, Neighbor));
}
else
{
//check if the right ray already hits a vertical Edge r
OrthogonalEdge r = null;
Vertex ClosestVertex = Neighbor;
if (HVEdges.ContainsKey(Neighbor.XLoc))
{
foreach (var vEdge in HVEdges[Neighbor.XLoc])
{
//check if there is an edge already that is blocking, in that case it must be the ray from the neighbor
if (vEdge.a.YLoc <= CurrentVertex.YLoc && vEdge.b.YLoc >= CurrentVertex.YLoc)
{
r = vEdge;
break;
}
//otherwise find the vertex on the line that is the closest one and between the neighbor and current vertex
if (Neighbor.YLoc > CurrentVertex.YLoc &&
Neighbor.YLoc >= vEdge.a.YLoc && vEdge.a.YLoc >= CurrentVertex.YLoc &&
Neighbor.YLoc >= vEdge.b.YLoc && vEdge.b.YLoc >= CurrentVertex.YLoc)
{
if (Math.Abs(vEdge.a.YLoc - CurrentVertex.YLoc) <
Math.Abs(ClosestVertex.YLoc - CurrentVertex.YLoc)) ClosestVertex = vEdge.a;
if (Math.Abs(vEdge.b.YLoc - CurrentVertex.YLoc) <
Math.Abs(ClosestVertex.YLoc - CurrentVertex.YLoc)) ClosestVertex = vEdge.b;
}
else if (Neighbor.YLoc < CurrentVertex.YLoc &&
Neighbor.YLoc <= vEdge.a.YLoc && vEdge.a.YLoc <= CurrentVertex.YLoc &&
Neighbor.YLoc <= vEdge.b.YLoc && vEdge.b.YLoc <= CurrentVertex.YLoc)
{
if (Math.Abs(vEdge.a.YLoc - CurrentVertex.YLoc) <
Math.Abs(ClosestVertex.YLoc - CurrentVertex.YLoc)) ClosestVertex = vEdge.a;
if (Math.Abs(vEdge.b.YLoc - CurrentVertex.YLoc) <
Math.Abs(ClosestVertex.YLoc - CurrentVertex.YLoc)) ClosestVertex = vEdge.b;
}
}
}
if (r != null)
{
a = g.InsertVertexWithDuplicateCheck(Neighbor.XLoc, CurrentVertex.YLoc, locationtoNode);
g.RemoveEdge(r.a.Id, r.b.Id);
g.AddEdge(r.a.Id, a);
g.AddEdge(r.b.Id, a);
g.AddEdge(CurrentVertex.Id, a);
if (!HVEdges.ContainsKey(Neighbor.XLoc))
HVEdges[Neighbor.XLoc] = new List<OrthogonalEdge>();
if (!VHEdges.ContainsKey(CurrentVertex.YLoc))
VHEdges[CurrentVertex.YLoc] = new List<OrthogonalEdge>();
HVEdges[Neighbor.XLoc].Remove(r);
HVEdges[Neighbor.XLoc].Add(new OrthogonalEdge(r.a, g.VList[a]));
HVEdges[Neighbor.XLoc].Add(new OrthogonalEdge(r.b, g.VList[a]));
VHEdges[CurrentVertex.YLoc].Add(new OrthogonalEdge(CurrentVertex, g.VList[a]));
}
else
{
a = g.InsertVertexWithDuplicateCheck(ClosestVertex.XLoc, CurrentVertex.YLoc, locationtoNode);
g.AddEdge(CurrentVertex.Id, a);
g.AddEdge(ClosestVertex.Id, a);
if (!HVEdges.ContainsKey(Neighbor.XLoc))
HVEdges[Neighbor.XLoc] = new List<OrthogonalEdge>();
if (!VHEdges.ContainsKey(CurrentVertex.YLoc))
VHEdges[CurrentVertex.YLoc] = new List<OrthogonalEdge>();
VHEdges[CurrentVertex.YLoc].Add(new OrthogonalEdge(CurrentVertex, g.VList[a]));
HVEdges[ClosestVertex.XLoc].Add(new OrthogonalEdge(ClosestVertex, g.VList[a]));
}
}
}
}
}