Add incremental circle and rectangle packing layouts - #985
Conversation
| public class IncrementalCirclePacker | ||
| { | ||
| /// <summary> | ||
| /// Packs the given list of circles into a container, adjusting |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// Packs the given list of circles into a container, adjusting | |
| /// Packs the given list of circles into a container, adjusting |
| } | ||
|
|
||
| /// <summary> | ||
| /// Performs the packing of circles based on their last known positions, |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// Performs the packing of circles based on their last known positions, | |
| /// Performs the packing of circles based on their last known positions, |
| } | ||
|
|
||
| /// <summary> | ||
| /// Packs the given list of circles into a container, |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// Packs the given list of circles into a container, | |
| /// Packs the given list of circles into a container, |
| } | ||
|
|
||
| /// <summary> | ||
| /// Computes the smallest circle that can surround all the given circles, |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// Computes the smallest circle that can surround all the given circles, | |
| /// Computes the smallest circle that can surround all the given circles, |
| return best; | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Warning
Missing newline at end of file! Files should always end with a single newline character.
| } | |
| } | |
| } | ||
|
|
||
| /// <summary> | ||
| /// A reference to the layout calculated in the previous frame or state. |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// A reference to the layout calculated in the previous frame or state. | |
| /// A reference to the layout calculated in the previous frame or state. |
| /// <summary> | ||
| /// A reference to the layout calculated in the previous frame or state. | ||
| /// This is strictly required for the "incremental" aspect of the layout, as the algorithm | ||
| /// uses the positions from this old layout to try and keep nodes as close to their previous |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// uses the positions from this old layout to try and keep nodes as close to their previous | |
| /// uses the positions from this old layout to try and keep nodes as close to their previous |
| public IncrementalRectanglePackingLayout oldLayout; | ||
|
|
||
| /// <summary> | ||
| /// Implements the IIncrementalNodeLayout interface property. Provides a safe setter to |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// Implements the IIncrementalNodeLayout interface property. Provides a safe setter to | |
| /// Implements the IIncrementalNodeLayout interface property. Provides a safe setter to |
|
|
||
| /// <summary> | ||
| /// Implements the IIncrementalNodeLayout interface property. Provides a safe setter to | ||
| /// inject the previous layout instance. It ensures type safety by throwing an ArgumentException |
There was a problem hiding this comment.
Warning
Trailing whitespace detected! Please remove it.
| /// inject the previous layout instance. It ensures type safety by throwing an ArgumentException | |
| /// inject the previous layout instance. It ensures type safety by throwing an ArgumentException |
| } | ||
|
|
||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Warning
Missing newline at end of file! Files should always end with a single newline character.
| } | |
| } | |
| Vector2 dir = c.Center - centerA; | ||
| float dist = dir.magnitude; | ||
|
|
||
| if (dist == 0f) |
| Single minValue = expanders.Values.Min(); | ||
|
|
||
| IEnumerable<KeyValuePair<PNode, float>> candidates = expanders | ||
| .Where(kv => kv.Value == minValue); |
| float distX = bCenterX - aCenterX; | ||
| float distY = bCenterY - aCenterY; | ||
|
|
||
| if (distX == 0f && distY == 0f) distX = 0.01f; |
| float distX = bCenterX - aCenterX; | ||
| float distY = bCenterY - aCenterY; | ||
|
|
||
| if (distX == 0f && distY == 0f) distX = 0.01f; |
| if (oldLayout != null) | ||
| { | ||
| lastPositions = oldLayout.lastPositions; | ||
| } | ||
| else | ||
| { | ||
| lastPositions = new(); | ||
| } |
| if (oldLayout == null) | ||
| { | ||
| lastPositions = new Dictionary<string, (List<(string, Vector2, Vector2)>, Vector2)>(); | ||
| } | ||
| else | ||
| { | ||
| lastPositions = oldLayout.lastPositions; | ||
| } |
| /// A spatial partitioning structure that divides the 2D space into cells. | ||
| /// This drastically reduces collision-check overhead from O(N^2) to near O(N) by only checking adjacent cells. | ||
| /// </summary> | ||
| private SpatialHashGrid _grid; |
| foreach (TheCircle circle in circles) | ||
| { | ||
| if (circle.Radius * 2f > maxCircleDiame) | ||
| { | ||
| maxCircleDiame = circle.Radius * 2f; | ||
| } | ||
| } |
| foreach (ILayoutNode node in layoutNodeList) | ||
| { | ||
| if (node.IsLeaf) | ||
| { | ||
|
|
||
| Vector3 scale = node.AbsoluteScale; | ||
| layoutResult[node] = new NodeTransform(0, 0, scale); | ||
| numberOfLeaves++; | ||
| } | ||
| } |
| foreach (ILayoutNode child in children) | ||
| { | ||
| if (!child.IsLeaf) | ||
| { | ||
| Vector2 childArea = PlaceNodes(layout, child, groundLevel); | ||
| layout[child] = new NodeTransform(0, 0, | ||
| new Vector3(childArea.x, child.AbsoluteScale.y, childArea.y)); | ||
|
|
||
| } | ||
| } |
|
Replaced by PR #990 |
No description provided.