Skip to content

Add incremental circle and rectangle packing layouts - #985

Closed
zama9 wants to merge 1 commit into
masterfrom
zama-last-branch
Closed

Add incremental circle and rectangle packing layouts#985
zama9 wants to merge 1 commit into
masterfrom
zama-last-branch

Conversation

@zama9

@zama9 zama9 commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few bad patterns I found which you should check.

public class IncrementalCirclePacker
{
/// <summary>
/// Packs the given list of circles into a container, adjusting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Missing newline at end of file! Files should always end with a single newline character.

Suggested change
}
}

}

/// <summary>
/// A reference to the layout calculated in the previous frame or state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Trailing whitespace detected! Please remove it.

Suggested change
/// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Missing newline at end of file! Files should always end with a single newline character.

Suggested change
}
}

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;
Comment on lines +82 to +89
if (oldLayout != null)
{
lastPositions = oldLayout.lastPositions;
}
else
{
lastPositions = new();
}
Comment on lines +99 to +106
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;
Comment on lines +30 to +36
foreach (TheCircle circle in circles)
{
if (circle.Radius * 2f > maxCircleDiame)
{
maxCircleDiame = circle.Radius * 2f;
}
}
Comment on lines +123 to +132
foreach (ILayoutNode node in layoutNodeList)
{
if (node.IsLeaf)
{

Vector3 scale = node.AbsoluteScale;
layoutResult[node] = new NodeTransform(0, 0, scale);
numberOfLeaves++;
}
}
Comment on lines +187 to +196
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));

}
}
@koschke

koschke commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Replaced by PR #990

@koschke koschke closed this Sep 2, 2026
@koschke
koschke deleted the zama-last-branch branch September 2, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants