Rectangle ScoreRectangle(int width, int height, FreeRectangleChoiceHeuristic method, ref int score1, ref int score2) { Rectangle newNode = new Rectangle(); score1 = int.MaxValue; score2 = int.MaxValue; switch (method) { case FreeRectangleChoiceHeuristic.RectangleBestShortSideFit: newNode = FindPositionForNewNodeBestShortSideFit(width, height, ref score1, ref score2); break; case FreeRectangleChoiceHeuristic.RectangleBottomLeftRule: newNode = FindPositionForNewNodeBottomLeft(width, height, ref score1, ref score2); break; case FreeRectangleChoiceHeuristic.RectangleContactPointRule: newNode = FindPositionForNewNodeContactPoint(width, height, ref score1); score1 = -score1; // Reverse since we are minimizing, but for contact point score bigger is better. break; case FreeRectangleChoiceHeuristic.RectangleBestLongSideFit: newNode = FindPositionForNewNodeBestLongSideFit(width, height, ref score2, ref score1); break; case FreeRectangleChoiceHeuristic.RectangleBestAreaFit: newNode = FindPositionForNewNodeBestAreaFit(width, height, ref score1, ref score2); break; } // Cannot fit the current Rectangleangle. if (newNode.Height == 0) { score1 = int.MaxValue; score2 = int.MaxValue; } return(newNode); }
public Rectangle Insert(int width, int height, FreeRectangleChoiceHeuristic method, CancellationToken cancellationToken) { Rectangle newNode = new Rectangle(); int score1 = 0; // Unused in this function. We don't need to know the score after finding the position. int score2 = 0; switch (method) { case FreeRectangleChoiceHeuristic.RectangleBestShortSideFit: newNode = FindPositionForNewNodeBestShortSideFit(width, height, ref score1, ref score2); break; case FreeRectangleChoiceHeuristic.RectangleBottomLeftRule: newNode = FindPositionForNewNodeBottomLeft(width, height, ref score1, ref score2); break; case FreeRectangleChoiceHeuristic.RectangleContactPointRule: newNode = FindPositionForNewNodeContactPoint(width, height, ref score1); break; case FreeRectangleChoiceHeuristic.RectangleBestLongSideFit: newNode = FindPositionForNewNodeBestLongSideFit(width, height, ref score2, ref score1); break; case FreeRectangleChoiceHeuristic.RectangleBestAreaFit: newNode = FindPositionForNewNodeBestAreaFit(width, height, ref score1, ref score2); break; } if (newNode.Height == 0) { return(newNode); } int numRectangleanglesToProcess = freeRectangles.Count; for (int i = 0; i < numRectangleanglesToProcess; ++i) { if (SplitFreeNode(freeRectangles[i], ref newNode)) { freeRectangles.RemoveAt(i); --i; --numRectangleanglesToProcess; } } PruneFreeList(cancellationToken); usedRectangles.Add(newNode); return(newNode); }