private static double EvaluateEdgeLength( [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph, [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm, [NotNull] IReadOnlyDictionary <object, Size> verticesSizes, double idealEdgeLength, double nestingFactor) { double edgeLengthError = 0.0; foreach (IEdge <object> edge in compoundGraph.Edges) { Point uPos = algorithm.VerticesPositions[edge.Source]; Point vPos = algorithm.VerticesPositions[edge.Target]; Size uSize = verticesSizes[edge.Source]; Size vSize = verticesSizes[edge.Target]; Point uPoint = LayoutUtils.GetClippingPoint(uSize, uPos, vPos); Point vPoint = LayoutUtils.GetClippingPoint(vSize, vPos, uPos); double length = (uPoint - vPoint).Length; bool isInterEdge = compoundGraph.GetParent(edge.Source) != compoundGraph.GetParent(edge.Target); double iel = isInterEdge ? idealEdgeLength * (algorithm.LevelOfVertex(edge.Source) + algorithm.LevelOfVertex(edge.Target) + 1) * nestingFactor : idealEdgeLength; double error = Math.Pow(length - iel, 2); edgeLengthError += error; } return(edgeLengthError); }
private static void EvaluateNodeDistances( [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph, [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm, [NotNull] IReadOnlyDictionary <object, Size> verticesSizes, out double minimalMinDistance, out double averageMinDistance, out double maximalMinDistance) { minimalMinDistance = 0.0; averageMinDistance = 0.0; maximalMinDistance = 0.0; foreach (HashSet <object> level in algorithm.Levels) { foreach (object u in level) { double m = double.PositiveInfinity; foreach (object v in level) { if (ReferenceEquals(u, v) || compoundGraph.GetParent(u) != compoundGraph.GetParent(v)) { continue; } Point uPoint = LayoutUtils.GetClippingPoint( verticesSizes[u], algorithm.VerticesPositions[u], algorithm.VerticesPositions[v]); Point vPoint = LayoutUtils.GetClippingPoint( verticesSizes[v], algorithm.VerticesPositions[v], algorithm.VerticesPositions[u]); double distance = (uPoint - vPoint).Length; m = Math.Min(m, distance); } if (double.IsPositiveInfinity(m)) { continue; } minimalMinDistance = Math.Min(minimalMinDistance, m); averageMinDistance += m; maximalMinDistance = Math.Max(maximalMinDistance, m); } } }
private static double EvaluateNodeOverlaps( [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph, [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm, [NotNull] IDictionary <object, Size> verticesSizes) { double overlapArea = 0.0; foreach (HashSet <object> level in algorithm.Levels) { foreach (object u in level) { foreach (object v in level) { if (ReferenceEquals(u, v) || compoundGraph.GetParent(u) != compoundGraph.GetParent(v)) { continue; } Point uPosition = algorithm.VerticesPositions[u]; Point vPosition = algorithm.VerticesPositions[v]; Size uSize = verticesSizes[u]; Size vSize = verticesSizes[v]; var uRect = new Rect(uPosition, uSize); var vRect = new Rect(vPosition, vSize); // Get the overlap size uRect.Intersect(vRect); if (double.IsNegativeInfinity(uRect.Width) || double.IsNegativeInfinity(uRect.Height)) { continue; } overlapArea += uRect.Width * uRect.Height; } } } return(overlapArea); }
public CompoundGraph(ICompoundGraph <TVertex, TEdge> graph) : base(graph.AllowParallelEdges, graph.VertexCount) { //copy the vertices AddVertexRange(graph.Vertices); //copy the containment information foreach (var vertex in graph.Vertices) { if (!graph.IsChildVertex(vertex)) { continue; } var parent = graph.GetParent(vertex); AddChildVertex(parent, vertex); } //copy the edges AddEdgeRange(graph.Edges); }