Nez.TextureAtlasGenerator.TextureAtlasPacker.guessOutputWidth C# (CSharp) Method

guessOutputWidth() static private method

Heuristic guesses what might be a good output width for a list of sprites.
static private guessOutputWidth ( List sprites ) : int
sprites List
return int
		static int guessOutputWidth( List<ArrangedSprite> sprites )
		{
			// Gather the widths of all our sprites into a temporary list.
			var widths = new List<int>();

			foreach( ArrangedSprite sprite in sprites )
			{
				widths.Add( sprite.width );
			}

			// Sort the widths into ascending order.
			widths.Sort();

			// Extract the maximum and median widths.
			var maxWidth = widths[widths.Count - 1];
			var medianWidth = widths[widths.Count / 2];

			// Heuristic assumes an NxN grid of median sized sprites.
			var width = medianWidth * (int)Math.Round( Math.Sqrt( sprites.Count ) );

			// Make sure we never choose anything smaller than our largest sprite.
			return Math.Max( width, maxWidth );
		}