/// <inheritdoc />
        public override void Calculate()
        {
            var topLeft     = new Point(double.PositiveInfinity, double.PositiveInfinity);
            var bottomRight = new Point(double.NegativeInfinity, double.NegativeInfinity);

            foreach (TVertex vertex in Graph.Vertices)
            {
                Point pos  = Positions[vertex];
                Size  size = Sizes[vertex];
                topLeft.X = Math.Min(pos.X - size.Width / 2.0, topLeft.X);
                topLeft.Y = Math.Min(pos.Y - size.Height / 2.0, topLeft.Y);

                bottomRight.X = Math.Max(pos.X + size.Width / 2.0, bottomRight.X);
                bottomRight.Y = Math.Max(pos.Y + size.Height / 2.0, bottomRight.Y);
            }

            foreach (TEdge edge in Graph.Edges)
            {
                if (!EdgeRoutes.TryGetValue(edge, out Point[] routePoints) ||
Пример #2
0
        public override void Calculate()
        {
            Point topLeft     = new Point(double.PositiveInfinity, double.PositiveInfinity);
            Point bottomRight = new Point(double.NegativeInfinity, double.NegativeInfinity);

            foreach (var v in Graph.Vertices)
            {
                Point p = Positions[v];
                Size  s = Sizes[v];
                topLeft.X = Math.Min(p.X - s.Width / 2.0, topLeft.X);
                topLeft.Y = Math.Min(p.Y - s.Height / 2.0, topLeft.Y);

                bottomRight.X = Math.Max(p.X + s.Width / 2.0, bottomRight.X);
                bottomRight.Y = Math.Max(p.Y + s.Height / 2.0, bottomRight.Y);
            }

            foreach (var e in Graph.Edges)
            {
                Point[] routePoints = null;
                if (!EdgeRoutes.TryGetValue(e, out routePoints) || routePoints == null || routePoints.Length == 0)
                {
                    continue;
                }

                for (int i = 0; i < routePoints.Length; i++)
                {
                    Point p = routePoints[i];
                    topLeft.X = Math.Min(p.X, topLeft.X);
                    topLeft.Y = Math.Min(p.Y, topLeft.Y);

                    bottomRight.X = Math.Max(p.X, bottomRight.X);
                    bottomRight.Y = Math.Max(p.Y, bottomRight.Y);
                }
            }

            Vector layoutAreaSize = bottomRight - topLeft;

            Area  = layoutAreaSize.LengthSquared;
            Ratio = layoutAreaSize.X / layoutAreaSize.Y;
        }
Пример #3
0
        /// <inheritdoc />
        public override void Calculate()
        {
            TEdge[] edges      = Graph.Edges.ToArray();
            var     edgePoints = new List <Point> [edges.Length];

            // Create the points of the edges
            for (int i = 0; i < edges.Length; ++i)
            {
                TEdge        edge   = edges[i];
                List <Point> points = EdgeRoutes.TryGetValue(edge, out Point[] route) && route != null && route.Length > 0
                    ? new List <Point>(route.Length + 2)
                    : new List <Point>(2);

                points.Add(Positions[edge.Source]);
                if (route != null && route.Length > 0)
                {
                    points.AddRange(route);
                }
                points.Add(Positions[edge.Target]);

                edgePoints[i] = points;

                for (int j = 1; j < points.Count; ++j)
                {
                    double length = (points[j] - points[j - 1]).Length;

                    MinimumEdgeLength  = Math.Min(MinimumEdgeLength, length);
                    MaximumEdgeLength  = Math.Max(MaximumEdgeLength, length);
                    AverageEdgeLength += length;
                }
            }

            // Check the crosses
            for (int i = 0; i < edges.Length - 1; ++i)
            {
                for (int j = i + 1; j < edges.Length; ++j)
                {
                    List <Point> edgePoints1 = edgePoints[i];
                    List <Point> edgePoints2 = edgePoints[j];

                    for (int ii = 0; ii < edgePoints1.Count - 1; ++ii)
                    {
                        Point pA = edgePoints1[ii];
                        Point pB = edgePoints1[ii + 1];

                        for (int jj = 0; jj < edgePoints2.Count - 1; ++jj)
                        {
                            Point pC = edgePoints2[jj];
                            Point pD = edgePoints2[jj + 1];

                            if (pB.Equals(pC) || pA.Equals(pC) || pA.Equals(pD) || pB.Equals(pD))
                            {
                                continue;   // Ignore if source and/or target are the same
                            }
                            // [AB]
                            double xA = pA.X;
                            double yA = pA.Y;
                            double xB = pB.X;
                            double yB = pB.Y;

                            // [CD]
                            double xC = pC.X;
                            double yC = pC.Y;
                            double xD = pD.X;
                            double yD = pD.Y;

                            // The edges crosses each other
                            bool segmentCrossing =
                                ((xC - xA) * (yB - yA) + (yC - yA) * (xA - xB) < 0) ^
                                ((xD - xA) * (yB - yA) + (yD - yA) * (xA - xB) < 0)
                                &&
                                ((xA - xC) * (yD - yC) + (yA - yC) * (xC - xD) < 0) ^
                                ((xB - xC) * (yD - yC) + (yB - yC) * (xC - xD) < 0);

                            if (segmentCrossing)
                            {
                                ++CrossCount;
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public override void Calculate()
        {
            var edges      = Graph.Edges.ToArray();
            var edgePoints = new List <Point> [edges.Length];

            int segmentCount = 0;

            //create the points of the edges
            for (int i = 0; i < edges.Length - 1; i++)
            {
                var          edge   = edges[i];
                Point[]      route  = null;
                List <Point> points = null;
                if (EdgeRoutes.TryGetValue(edge, out route) && route != null && route.Length > 0)
                {
                    points = new List <Point>(route.Length + 2);
                }
                else
                {
                    points = new List <Point>(2);
                }
                points.Add(Positions[edge.Source]);
                if (route != null && route.Length > 0)
                {
                    points.AddRange(route);
                }
                points.Add(Positions[edge.Target]);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    double length = (points[j] - points[j - 1]).Length;

                    MinimumEdgeLength  = Math.Min(MinimumEdgeLength, length);
                    MaximumEdgeLength  = Math.Max(MaximumEdgeLength, length);
                    AverageEdgeLength += length;
                    segmentCount      += 1;
                }
            }

            //check the crosses
            for (int i = 0; i < edges.Length - 1; i++)
            {
                for (int j = i + 1; j < edges.Length; j++)
                {
                    List <Point> edgePoints1 = edgePoints[i];
                    List <Point> edgePoints2 = edgePoints[j];

                    for (int ii = 0; ii < edgePoints1.Count - 1; ii++)
                    {
                        var p11 = edgePoints1[ii];
                        var p12 = edgePoints1[ii + 1];
                        if (p12.X < p11.X)
                        {
                            Point p = p12;
                            p12 = p11;
                            p11 = p;
                        }
                        for (int jj = 0; jj < edgePoints2.Count - 1; jj++)
                        {
                            var p21 = edgePoints2[jj];
                            var p22 = edgePoints2[jj + 1];
                            if (p22.X < p21.X)
                            {
                                Point p = p22;
                                p22 = p21;
                                p21 = p22;
                            }

                            p11.X = p21.X = Math.Max(p11.X, p21.X);
                            p12.X = p22.X = Math.Min(p12.X, p22.X);

                            if ((p11.Y - p21.Y) * (p12.Y - p22.Y) < 0)
                            {
                                //the edges crosses each other
                                CrossCount += 1;

                                Vector v1 = p11 - p12;
                                Vector v2 = p21 - p22;

                                double angle = Math.Acos(Math.Abs((v1.X * v2.X + v1.Y * v2.Y) / (v1.Length * v2.Length)));

                                MinimumAngle  = Math.Min(MinimumAngle, angle);
                                MaximumAngle  = Math.Max(MaximumAngle, angle);
                                AverageAngle += angle;
                            }
                        }
                    }
                }
            }

            AverageAngle      /= segmentCount;
            AverageEdgeLength /= segmentCount;
        }