public void MsaglDetour()

in GraphLayout/MSAGL/GraphmapsWithMesh/Tiling.cs [945:1062]


        public void MsaglDetour(Dictionary<int, Node> idToNode, bool omit)
        {
            NumOfnodesBeforeDetour = NumOfnodes;

            if(omit) return;
            for (int index = 0; index < N; index++)
            {
                Vertex w = VList[index];
                Vertex[] list = new Vertex[10];
                int separation = 30;
                int neighbor;


#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
                throw new InvalidOperationException();
#else
                int[,] removelist = new int[10, 2];
                int[,] addlist = new int[10, 4];

                int remove = 0;
                int add = 0;
                int newnode = 0;

                for (neighbor = 0; neighbor < DegList[index]; neighbor++)
                {

                    int a = NumOfnodes;
                    Vertex b = VList[EList[index, neighbor].NodeId];



                    if (w.YLoc == b.YLoc && w.XLoc > b.XLoc)
                    {
                        int exists = GetNode(w.XLoc - separation, w.YLoc);
                        if (exists == -1)
                        {
                            VList[a] = new Vertex(w.XLoc - separation, w.YLoc) { Id = a };
                            removelist[remove, 0] = w.Id; removelist[remove, 1] = b.Id; remove++;
                            addlist[add, 0] = w.Id; addlist[add, 1] = a;
                            addlist[add, 2] = b.Id; addlist[add, 3] = a; add++;
                            list[newnode++] = VList[a];
                            NumOfnodes++;
                        }
                        else { list[newnode++] = VList[exists]; }
                    }

                    if (w.YLoc == b.YLoc && w.XLoc < b.XLoc)
                    {
                        int exists = GetNode(w.XLoc + separation, w.YLoc);
                        if (exists == -1)
                        {
                            VList[a] = new Vertex(w.XLoc + separation, w.YLoc) { Id = a };
                            removelist[remove, 0] = w.Id; removelist[remove, 1] = b.Id; remove++;
                            addlist[add, 0] = w.Id; addlist[add, 1] = a;
                            addlist[add, 2] = b.Id; addlist[add, 3] = a; add++;
                            list[newnode++] = VList[a];
                            NumOfnodes++;
                        }
                        else list[newnode++] = VList[exists];
                    }

                    if (w.XLoc == b.XLoc && w.YLoc > b.YLoc)
                    {
                        int exists = GetNode(w.XLoc, w.YLoc - separation);
                        if (exists == -1)
                        {
                            VList[a] = new Vertex(w.XLoc, w.YLoc - separation) { Id = a };
                            removelist[remove, 0] = w.Id; removelist[remove, 1] = b.Id; remove++;
                            addlist[add, 0] = w.Id; addlist[add, 1] = a;
                            addlist[add, 2] = b.Id; addlist[add, 3] = a; add++;
                            list[newnode++] = VList[a];
                            NumOfnodes++;
                        }
                        else list[newnode++] = VList[exists];
                    }

                    if (w.XLoc == b.XLoc && w.YLoc < b.YLoc)
                    {
                        int exists = GetNode(w.XLoc, w.YLoc + separation);
                        if (exists == -1)
                        {
                            VList[a] = new Vertex(w.XLoc, w.YLoc + separation) { Id = a };
                            removelist[remove, 0] = w.Id; removelist[remove, 1] = b.Id; remove++;
                            addlist[add, 0] = w.Id; addlist[add, 1] = a;
                            addlist[add, 2] = b.Id; addlist[add, 3] = a; add++;
                            list[newnode++] = VList[a];
                            NumOfnodes++;
                        }
                        else list[newnode++] = VList[exists];
                    }
                }

                for (int i = 0; i < remove; i++) RemoveEdge(removelist[i, 0], removelist[i, 1]);
                for (int i = 0; i < add; i++)
                {
                    AddEdge(addlist[i, 0], addlist[i, 1], 1, 0);
                    AddEdge(addlist[i, 2], addlist[i, 3]);
                }

                int removeA = 0, removeB = 0;
                for (int i = 0; i < newnode; i++)
                {
                    for (int j = i + 1; j < newnode; j++)
                    {
                        if (list[i] == null || list[j] == null) continue;
                        if (list[i].XLoc == list[j].XLoc || list[i].YLoc == list[j].YLoc) continue;
                        if (AddEdge(list[i].Id, list[j].Id))
                        {
                            removeA = list[i].Id;
                            removeB = list[j].Id;
                        }
                    }
                }
                //remove one edge
                if (removeA + removeB > 0) RemoveEdge(removeA, removeB);
#endif
            }
        }