private bool Intersect(LayerEdge e, LayerEdge m) {
     return (layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0;
 }
        //[System.Diagnostics.Conditional("DEBUGGLEE")]
        //private void TestYXLayers(LayerArrays layerArrays, int[] xLayers) {
        //    foreach (IntEdge e in this.xLayoutGraph.Edges) {
        //        int s = e.Source; int targ = e.Target;
        //        if (e.Source >= layeredGraph.Nodes.Count) {
        //            if (xLayoutGraph.OutEdges(s).Count != 2 || xLayoutGraph.InEdges(s).Count != 0)
        //                Report("must be two out edges and none incoming");

        //            if (targ >= layeredGraph.Nodes.Count)
        //                Report("an illegal edge");

        //        } else {

        //            if (layerArrays.Y[s] != layerArrays.Y[targ])
        //                Report("layers don't coincide");

        //            if (layerArrays.X[s] - 1 != layerArrays.X[targ])
        //                Report("wrong input");

        //            if (xLayers[s] <= xLayers[targ])
        //                Report("wrong xlayering");

        //        }
        //    }
        //}

        /// <summary>
        /// Creating a proper layered graph, a graph where each 
        /// edge goes only one layer down from the i+1-th layer to the i-th layer.
        /// </summary>
        /// <param name="layering"></param>
        /// <param name="layerArrays"></param>
        void CreaeteProperLayeredGraph(int[] layering, out LayerArrays layerArrays) {
            int n = layering.Length;
            int nOfVV = 0;


            foreach (IntEdge e in database.SkeletonEdges()) {
                int span = EdgeSpan(layering, e);

                Debug.Assert(span >= 0);

                if (span > 0)
                    e.LayerEdges = new LayerEdge[span];
                int pe = 0; //offset in the string

                if (span > 1) {
                   
                    //we create span-2 dummy nodes and span new edges
                    int d0 = n + nOfVV++;
                   
                    var layerEdge = new LayerEdge(e.Source, d0, e.CrossingWeight,e.Weight);

                    e.LayerEdges[pe++] = layerEdge;


                    //create span-2 internal edges all from dummy nodes
                    for (int j = 0; j < span - 2; j++) {
                        d0++;
                        nOfVV++;
                        layerEdge = new LayerEdge(d0 - 1, d0, e.CrossingWeight,e.Weight);
                        e.LayerEdges[pe++] = layerEdge;
                    }

                    layerEdge = new LayerEdge(d0, e.Target, e.CrossingWeight, e.Weight);
                    e.LayerEdges[pe] = layerEdge;
                } else if (span == 1) {
                    var layerEdge = new LayerEdge(e.Source, e.Target, e.CrossingWeight, e.Weight);
                    e.LayerEdges[pe] = layerEdge;
                }
            }

            var extendedVertexLayering = new int[originalGraph.Nodes.Count + nOfVV];

            foreach (IntEdge e in database.SkeletonEdges())
                if (e.LayerEdges != null) {
                    int l = layering[e.Source];
                    extendedVertexLayering[e.Source] = l--;
                    foreach (LayerEdge le in e.LayerEdges)
                        extendedVertexLayering[le.Target] = l--;
                } else {
                    extendedVertexLayering[e.Source] = layering[e.Source];
                    extendedVertexLayering[e.Target] = layering[e.Target];
                }

            properLayeredGraph =
                new ProperLayeredGraph(new BasicGraph<Node, IntEdge>(database.SkeletonEdges(), layering.Length));
            properLayeredGraph.BaseGraph.Nodes = IntGraph.Nodes;
            layerArrays = new LayerArrays(extendedVertexLayering);
        }
 private bool Intersect(LayerEdge e, LayerEdge m) {
     int a = layerArrays.X[e.Source] - layerArrays.X[m.Source];
     int b = layerArrays.X[e.Target] - layerArrays.X[m.Target];
     return a > 0 && b < 0 || a < 0 && b > 0;
     //return (layerArrays.X[e.Source] - layerArrays.X[m.Source]) * (layerArrays.X[e.Target] - layerArrays.X[m.Target]) < 0;
 }
 private void MoveBundledSites(LayerEdge fromEdge, LayerEdge toEdge) {
     MoveBundledEdge(anchors[toEdge.Source].X - anchors[fromEdge.Source].X, anchors[toEdge.Target].X - anchors[fromEdge.Target].X);
 }
 private void MarkEdge(LayerEdge ie) {
     this.markedEdges.Insert(new IntPair(ie.Source, ie.Target));
 }
 int Target(LayerEdge edge) { return BT ? edge.Target : edge.Source; }
 bool IsInnerEdge(LayerEdge e) {
     return IsVirtual(e.Source) && IsVirtual(e.Target);
 }
 int Source(LayerEdge edge) { return BT ? edge.Source : edge.Target; }
        ///// <summary>
        ///// This function marks conflicting edges with targets positioned between innerEdge and newInnerEdge targets.
        ///// </summary>
        ///// <param name="lowerLayer"></param>
        ///// <param name="innerEdge"></param>
        ///// <param name="newInnerEdge"></param>
        ///// <param name="posInnerEdgeTarget"></param>
        ///// <param name="posNewInnerEdgeTarget"></param>
        void MarkEdgesBetweenInnerAndNewInnerEdges(int[] lowerLayer, LayerEdge innerEdge, LayerEdge newInnerEdge,
          int innerEdgeSourcePos, int newInnerEdgeSourcePos) {
            int u = NextRight(Pos(Target(innerEdge)));


            for (; IsLeftFrom(u, Pos(Target(newInnerEdge))); u = NextRight(u)) {
                foreach (LayerEdge ie in InEdges(lowerLayer[u])) {
                    int ieSourcePos = Pos(Source(ie));
                    if (IsLeftFrom(ieSourcePos, innerEdgeSourcePos))//the equality is not possible
                        MarkEdge(ie);
                    else if (IsLeftFrom(newInnerEdgeSourcePos, ieSourcePos))
                        MarkEdge(ie);
                }
            }
        }