fixed the build function

This commit is contained in:
Harrison Deng 2018-12-07 11:20:46 -06:00
parent 26a359de46
commit b705b2a457

View File

@ -66,20 +66,20 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
ImageHandler imageHandler;
while (imageHandlerQueue.TryDequeue(out imageHandler))
{
try
Node activeNode = null;
do
{
masterNode.InsertImageHandler(imageHandler);
}
catch (InvalidOperationException)
activeNode = masterNode.InsertImageHandler(imageHandler);
if (activeNode == null)
{
textureLength *= 2;
if (!AutoCorrectAtlasSize || textureLength > Math.Pow(2, powLimit))
if (!AutoCorrectAtlasSize || (textureLength *= 2) > Math.Pow(2, powLimit))
{
throw new InvalidOperationException("Dimensions of texture goes past limit amount of " + powLimit + " which is " + Math.Pow(2, powLimit) + ". New texture size would be " + textureLength + "x" + textureLength + ".");
}
Build();
}
}
while (activeNode == null);
}
}
/// <summary>
@ -105,8 +105,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
public Node childA { get { if (a == null) a = new Node(this); return a; } set { value.parent = this; a = value; } }
public Node childB { get { if (b == null) { b = new Node(this); } return b; } set { value.parent = this; b = value; } }
public Rectangle region;
public ImageHandler imageHandler;
public bool Filled { get { return (imageHandler != null) || (a != null && b != null && a.Filled && b.Filled); } }
public bool containsImage = false;
public bool Filled { get { return containsImage || (a != null && b != null && a.Filled && b.Filled); } }
public Node(Node parent = null)
{
@ -114,21 +114,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
region = parent.region;
}
public void SetNodeRegion(int x, int y, int width, int height, ImageHandler imageHandler)
{
region.X = x;
region.Y = y;
region.Width = width;
region.Height = height;
this.imageHandler = imageHandler;
}
public void SetNodeRegion(ImageHandler imageHandler)
{
SetNodeRegion(imageHandler.x, imageHandler.y, imageHandler.Width, imageHandler.Height, imageHandler);
}
/// <summary>
/// Attempts to insert image within the node. This builds the node to have children if needed.
/// </summary>
/// <param name="imageHandler">the image to insert.</param>
/// <returns>The node the image is placed in.</returns>
public Node InsertImageHandler(ImageHandler imageHandler)
{
if (imageHandler.Width != region.Width)
@ -176,11 +166,10 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
{
imageHandler.x = region.X;
imageHandler.y = region.Y;
this.imageHandler = imageHandler;
containsImage = true;
return this;
}
throw new ArgumentException();
return null;
}
}