Created
February 22, 2012 19:22
-
-
Save springmeyer/1886759 to your computer and use it in GitHub Desktop.
various asserts to test of hextree conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/SConstruct b/SConstruct | |
index 28d3cb9..78b38b9 100644 | |
--- a/SConstruct | |
+++ b/SConstruct | |
@@ -1412,7 +1412,7 @@ if not preconfigured: | |
# Common debugging flags. | |
debug_flags = '-g -DDEBUG -DMAPNIK_DEBUG' | |
- ndebug_flags = '-DNDEBUG' | |
+ ndebug_flags = '-g3 -ggdb -DDEBUG' | |
# Customizing the C++ compiler flags depending on: | |
diff --git a/include/mapnik/hextree.hpp b/include/mapnik/hextree.hpp | |
index 780c42c..83ea06d 100644 | |
--- a/include/mapnik/hextree.hpp | |
+++ b/include/mapnik/hextree.hpp | |
@@ -38,6 +38,18 @@ | |
#include <algorithm> | |
#include <cmath> | |
+ | |
+#ifndef NDEBUG | |
+#include <cassert> | |
+ | |
+#define ASSERT_EX(condition, statement) \ | |
+ do { \ | |
+ if (!(condition)) { statement; assert(condition); } \ | |
+ } while (false) | |
+#else | |
+#define ASSERT_EX(condition, statement) ((void)0) | |
+#endif | |
+ | |
namespace mapnik { | |
struct RGBAPolicy | |
@@ -70,6 +82,12 @@ class hextree : private boost::noncopyable | |
children_count(0) | |
{ | |
memset(&children_[0],0,sizeof(children_)); | |
+#ifndef NDEBUG | |
+ for (unsigned i = 0; i < 16; ++i) | |
+ { | |
+ ASSERT_EX(children_[i] == 0, std::clog << "'children_[i]==0' i:" << i << " children_[i]:" << children_[i] << "\n"); | |
+ } | |
+#endif | |
} | |
~node () | |
@@ -224,9 +242,11 @@ public: | |
} | |
unsigned idx = InsertPolicy::index_from_level(level,data); | |
+ ASSERT_EX(idx <= 15, std::clog << "'idx<=15' " << idx << "\n"); | |
if (cur_node->children_[idx] == 0) | |
{ | |
cur_node->children_count++; | |
+ ASSERT_EX(cur_node->children_count <= 15, std::clog << "'cur_node->children_count<=15' " << cur_node->children_count << "\n"); | |
cur_node->children_[idx] = new node(); | |
} | |
cur_node = cur_node->children_[idx]; | |
@@ -245,6 +265,7 @@ public: | |
} | |
if (colors_ == 1) | |
{ | |
+ ASSERT_EX(pal_remap_.size() > 2, std::clog << "'pal_remap_.size()>2' " << pal_remap_.size() << "\n"); | |
return pal_remap_[has_holes_?1:0]; | |
} | |
@@ -312,6 +333,8 @@ public: | |
ind = it->second; | |
} | |
+ ASSERT_EX(pal_remap_.size() > 0, std::clog << "'pal_remap_.size() > 0'" << pal_remap_.size() << "\n";); | |
+ ASSERT_EX(ind < pal_remap_.size(), std::clog << "'ind < pal_remap_.size()' " << ind << "<" << pal_remap_.size() << "\n"); | |
return pal_remap_[ind]; | |
} | |
@@ -402,16 +425,24 @@ private: | |
But this could lead to memory corruption | |
*/ | |
- | |
- if (itr->count > 0) | |
+ print_tree(itr); | |
+ int count = itr->count; | |
+ | |
+ ASSERT_EX(count >= 0, std::clog << "'count>=0' " << count << "\n"); | |
+ if (count >= 3) | |
{ | |
- unsigned count = itr->count; | |
- byte a = byte(itr->alphas/float(count)); | |
+ double count_d = static_cast<double>(count); | |
+ byte a = static_cast<byte>(itr->alphas/count_d); | |
if (a > InsertPolicy::MAX_ALPHA) a = 255; | |
if (a < InsertPolicy::MIN_ALPHA) a = 0; | |
- palette.push_back(rgba((byte)round(gamma(itr->reds / count, gamma_)), | |
- (byte)round(gamma(itr->greens / count, gamma_)), | |
- (byte)round(gamma(itr->blues / count, gamma_)), a)); | |
+ byte r(static_cast<byte>(round(gamma(itr->reds/count_d, gamma_)))); | |
+ ASSERT_EX(r > 0 && r <= 255, std::clog << "'r>0 && r<=255' " << r << "\n"); | |
+ byte g(static_cast<byte>(round(gamma(itr->greens/count_d, gamma_)))); | |
+ ASSERT_EX(g > 0 && g <= 255, std::clog << "'g>0 && g<=255' " << g << "\n"); | |
+ byte b(static_cast<byte>(round(gamma(itr->blues/count_d, gamma_)))); | |
+ ASSERT_EX(b > 0 && b <= 255, std::clog << "'b>0 && b<=255' " << b << "\n"); | |
+ rgba clipped(r,g,b,a); | |
+ palette.push_back(clipped); | |
} | |
for (unsigned idx=0; idx < 16; ++idx) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment