change heuristic to Best Area Fit

pull/1/head
cosmonaut 2022-07-22 12:20:14 -07:00
parent 812d142aa0
commit 943253add1
1 changed files with 6 additions and 6 deletions

View File

@ -226,7 +226,7 @@ RectPackContext* Cram_Internal_InitRectPacker(uint32_t width, uint32_t height)
return context;
}
/* Uses the short side fit heuristic. */
/* Uses the best area fit heuristic. */
/* TODO: make the heuristic configurable? */
void Cram_Internal_Score(
RectPackContext *context,
@ -235,8 +235,8 @@ void Cram_Internal_Score(
PackScoreInfo *scoreInfo
) {
Rect *freeRect;
int32_t areaFit;
int32_t shortestSide;
int32_t longestSide;
int32_t i;
scoreInfo->score = INT32_MAX;
@ -248,13 +248,13 @@ void Cram_Internal_Score(
if (freeRect->w >= width && freeRect->h >= height)
{
areaFit = freeRect->w * freeRect->h - width * height;
shortestSide = Cram_min(freeRect->w - width, freeRect->h - height);
longestSide = Cram_max(freeRect->w - width, freeRect->h - height);
if (shortestSide < scoreInfo->score || (shortestSide == scoreInfo->score && longestSide < scoreInfo->secondaryScore))
if (areaFit < scoreInfo->score || (areaFit == scoreInfo->score && shortestSide < scoreInfo->secondaryScore))
{
scoreInfo->score = shortestSide;
scoreInfo->secondaryScore = longestSide;
scoreInfo->score = areaFit;
scoreInfo->secondaryScore = shortestSide;
scoreInfo->x = freeRect->x;
scoreInfo->y = freeRect->y;
}