Rect FindPositionForNewNodeContactPoint(int width, int height, ref int bestContactScore)
{
Rect bestNode = new Rect();
bestContactScore = -1;
for (int i = 0; i < freeRectangles.Count; ++i)
{
// Try to place the rectangle in upright (non-flipped) orientation.
if (freeRectangles[i].width >= width && freeRectangles[i].height >= height)
{
int score = ContactPointScoreNode(freeRectangles[i].x, freeRectangles[i].y, width, height);
if (score > bestContactScore)
{
bestNode.x = freeRectangles[i].x;
bestNode.y = freeRectangles[i].y;
bestNode.width = width;
bestNode.height = height;
bestContactScore = score;
}
}
if (freeRectangles[i].width >= height && freeRectangles[i].height >= width)
{
int score = ContactPointScoreNode(freeRectangles[i].x, freeRectangles[i].y, width, height);
if (score > bestContactScore)
{
bestNode.x = freeRectangles[i].x;
bestNode.y = freeRectangles[i].y;
bestNode.width = height;
bestNode.height = width;
bestContactScore = score;
}
}
}
return bestNode;
}