Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2018-07-23 19:29:00 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2018-07-25 18:49:59 +0300
commit845af4ae26f41e86d2db9399420c19ec04b43d05 (patch)
tree6b7c4d696579d9f5b9d304dd7ed7246767244925 /geometry/packer.cpp
parent4e146ec1ed8f8aed0d07ab6f0fe49d067b4c9901 (diff)
[geometry] Coding style fixes.
Diffstat (limited to 'geometry/packer.cpp')
-rw-r--r--geometry/packer.cpp268
1 files changed, 131 insertions, 137 deletions
diff --git a/geometry/packer.cpp b/geometry/packer.cpp
index 183af8d4e8..6b56b86966 100644
--- a/geometry/packer.cpp
+++ b/geometry/packer.cpp
@@ -3,106 +3,122 @@
#include "base/assert.hpp"
#include "base/logging.hpp"
+using namespace std;
+
namespace m2
{
- Packer::Packer()
- : m_currentX(0),
- m_currentY(0),
- m_yStep(0),
- m_width(0),
- m_height(0),
- m_currentHandle(0),
- m_maxHandle(0),
- m_invalidHandle(0x00FFFFFF)
- {}
-
- Packer::Packer(unsigned width, unsigned height, uint32_t maxHandle)
- : m_currentX(0),
- m_currentY(0),
- m_yStep(0),
- m_width(width),
- m_height(height),
- m_currentHandle(0),
- m_maxHandle(maxHandle),
- m_invalidHandle(0x00FFFFFF)
- {
- }
-
- uint32_t Packer::invalidHandle() const
- {
- return m_invalidHandle;
- }
-
- Packer::handle_t Packer::pack(unsigned width, unsigned height)
- {
- ASSERT(width <= m_width, ());
- ASSERT(height <= m_height, ());
+Packer::Packer()
+ : m_currentX(0)
+ , m_currentY(0)
+ , m_yStep(0)
+ , m_width(0)
+ , m_height(0)
+ , m_currentHandle(0)
+ , m_maxHandle(0)
+ , m_invalidHandle(0x00FFFFFF)
+{
+}
- if ((width > m_width) || (height > m_height))
- return m_invalidHandle;
+Packer::Packer(unsigned width, unsigned height, uint32_t maxHandle)
+ : m_currentX(0)
+ , m_currentY(0)
+ , m_yStep(0)
+ , m_width(width)
+ , m_height(height)
+ , m_currentHandle(0)
+ , m_maxHandle(maxHandle)
+ , m_invalidHandle(0x00FFFFFF)
+{
+}
- /// checking whether there is enough space on X axis
+uint32_t Packer::invalidHandle() const { return m_invalidHandle; }
- if (m_currentX + width > m_width)
- {
- m_currentY += m_yStep;
- m_currentX = 0;
- m_yStep = 0;
- }
+Packer::handle_t Packer::pack(unsigned width, unsigned height)
+{
+ ASSERT(width <= m_width, ());
+ ASSERT(height <= m_height, ());
- /// checking whether there is enough space on Y axis
- if (m_currentY + height > m_height)
- {
- /// texture overflow detected. all packed rects should be forgotten.
- callOverflowFns();
- reset();
- }
- /// check handleOverflow
- if (m_currentHandle == m_maxHandle)
- {
- /// handles overflow detected. all packed rects should be forgotten.
- callOverflowFns();
- reset();
- m_currentHandle = 0;
- }
+ if ((width > m_width) || (height > m_height))
+ return m_invalidHandle;
- /// can pack
- m_yStep = max(height, m_yStep);
- handle_t curHandle = m_currentHandle++;
- m_rects[curHandle] = m2::RectU(m_currentX, m_currentY, m_currentX + width, m_currentY + height);
- m_currentX += width;
+ /// checking whether there is enough space on X axis
- return curHandle;
+ if (m_currentX + width > m_width)
+ {
+ m_currentY += m_yStep;
+ m_currentX = 0;
+ m_yStep = 0;
}
- Packer::handle_t Packer::freeHandle()
+ /// checking whether there is enough space on Y axis
+ if (m_currentY + height > m_height)
{
- if (m_currentHandle == m_maxHandle)
- {
- callOverflowFns();
- reset();
- m_currentHandle = 0;
- }
-
- return m_currentHandle++;
+ /// texture overflow detected. all packed rects should be forgotten.
+ callOverflowFns();
+ reset();
+ }
+ /// check handleOverflow
+ if (m_currentHandle == m_maxHandle)
+ {
+ /// handles overflow detected. all packed rects should be forgotten.
+ callOverflowFns();
+ reset();
+ m_currentHandle = 0;
}
- bool Packer::hasRoom(unsigned width, unsigned height) const
+ /// can pack
+ m_yStep = max(height, m_yStep);
+ handle_t curHandle = m_currentHandle++;
+ m_rects[curHandle] = m2::RectU(m_currentX, m_currentY, m_currentX + width, m_currentY + height);
+ m_currentX += width;
+
+ return curHandle;
+}
+
+Packer::handle_t Packer::freeHandle()
+{
+ if (m_currentHandle == m_maxHandle)
{
- return ((m_width >= width) && (m_height - m_currentY - m_yStep >= height))
- || ((m_width - m_currentX >= width ) && (m_height - m_currentY >= height));
+ callOverflowFns();
+ reset();
+ m_currentHandle = 0;
}
- bool Packer::hasRoom(m2::PointU const * sizes, size_t cnt) const
+ return m_currentHandle++;
+}
+
+bool Packer::hasRoom(unsigned width, unsigned height) const
+{
+ return ((m_width >= width) && (m_height - m_currentY - m_yStep >= height)) ||
+ ((m_width - m_currentX >= width) && (m_height - m_currentY >= height));
+}
+
+bool Packer::hasRoom(m2::PointU const * sizes, size_t cnt) const
+{
+ unsigned currentX = m_currentX;
+ unsigned currentY = m_currentY;
+ unsigned yStep = m_yStep;
+
+ for (unsigned i = 0; i < cnt; ++i)
{
- unsigned currentX = m_currentX;
- unsigned currentY = m_currentY;
- unsigned yStep = m_yStep;
+ unsigned width = sizes[i].x;
+ unsigned height = sizes[i].y;
- for (unsigned i = 0; i < cnt; ++i)
+ if (width <= m_width - currentX)
+ {
+ if (height <= m_height - currentY)
+ {
+ yStep = max(height, yStep);
+ currentX += width;
+ }
+ else
+ return false;
+ }
+ else
{
- unsigned width = sizes[i].x;
- unsigned height = sizes[i].y;
+ currentX = 0;
+ currentY += yStep;
+ yStep = 0;
if (width <= m_width - currentX)
{
@@ -114,70 +130,48 @@ namespace m2
else
return false;
}
- else
- {
- currentX = 0;
- currentY += yStep;
- yStep = 0;
-
- if (width <= m_width - currentX)
- {
- if (height <= m_height - currentY)
- {
- yStep = max(height, yStep);
- currentX += width;
- }
- else
- return false;
- }
- }
}
-
- return true;
}
- bool Packer::isPacked(handle_t handle)
- {
- return m_rects.find(handle) != m_rects.end();
- }
+ return true;
+}
- Packer::find_result_t Packer::find(handle_t handle) const
- {
- rects_t::const_iterator it = m_rects.find(handle);
- std::pair<bool, m2::RectU> res;
- res.first = (it != m_rects.end());
- if (res.first)
- res.second = it->second;
- return res;
- }
+bool Packer::isPacked(handle_t handle) { return m_rects.find(handle) != m_rects.end(); }
- void Packer::remove(handle_t handle)
- {
- m_rects.erase(handle);
- }
+Packer::find_result_t Packer::find(handle_t handle) const
+{
+ rects_t::const_iterator it = m_rects.find(handle);
+ std::pair<bool, m2::RectU> res;
+ res.first = (it != m_rects.end());
+ if (res.first)
+ res.second = it->second;
+ return res;
+}
- void Packer::reset()
- {
- m_rects.clear();
- m_currentX = 0;
- m_currentY = 0;
- m_yStep = 0;
- m_currentHandle = 0;
- }
+void Packer::remove(handle_t handle) { m_rects.erase(handle); }
- void Packer::addOverflowFn(overflowFn fn, int priority)
- {
- m_overflowFns.push(std::pair<size_t, overflowFn>(priority, fn));
- }
+void Packer::reset()
+{
+ m_rects.clear();
+ m_currentX = 0;
+ m_currentY = 0;
+ m_yStep = 0;
+ m_currentHandle = 0;
+}
- void Packer::callOverflowFns()
+void Packer::addOverflowFn(overflowFn fn, int priority)
+{
+ m_overflowFns.push(std::pair<size_t, overflowFn>(priority, fn));
+}
+
+void Packer::callOverflowFns()
+{
+ LOG(LDEBUG, ("Texture|Handles Overflow"));
+ overflowFns handlersCopy = m_overflowFns;
+ while (!handlersCopy.empty())
{
- LOG(LDEBUG, ("Texture|Handles Overflow"));
- overflowFns handlersCopy = m_overflowFns;
- while (!handlersCopy.empty())
- {
- handlersCopy.top().second();
- handlersCopy.pop();
- }
+ handlersCopy.top().second();
+ handlersCopy.pop();
}
}
+} // namespace m2