[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jul 15 12:20:33 EDT 2010


changeset 13553eea6159 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=13553eea6159
summary: Assert mark position is lower than cache mask size. Experienced out of range position while running test<15> of lasreader_iterator_test.

changeset f349cf951df7 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=f349cf951df7
summary: Made bbox_calculator a proper copyable functor

diffstat:

 src/detail/reader/reader.cpp          |  14 +++++++++-----
 test/unit/common.hpp                  |  12 +++++++-----
 test/unit/lasreader_iterator_test.cpp |  22 +++++++++++++---------
 3 files changed, 29 insertions(+), 19 deletions(-)

diffs (116 lines):

diff -r 91a7575834d7 -r f349cf951df7 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Thu Jul 15 16:48:56 2010 +0100
+++ b/src/detail/reader/reader.cpp	Thu Jul 15 17:23:59 2010 +0100
@@ -317,15 +317,19 @@
 void CachedReaderImpl::Reset(liblas::Header const& header)
 {
     
-    if (m_mask.size() > 0) {
+    if (!m_mask.empty()) {
 
-    std::vector<uint8_t>::size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
-    std::vector<uint8_t>::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
+        typedef std::vector<uint8_t>::size_type size_type;
+        size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
+        size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
+        size_type to_mark = std::max(m_cache_size, left_to_cache);
 
-    std::vector<uint8_t>::size_type to_mark = std::max(m_cache_size, left_to_cache);
         for (uint32_t i = 0; i < to_mark; ++i) {
 
-            m_mask[m_cache_start_position + i] = 0;
+            size_type const mark_pos = m_cache_start_position + i;
+            assert(mark_pos < m_mask.size());
+
+            m_mask[mark_pos] = 0;
         }
 
         m_cache_start_position = 0;
diff -r 91a7575834d7 -r f349cf951df7 test/unit/common.hpp
--- a/test/unit/common.hpp	Thu Jul 15 16:48:56 2010 +0100
+++ b/test/unit/common.hpp	Thu Jul 15 17:23:59 2010 +0100
@@ -37,10 +37,11 @@
 // Functor to calculate bounding box of a set of points
 struct bbox_calculator
 {
-    // bbox object will store operation result
-    bbox_calculator(liblas::detail::Extents<double>& bbox)
-        : empty(true), bbox(bbox)
-    {}
+    typedef liblas::detail::Extents<double> result_type;
+
+    bbox_calculator() : empty(true) {}
+
+    result_type get_result() const { return bbox; }    
 
     void operator()(liblas::Point const& p)
     {
@@ -62,8 +63,9 @@
         bbox.max.z = std::max(bbox.max.z, p.GetZ());
     }
 
+
     bool empty;
-    liblas::detail::Extents<double>& bbox;
+    liblas::detail::Extents<double> bbox;
 };
 
 // Common test procedure for default constructed point data.
diff -r 91a7575834d7 -r f349cf951df7 test/unit/lasreader_iterator_test.cpp
--- a/test/unit/lasreader_iterator_test.cpp	Thu Jul 15 16:48:56 2010 +0100
+++ b/test/unit/lasreader_iterator_test.cpp	Thu Jul 15 17:23:59 2010 +0100
@@ -204,8 +204,9 @@
         lasreader_iterator it(reader_); // move to 1st point
         lasreader_iterator end;
 
-        lasreader_iterator::difference_type const d = std::distance(it, end);
-        ensure_equals(d, cnt);
+        typedef lasreader_iterator::difference_type difference_type;
+        difference_type const d = std::distance(it, end);
+        ensure_equals(d, static_cast<difference_type>(cnt));
     }
 
     // Test std::distance operation
@@ -213,13 +214,15 @@
     template<>
     void to::test<15>()
     {
-        std::size_t a = std::distance(lasreader_iterator(reader_), lasreader_iterator());
+        typedef lasreader_iterator::difference_type difference_type;
+        
+        difference_type a = std::distance(lasreader_iterator(reader_), lasreader_iterator());
 
         // Reader state is set to "past-the-end-of-file"
         // So, reset is needed
         reader_.Reset();
 
-        std::size_t b = std::distance(lasreader_iterator(reader_), lasreader_iterator());
+        difference_type b = std::distance(lasreader_iterator(reader_), lasreader_iterator());
 
         ensure_equals(a, b);
     }
@@ -284,8 +287,9 @@
         lasreader_iterator end;
 
         // Count records equal to given point object
-        lasreader_iterator::difference_type const expected = 1;
-        lasreader_iterator::difference_type n = std::count(it, end, pt);
+        typedef lasreader_iterator::difference_type difference_type;
+        difference_type const expected = 1;
+        difference_type n = std::count(it, end, pt);
         ensure_equals(n, expected);
     }
 
@@ -382,9 +386,9 @@
                        point_t(h.GetMaxX(), h.GetMaxY(), h.GetMaxZ()));
 
         // Accumulate points extents to common bounding box
-        bbox_t bbox;
-        std::for_each(it, end, bbox_calculator(bbox));
+        bbox_calculator calculator;
+        std::for_each(it, end, calculator);
 
-        ensure(lasbbox == bbox);
+        ensure(lasbbox == calculator.get_result());
     }
 }


More information about the Liblas-commits mailing list