int IMutableBidirectionalGraph <TVertex, TEdge> .RemoveInEdgeIf(TVertex v, EdgePredicate <TVertex, TEdge> predicate) { IMutableBidirectionalGraph <TVertex, TEdge> ithis = this; Contract.Requires(v != null); Contract.Requires(predicate != null); Contract.Requires(ithis.ContainsVertex(v)); Contract.Ensures(ithis.ContainsVertex(v)); Contract.Ensures(Enumerable.All(ithis.InEdges(v), e => predicate(e))); Contract.Ensures(Contract.Result <int>() == Contract.OldValue(Enumerable.Count(ithis.InEdges(v), e => predicate(e)))); Contract.Ensures(ithis.InDegree(v) == Contract.OldValue(ithis.InDegree(v)) - Contract.Result <int>()); return(default(int)); }
void IMutableBidirectionalGraph <TVertex, TEdge> .ClearInEdges(TVertex v) { IMutableBidirectionalGraph <TVertex, TEdge> ithis = this; Contract.Requires(v != null); Contract.Requires(ithis.ContainsVertex(v)); Contract.Ensures(ithis.EdgeCount == Contract.OldValue(ithis.EdgeCount) - Contract.OldValue(ithis.InDegree(v))); Contract.Ensures(ithis.InDegree(v) == 0); }
private void PlaceBlock(int modeIndex, LeftRightMode leftRightMode, UpperLowerEdges upperLowerEdges, SugiVertex v) { if (!double.IsNaN(v.HorizontalPositions[modeIndex])) { return; } double delta = Parameters.VertexDistance; v.HorizontalPositions[modeIndex] = 0; Data w = v; do { SugiVertex wVertex = w as SugiVertex; Segment wSegment = w as Segment; if (_sparseCompactionGraph.ContainsVertex(w) && ((leftRightMode == LeftRightMode.Left && _sparseCompactionGraph.InDegree(w) > 0) || (leftRightMode == LeftRightMode.Right && _sparseCompactionGraph.OutDegree(w) > 0))) { var edges = leftRightMode == LeftRightMode.Left ? _sparseCompactionGraph.InEdges(w) : _sparseCompactionGraph.OutEdges(w); foreach (var edge in edges) { SugiVertex u = null; Data pred = leftRightMode == LeftRightMode.Left ? edge.Source : edge.Target; if (pred is SugiVertex) { u = ((SugiVertex)pred).Roots[modeIndex]; } else { var segment = (Segment)pred; u = upperLowerEdges == UpperLowerEdges.Upper ? segment.PVertex.Roots[modeIndex] : segment.QVertex.Roots[modeIndex]; } PlaceBlock(modeIndex, leftRightMode, upperLowerEdges, u); if (v.Sinks[modeIndex] == v) { v.Sinks[modeIndex] = u.Sinks[modeIndex]; } //var xDelta = delta + (v.Roots[modeIndex].BlockWidths[modeIndex] + u.BlockWidths[modeIndex]) / 2.0; var xDelta = delta + ((wVertex != null ? wVertex.Size.Width : 0.0) + ((pred is SugiVertex) ? ((SugiVertex)pred).Size.Width : u.BlockWidths[modeIndex])) / 2.0; if (v.Sinks[modeIndex] != u.Sinks[modeIndex]) { var s = leftRightMode == LeftRightMode.Left ? v.HorizontalPositions[modeIndex] - u.HorizontalPositions[modeIndex] - xDelta : u.HorizontalPositions[modeIndex] - v.HorizontalPositions[modeIndex] - xDelta; u.Sinks[modeIndex].Shifts[modeIndex] = leftRightMode == LeftRightMode.Left ? Math.Min(u.Sinks[modeIndex].Shifts[modeIndex], s) : Math.Max(u.Sinks[modeIndex].Shifts[modeIndex], s); } else { v.HorizontalPositions[modeIndex] = leftRightMode == LeftRightMode.Left ? Math.Max(v.HorizontalPositions[modeIndex], u.HorizontalPositions[modeIndex] + xDelta) : Math.Min(v.HorizontalPositions[modeIndex], u.HorizontalPositions[modeIndex] - xDelta); } } } if (wSegment != null) { w = (upperLowerEdges == UpperLowerEdges.Upper) ? wSegment.QVertex : wSegment.PVertex; } else if (wVertex.Type == VertexTypes.PVertex && upperLowerEdges == UpperLowerEdges.Upper) { w = wVertex.Segment; } else if (wVertex.Type == VertexTypes.QVertex && upperLowerEdges == UpperLowerEdges.Lower) { w = wVertex.Segment; } else { w = wVertex.Aligns[modeIndex]; } } while (w != v); }
private void PlaceBlock( int modeIndex, LeftRightMode leftRightMode, UpperLowerEdges upperLowerEdges, [NotNull] SugiVertex v) { if (!double.IsNaN(v.SlicePositions[modeIndex])) { return; } double delta = Parameters.SliceGap; v.SlicePositions[modeIndex] = 0; Data w = v; do { var wVertex = w as SugiVertex; var wSegment = w as Segment; if (_sparseCompactionGraph.ContainsVertex(w) && (leftRightMode == LeftRightMode.Left && _sparseCompactionGraph.InDegree(w) > 0 || leftRightMode == LeftRightMode.Right && _sparseCompactionGraph.OutDegree(w) > 0)) { IEnumerable <IEdge <Data> > edges = leftRightMode == LeftRightMode.Left ? _sparseCompactionGraph.InEdges(w) : _sparseCompactionGraph.OutEdges(w); foreach (IEdge <Data> edge in edges) { SugiVertex u; Data predecessor = leftRightMode == LeftRightMode.Left ? edge.Source : edge.Target; if (predecessor is SugiVertex vertex) { u = vertex.Roots[modeIndex]; } else { var segment = (Segment)predecessor; u = upperLowerEdges == UpperLowerEdges.Upper ? segment.PVertex.Roots[modeIndex] : segment.QVertex.Roots[modeIndex]; } PlaceBlock(modeIndex, leftRightMode, upperLowerEdges, u); if (v.Sinks[modeIndex] == v) { v.Sinks[modeIndex] = u.Sinks[modeIndex]; } double xDelta = delta + ( (wVertex?.Size.Width ?? 0.0) + (predecessor is SugiVertex sugiVertex ? sugiVertex.Size.Width : u.BlockWidths[modeIndex]) ) / 2.0; if (v.Sinks[modeIndex] != u.Sinks[modeIndex]) { double s = leftRightMode == LeftRightMode.Left ? v.SlicePositions[modeIndex] - u.SlicePositions[modeIndex] - xDelta : u.SlicePositions[modeIndex] - v.SlicePositions[modeIndex] - xDelta; u.Sinks[modeIndex].Shifts[modeIndex] = leftRightMode == LeftRightMode.Left ? Math.Min(u.Sinks[modeIndex].Shifts[modeIndex], s) : Math.Max(u.Sinks[modeIndex].Shifts[modeIndex], s); } else { v.SlicePositions[modeIndex] = leftRightMode == LeftRightMode.Left ? Math.Max(v.SlicePositions[modeIndex], u.SlicePositions[modeIndex] + xDelta) : Math.Min(v.SlicePositions[modeIndex], u.SlicePositions[modeIndex] - xDelta); } } } if (wSegment != null) { w = upperLowerEdges == UpperLowerEdges.Upper ? wSegment.QVertex : wSegment.PVertex; } // ReSharper disable once PossibleNullReferenceException // Justification: If not a segment then it's a vertex else if (wVertex.Type == VertexTypes.PVertex && upperLowerEdges == UpperLowerEdges.Upper) { w = wVertex.Segment; } else if (wVertex.Type == VertexTypes.QVertex && upperLowerEdges == UpperLowerEdges.Lower) { w = wVertex.Segment; } else { w = wVertex.Aligns[modeIndex]; } } while (w != v); }