private static Route GetRoutePoints(LayoutPath layoutPath, LayoutVertexToPointMap vertexCenters) { var sourceRect = vertexCenters.GetRect(layoutPath.PathSource); var targetRect = vertexCenters.GetRect(layoutPath.PathTarget); var routePoints = sourceRect.Center.ToEnumerable() .Concat(layoutPath.InterimVertices.Select(vertexCenters.Get)) .Concat(targetRect.Center.ToEnumerable()); return(new Route(routePoints).AttachToSourceRectAndTargetRect(sourceRect, targetRect)); }
private void CheckThatParentsAreCentered(LayoutVertexToPointMap vertexCenters) { foreach (var vertex in ProperLayoutGraph.Vertices) { if (ProperLayoutGraph.HasPrimaryChildren(vertex)) { var childrenBlockRect = ProperLayoutGraph.GetPrimaryChildren(vertex) .Select(i => Rect2D.CreateFromCenterAndSize(vertexCenters.Get(i), i.Size)) .Union(); if (!vertexCenters.Get(vertex).X.IsEqualWithTolerance(childrenBlockRect.Center.X)) { throw new Exception($"{vertex} is not centered to its children."); } } } }
private LayoutVertexToPointMap CalculateVertexCenters() { CalculateXPositions(); CalculateYPositions(); var vertexCenters = new LayoutVertexToPointMap(); foreach (var layer in Layers) { var yPos = _layerCenterYPositions[layer]; foreach (var vertex in layer) { var xPos = _vertexCenterXPositions[vertex]; var center = new Point2D(xPos, yPos); vertexCenters.Set(vertex, center); } } CheckPostConditions(vertexCenters); return(vertexCenters); }
private void CheckCorrectOrderingAndNoOverlap(LayoutVertexToPointMap vertexCenters) { foreach (var layer in Layers) { for (var i = 0; i < layer.Count - 1; i++) { var vertex1 = layer[i]; var vertex1HalfWidth = vertex1.Width / 2; var vertex1Center = vertexCenters.Get(vertex1).X; var vertex2 = layer[i + 1]; var vertex2HalfWidth = vertex2.Width / 2; var vertex2Center = vertexCenters.Get(vertex2).X; var vertex1RightSide = vertex1Center + vertex1HalfWidth; var vertex2LeftSide = vertex2Center - vertex2HalfWidth; if (vertex1RightSide > vertex2LeftSide) { throw new Exception($"{vertex1} overlaps {vertex2}."); } } } }
private void CheckPostConditions(LayoutVertexToPointMap vertexCenters) { CheckThatParentsAreCentered(vertexCenters); CheckCorrectOrderingAndNoOverlap(vertexCenters); }
private IDictionary <ModelRelationshipId, Route> CalculateEdgeRoutes(LayoutVertexToPointMap newVertexCenters) { return(LayeredLayoutGraph.Edges.ToDictionary(i => i.DiagramConnector.Id, i => GetRoutePoints(i, newVertexCenters))); }