Skip to content

Commit

Permalink
563 Utils, applied Falko's suggestions (style, doc)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschramm authored and falko17 committed Sep 5, 2023
1 parent 20ff02c commit f2388af
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
14 changes: 7 additions & 7 deletions Assets/SEE/Layout/NodeLayouts/IncrementalTreeMap/CorrectArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static bool Correct(IList<Node> nodes, IncrementalTreeMapSetting settings

// adjust the position of slicingSegments
AdjustSliced(nodes, partition1, partition2, slicingSegment);
// recursive adjust the two sub layouts
// recursively adjust the two sub layouts
// since both sublayouts are temporally independent from each other
// the segment that separates these must be considered as border (IsConst = true)
// the segment that separates these must be considered as a border (IsConst = true)
slicingSegment.IsConst = true;
Correct(partition1, settings);
Correct(partition2, settings);
Expand Down Expand Up @@ -205,9 +205,9 @@ private static void AdjustSliced(
/// A gradient decent approach to recalibrate the layout.
/// This approach 'moves' the segment in several steps, until the desired sizes are realized.
/// In one step it calculates a shift for all segments at once
/// by set up a function that maps the position of the segments to the area of each node,
/// get the derivative of this function
/// and calculate a shift for the segment vector in the direction of the desired size vector.
/// by setting up a function that maps the position of the segments to the area of each node,
/// getting the derivative of this function
/// and calculating a shift for the segment vector in the direction of the desired size vector.
/// </summary>
/// <param name="nodes">nodes with layout</param>
/// <param name="settings">the settings of the incremental tree map layout,
Expand Down Expand Up @@ -248,7 +248,7 @@ private static Matrix<double> JacobianMatrix(
{
int n = nodes.Count;
Matrix<double> matrix = Matrix<double>.Build.Sparse(n, n - 1);
for(int indexNode = 0; indexNode < nodes.Count; indexNode++)
for (int indexNode = 0; indexNode < nodes.Count; indexNode++)
{
Node node = nodes[indexNode];
IDictionary<Direction, Segment> segments = node.SegmentsDictionary();
Expand Down Expand Up @@ -353,4 +353,4 @@ private static bool CheckPositiveLength(IList<Node> nodes)
return nodes.All(node => node.Rectangle.Width > 0 || node.Rectangle.Depth > 0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ private void FlipOnHorizontalSegment(Node lowerNode, Node upperNode)
/// </summary>
private string DebuggerDisplay => "flip " + Node1.ID + " " + Node2.ID + " {clockwise}";
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Segment(bool isConst, bool isVertical)
/// <summary>
/// Is true if the segment is a border of the layout.
/// In most cases that means that <see cref="Side1Nodes"/> or <see cref="Side2Nodes"/> are empty
/// and layout has i.g. 4 const segments.
/// and layout has e.g. 4 const segments.
/// </summary>
public bool IsConst { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ private void StretchUpperOverHorizontal(Node lowerNode, Node upperNode)
/// </summary>
private string DebuggerDisplay => "stretch " + Node1.ID + " " + Node2.ID;
}
}
}
25 changes: 14 additions & 11 deletions Assets/SEE/Layout/NodeLayouts/IncrementalTreeMap/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ namespace SEE.Layout.NodeLayouts.IncrementalTreeMap
internal static class Utils
{
/// <summary>
/// arg max function, returns a item of a collection, that maximizes a function.
/// Returns the item of the given collection that maximizes the given function.
/// </summary>
/// <param name="collection"></param>
/// <param name="eval">function to be maximized</param>
/// <returns></returns>
/// <param name="collection">The collection whose maximum with respect to
/// <paramref name="eval"/> shall be returned</param>
/// <param name="eval">The function to be maximized</param>
/// <returns>Item of <paramref name="collection"/> that maximizes <paramref name="eval"/></returns>
public static T ArgMax<T>(ICollection<T> collection, Func<T, IComparable> eval)
{
IComparable bestVal = collection.Max(eval);
return collection.First(x => eval(x).CompareTo(bestVal) == 0);
}

/// <summary>
/// arg min function, returns a item of a collection, that minimizes a function.
/// Returns the item of the given collection that minimizes the given function.
/// </summary>
/// <param name="collection"></param>
/// <param name="eval">function to be minimized</param>
/// <returns></returns>
/// <param name="collection">The collection whose minimum with respect to
/// <paramref name="eval"/> shall be returned</param>
/// <param name="eval">The function to be minimized</param>
/// <returns>Item of <paramref name="collection"/> that minimizes <paramref name="eval"/></returns>
public static T ArgMin<T>(ICollection<T> collection, Func<T, IComparable> eval)
{
IComparable bestVal = collection.Min(eval);
Expand Down Expand Up @@ -84,7 +85,7 @@ public static IDictionary<string, Node> CloneGraph(IList<Node> nodes)
Rectangle = node.Rectangle.Clone(), DesiredSize = node.DesiredSize
}
);
CloneSegments(nodes, clonesMap);
CloneSegments(from : nodes,to : clonesMap);
return clonesMap;
}

Expand All @@ -97,10 +98,12 @@ public static IDictionary<string, Node> CloneGraph(IList<Node> nodes)
/// <param name="to">dictionary that maps ID to nodes that should get the segment structure</param>
public static void CloneSegments(IEnumerable<Node> from, IDictionary<string, Node> to)
{
HashSet<Segment> segments = from.SelectMany(n => n.SegmentsDictionary().Values).ToHashSet();
IEnumerable<Segment> segments = from.SelectMany(n => n.SegmentsDictionary().Values).Distinct();
foreach (Segment segment in segments)
{
Segment segmentClone = new Segment(segment.IsConst, segment.IsVertical);
// Segment.SidesXNodes must be copied (.ToList()) because else in the case 'from == to'
// it would change the list while iterating over it.
foreach (Node node in segment.Side1Nodes.ToList())
{
to[node.ID].RegisterSegment(segmentClone,
Expand Down
4 changes: 2 additions & 2 deletions Assets/SEE/Layout/NodeLayouts/IncrementalTreeMapLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void SetupNodeLists(
/// with the same id as a node in <paramref name="nodes"/>. The result will contain null
/// if there is a root in the old layout with an equivalent node in <paramref name="nodes"/>
/// </summary>
/// <param name="nodes"></param>
/// <param name="nodes">nodes in this graph</param>
/// <returns>Collection of parent nodes from <see cref="oldLayout"/>.</returns>
private ICollection<ILayoutNode> ParentsInOldGraph(IEnumerable<Node> nodes)
{
Expand Down Expand Up @@ -362,4 +362,4 @@ public override bool UsesEdgesAndSublayoutNodes()
return false;
}
}
}
}

0 comments on commit f2388af

Please sign in to comment.