From 7358817975c4df4bbf34dec4fc963ac22c638239 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Mon, 18 Jan 2016 14:45:23 -0600 Subject: [PATCH 1/2] *BinPack fixes -- disjointRects only defined #ifdef _DEBUG --- src/GuillotineBinPack.cpp | 11 ++++++++++- src/SkylineBinPack.cpp | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/GuillotineBinPack.cpp b/src/GuillotineBinPack.cpp index 5efbbf8a1..57dce4501 100644 --- a/src/GuillotineBinPack.cpp +++ b/src/GuillotineBinPack.cpp @@ -144,7 +144,9 @@ void GuillotineBinPack::Insert(TArray &rects, TArray &dst, bool usedRectangles.Push(newNode); // Check that we're really producing correct packings here. +#ifdef _DEBUG assert(disjointRects.Add(newNode) == true); +#endif } } @@ -355,8 +357,9 @@ Rect GuillotineBinPack::Insert(int width, int height, bool merge, FreeRectChoice usedRectangles.Push(newRect); // Check that we're really producing correct packings here. +#ifdef _DEBUG assert(disjointRects.Add(newRect) == true); - +#endif return newRect; } @@ -442,7 +445,9 @@ Rect GuillotineBinPack::FindPositionForNewNode(int width, int height, FreeRectCh bestNode.height = height; bestScore = INT_MIN; *nodeIndex = i; +#ifdef _DEBUG assert(disjointRects.Disjoint(bestNode)); +#endif break; } // If this is a perfect fit sideways, choose it. @@ -470,7 +475,9 @@ Rect GuillotineBinPack::FindPositionForNewNode(int width, int height, FreeRectCh bestNode.height = height; bestScore = score; *nodeIndex = i; +#ifdef _DEBUG assert(disjointRects.Disjoint(bestNode)); +#endif } } // Does the rectangle fit sideways? @@ -575,8 +582,10 @@ void GuillotineBinPack::SplitFreeRectAlongAxis(const Rect &freeRect, const Rect if (right.width > 0 && right.height > 0) freeRectangles.Push(right); +#ifdef _DEBUG assert(disjointRects.Disjoint(bottom)); assert(disjointRects.Disjoint(right)); +#endif } void GuillotineBinPack::MergeFreeList() diff --git a/src/SkylineBinPack.cpp b/src/SkylineBinPack.cpp index cb0be54e1..d63610370 100644 --- a/src/SkylineBinPack.cpp +++ b/src/SkylineBinPack.cpp @@ -69,7 +69,9 @@ void SkylineBinPack::Insert(TArray &rects, TArray &dst) int score2; int index; newNode = FindPositionForNewNodeMinWaste(rects[i].width, rects[i].height, score2, score1, index); +#ifdef _DEBUG assert(disjointRects.Disjoint(newNode)); +#endif if (newNode.height != 0) { if (score1 < bestScore1 || (score1 == bestScore1 && score2 < bestScore2)) @@ -87,8 +89,8 @@ void SkylineBinPack::Insert(TArray &rects, TArray &dst) return; // Perform the actual packing. - assert(disjointRects.Disjoint(bestNode)); #ifdef _DEBUG + assert(disjointRects.Disjoint(bestNode)); disjointRects.Add(bestNode); #endif AddSkylineLevel(bestSkylineIndex, bestNode); @@ -103,7 +105,9 @@ Rect SkylineBinPack::Insert(int width, int height) // First try to pack this rectangle into the waste map, if it fits. Rect node = wasteMap.Insert(width, height, true, GuillotineBinPack::RectBestShortSideFit, GuillotineBinPack::SplitMaximizeArea); +#ifdef _DEBUG assert(disjointRects.Disjoint(node)); +#endif if (node.height != 0) { @@ -113,8 +117,8 @@ Rect SkylineBinPack::Insert(int width, int height) newNode.width = node.width; newNode.height = node.height; usedSurfaceArea += width * height; - assert(disjointRects.Disjoint(newNode)); #ifdef _DEBUG + assert(disjointRects.Disjoint(newNode)); disjointRects.Add(newNode); #endif return newNode; @@ -190,7 +194,9 @@ void SkylineBinPack::AddWasteMapArea(int skylineNodeIndex, int width, int height waste.width = rightSide - leftSide; waste.height = y - skyLine[skylineNodeIndex].y; +#ifdef _DEBUG assert(disjointRects.Disjoint(waste)); +#endif wasteMap.GetFreeRectangles().Push(waste); } } @@ -264,7 +270,9 @@ Rect SkylineBinPack::InsertBottomLeft(int width, int height) if (bestIndex != -1) { +#ifdef _DEBUG assert(disjointRects.Disjoint(newNode)); +#endif // Perform the actual packing. AddSkylineLevel(bestIndex, newNode); @@ -300,7 +308,9 @@ Rect SkylineBinPack::FindPositionForNewNodeBottomLeft(int width, int height, int newNode.y = y; newNode.width = width; newNode.height = height; +#ifdef _DEBUG assert(disjointRects.Disjoint(newNode)); +#endif } } /* if (RectangleFits(i, height, width, y)) @@ -331,7 +341,9 @@ Rect SkylineBinPack::InsertMinWaste(int width, int height) if (bestIndex != -1) { +#ifdef _DEBUG assert(disjointRects.Disjoint(newNode)); +#endif // Perform the actual packing. AddSkylineLevel(bestIndex, newNode); @@ -369,7 +381,9 @@ Rect SkylineBinPack::FindPositionForNewNodeMinWaste(int width, int height, int & newNode.y = y; newNode.width = width; newNode.height = height; +#ifdef _DEBUG assert(disjointRects.Disjoint(newNode)); +#endif } } /* if (RectangleFits(i, height, width, y, wastedArea)) From d94aaf1fcf01abeb3c205a4ad42417d6d80fdf22 Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Mon, 18 Jan 2016 16:03:37 -0500 Subject: [PATCH 2/2] - Fixed: Undefined negative double to unsigned int conversion in FNodeBuilder::PointToAngle. --- src/nodebuild_utility.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nodebuild_utility.cpp b/src/nodebuild_utility.cpp index 14ab7be58..5eba8b7be 100644 --- a/src/nodebuild_utility.cpp +++ b/src/nodebuild_utility.cpp @@ -76,7 +76,8 @@ angle_t FNodeBuilder::PointToAngle (fixed_t x, fixed_t y) #else // !__APPLE__ || __llvm__ double ang = atan2 (double(y), double(x)); #endif // __APPLE__ && !__llvm__ - return angle_t(ang * rad2bam) << 1; + // Convert to signed first since negative double to unsigned is undefined. + return angle_t(int(ang * rad2bam)) << 1; } void FNodeBuilder::FindUsedVertices (vertex_t *oldverts, int max)