[Liblas-commits] libpc: added some unit tests
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Feb 21 11:59:26 EST 2011
details: http://hg.liblas.orglibpc/rev/0b214b706f0d
changeset: 71:0b214b706f0d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 21 08:58:49 2011 -0800
description:
added some unit tests
Subject: libpc: why?
details: http://hg.liblas.orglibpc/rev/674deb620627
changeset: 72:674deb620627
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 21 08:59:21 2011 -0800
description:
why?
diffstat:
apps/CMakeLists.txt | 5 -
include/libpc/Bounds.hpp | 119 ++++++++++++++++------------------
include/libpc/Range.hpp | 22 +++++-
include/libpc/Vector.hpp | 51 +++-----------
src/ColorFilter.cpp | 4 +-
src/FauxReader.cpp | 13 ++-
src/LasHeader.cpp | 18 ++--
src/LasWriter.cpp | 4 +-
test/unit/BoundsTest.cpp | 96 ++++++++++++++++++++++++++++
test/unit/CMakeLists.txt | 9 ++-
test/unit/RangeTest.cpp | 161 +++++++++++++++++++++++++++++++++++++++++++++++
test/unit/Suite1.cpp | 19 -----
test/unit/Suite2.cpp | 29 --------
test/unit/VectorTest.cpp | 93 +++++++++++++++++++++++++++
test/unit/main.cpp | 7 +-
15 files changed, 471 insertions(+), 179 deletions(-)
diffs (truncated from 1038 to 300 lines):
diff -r 82ffaac465a1 -r 674deb620627 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt Fri Feb 18 11:54:21 2011 -0800
+++ b/apps/CMakeLists.txt Mon Feb 21 08:59:21 2011 -0800
@@ -19,11 +19,6 @@
set(PC2PC pc2pc)
set(PCINFO pcinfo)
-# Set the build type to release if it is not explicitly set by the user and
-# isn't in the cache yet
-if (NOT CMAKE_BUILD_TYPE )
- set(CMAKE_BUILD_TYPE "Release")
-endif()
set(LIBPC_UTILITIES
${PCINFO} ${PC2PC})
diff -r 82ffaac465a1 -r 674deb620627 include/libpc/Bounds.hpp
--- a/include/libpc/Bounds.hpp Fri Feb 18 11:54:21 2011 -0800
+++ b/include/libpc/Bounds.hpp Mon Feb 21 08:59:21 2011 -0800
@@ -60,13 +60,11 @@
template <typename T>
class LIBPC_DLL Bounds
{
-public:
- typedef T value_type;
- typedef typename std::vector< Range<T> >::size_type size_type;
- typedef typename std::vector< Range<T> > RangeVec;
+private:
+ typedef typename std::vector< Range<T> > RangeVector;
private:
- RangeVec m_ranges;
+ RangeVector m_ranges;
public:
Bounds<T>()
@@ -79,7 +77,7 @@
{
}
- Bounds(RangeVec const& ranges)
+ Bounds(RangeVector const& ranges)
:
m_ranges(ranges)
{
@@ -102,9 +100,7 @@
m_ranges[1].setMaximum(maxy);
m_ranges[2].setMaximum(maxz);
-#ifdef DEBUG
- verify();
-#endif
+ assert(verify());
}
@@ -122,10 +118,7 @@
m_ranges[0].setMaximum(maxx);
m_ranges[1].setMaximum(maxy);
-#ifdef DEBUG
- verify();
-#endif
-
+ assert(verify());
}
Bounds(const Vector<T>& minimum, const Vector<T>& maximum)
@@ -136,16 +129,14 @@
for (std::size_t i=0; i<minimum.size(); i++)
{
- m_ranges[i].setMinimum(minimum.getn(i));
- m_ranges[i].setMaximum(maximum.getn(i));
+ m_ranges[i].setMinimum(minimum[i]);
+ m_ranges[i].setMaximum(maximum[i]);
}
- #ifdef DEBUG
- verify();
- #endif
+ assert(verify());
}
- T minimum(std::size_t const& index) const
+ T getMinimum(std::size_t const& index) const
{
if (m_ranges.size() <= index)
{
@@ -155,7 +146,7 @@
// throw std::runtime_error(msg.str());
return 0;
}
- return m_ranges[index].minimum();
+ return m_ranges[index].getMinimum();
}
void setMinimum(std::size_t const& index, T v)
@@ -167,7 +158,7 @@
m_ranges[index].setMinimum(v);
}
- T maximum(std::size_t const& index) const
+ T getMaximum(std::size_t const& index) const
{
if (m_ranges.size() <= index)
{
@@ -177,7 +168,7 @@
// throw std::runtime_error(msg.str());
return 0;
}
- return m_ranges[index].maximum();
+ return m_ranges[index].getMaximum();
}
void setMaximum(std::size_t const& index, T v)
@@ -195,7 +186,7 @@
for (std::size_t i=0; i<m_ranges.size(); i++)
{
- vec.push_back(m_ranges[i].minimum());
+ vec.push_back(m_ranges[i].getMinimum());
}
return Vector<T>(vec);
@@ -207,7 +198,7 @@
for (std::size_t i=0; i<m_ranges.size(); i++)
{
- vec.push_back(m_ranges[i].maximum());
+ vec.push_back(m_ranges[i].getMaximum());
}
return Vector<T>(vec);
@@ -234,30 +225,30 @@
}
/// The vector of Range<T> for the Bounds
- RangeVec const& dims () const
+ RangeVector const& dimensions() const
{
return m_ranges;
}
/// The number of dimensions of the Bounds
- size_type size() const
+ std::size_t size() const
{
return m_ranges.size();
}
- /// Resize the dimensionality of the Bounds to d
- void resize(size_type d)
- {
- if (m_ranges.size() < d)
- {
- m_ranges.resize(d);
- }
- }
+ ///// Resize the dimensionality of the Bounds to d
+ //void resize(size_type d)
+ //{
+ // if (m_ranges.size() < d)
+ // {
+ // m_ranges.resize(d);
+ // }
+ //}
/// Is this Bounds equal to other?
bool equal(Bounds<T> const& other) const
{
- for (size_type i = 0; i < size(); i++)
+ for (std::size_t i = 0; i < size(); i++)
{
if ( m_ranges[i] != other.m_ranges[i] )
return false;
@@ -265,11 +256,11 @@
return true;
}
-/// Does this Bounds intersect other?
+ /// Does this Bounds intersect other?
bool intersects(Bounds const& other) const
{
- for (size_type i = 0; i < size(); i++)
+ for (std::size_t i = 0; i < size(); i++)
{
if ( m_ranges[i].overlaps(other.m_ranges[i]) )
return true;
@@ -291,10 +282,10 @@
if (point.size() != size())
return false;
- for (size_type i = 0; i < size(); i++)
+ for (std::size_t i = 0; i < size(); i++)
{
// As soon as it is not contains, we're false
- if (! m_ranges[i].contains(point.getn(i)) )
+ if (! m_ranges[i].contains(point[i]) )
return false;
}
return true;
@@ -303,7 +294,7 @@
/// Does this Bounds contain other?
bool contains(Bounds<T> const& other) const
{
- for (size_type i = 0; i < size(); i++)
+ for (std::size_t i = 0; i < size(); i++)
{
// As soon as it is not contains, we're false
if (! m_ranges[i].contains(other.m_ranges[i]) )
@@ -315,9 +306,7 @@
/// Shift each dimension by a vector of detlas
void shift(std::vector<T> deltas)
{
- typedef typename std::vector< T >::size_type size_type;
-
- size_type i;
+ std::size_t i;
if( size() <= deltas.size())
{
std::ostringstream msg;
@@ -334,9 +323,7 @@
/// Scale each dimension by a vector of deltas
void scale(std::vector<T> deltas)
{
- typedef typename std::vector< T >::size_type size_type;
-
- size_type i;
+ std::size_t i;
if( size() <= deltas.size())
{
std::ostringstream msg;
@@ -353,8 +340,8 @@
/// Clip this Bounds to the extent of r
void clip(Bounds const& r)
{
- RangeVec ds = r.dims();
- for (size_type i = 0; i < size(); ++i)
+ RangeVector ds = r.dimensions();
+ for (std::size_t i = 0; i < size(); ++i)
{
m_ranges[i].clip(ds[i]);
}
@@ -363,8 +350,8 @@
/// Grow to the union of two liblas::Bounds
void grow(Bounds const& r)
{
- RangeVec ds = r.dims();
- for (size_type i = 0; i < size(); ++i)
+ RangeVector ds = r.dimensions();
+ for (std::size_t i = 0; i < size(); ++i)
{
m_ranges[i].grow(ds[i]);
}
@@ -374,16 +361,16 @@
void grow(Vector<T> const& point)
{
assert(point.size() == size());
- for (size_type i = 0; i < size(); ++i)
+ for (std::size_t i = 0; i < size(); ++i)
{
- m_ranges[i].grow(point.getn(i));
+ m_ranges[i].grow(point[i]);
}
}
T volume() const
{
T output = T();
- for (size_type i = 0; i < size(); i++)
+ for (std::size_t i = 0; i < size(); i++)
{
output = output * m_ranges[i].length();
}
@@ -393,23 +380,30 @@
bool empty() const
{
- for (size_type i = 0; i < size(); i++)
+ if (size()==0)
+ {
+ return true;
+ }
+
+ for (std::size_t i = 0; i < size(); i++)
{
if (m_ranges[i].empty())
+ {
return true;
+ }
}
return false;
}
- void verify()
+ bool verify()
{
- for (size_type d = 0; d < size(); ++d)
+ for (std::size_t d = 0; d < size(); ++d)
More information about the Liblas-commits
mailing list