static int GuessOutputWidth(List<ArrangedSprite> p_sprites)
{
// Gather the widths of all our sprites into a temporary list.
List<int> l_widths = new List<int>();
foreach (ArrangedSprite sprite in p_sprites) {
l_widths.Add(sprite.Width);
}
// Sort the widths into ascending order.
l_widths.Sort();
// Extract the maximum and median widths.
int l_maxWidth = l_widths[l_widths.Count - 1];
int l_medianWidth = l_widths[l_widths.Count / 2];
// Heuristic assumes an NxN grid of median sized sprites.
int width = l_medianWidth * (int)Math.Round(Math.Sqrt(p_sprites.Count));
// Make sure we never choose anything smaller than our largest sprite.
return Math.Max(width, l_maxWidth);
}