Exemple #1
0
        private int CountCrossings()
        {
            // Initialize
            foreach (GraphNode node in _graph.Nodes)
            {
                SpringVertexData data = (SpringVertexData)node.GetData(_SpringVertex);
                data.Crossings = 0;
            }
            foreach (GraphLink link in _graph.Links)
            {
                SpringEdgeData data = (SpringEdgeData)link.GetData(_SpringEdge);
                data.Crossings = 0;
            }

            foreach (GraphLink link in _graph.Links)
            {
                CountEdgeCrossings(link);
            }

            int crossings = 0;

            foreach (GraphNode node in _graph.Nodes)
            {
                SpringVertexData data = (SpringVertexData)node.GetData(_SpringVertex);
                crossings += data.Crossings;
            }

            return(crossings);
        }
Exemple #2
0
        private void CountEdgeCrossings(GraphLink edge)
        {
            int crossings = 0;

            GraphNode v1 = edge.Origin;
            GraphNode v2 = edge.Destination;

            SpringVertexData v1D = (SpringVertexData)v1.GetData(_SpringVertex);
            SpringVertexData v2D = (SpringVertexData)v2.GetData(_SpringVertex);

            PointF pt = new PointF(0, 0), pt11, pt12, pt21, pt22;

            pt11 = v1.Center;
            pt12 = v2.Center;

            foreach (GraphLink test in _graph.Links)
            {
                if (edge == test)
                {
                    continue;
                }

                pt21 = test.Origin.Center;
                pt22 = test.Destination.Center;
                if (pt11 != pt21 && pt11 != pt22 && pt12 != pt21 && pt12 != pt22)
                {
                    if (new Line(pt11, pt12).IntersectSegment(pt21, pt22).X !=
                        float.PositiveInfinity)
                    {
                        crossings++;
                        v1D.Crossings++;
                        v2D.Crossings++;
                    }
                }
            }

            SpringEdgeData data = (SpringEdgeData)edge.GetData(_SpringEdge);

            data.Crossings = crossings;
        }