[Liblas-commits] hg: remove shared_ptr storage for liblas::Bounds

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jul 26 11:13:00 EDT 2010


changeset afa4400551d6 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=afa4400551d6
summary: remove shared_ptr storage for liblas::Bounds

diffstat:

 include/liblas/lasbounds.hpp |  27 +++++++++++--
 src/lasbounds.cpp            |  83 +++++++++++++++++++++++++++++++++----------
 2 files changed, 85 insertions(+), 25 deletions(-)

diffs (183 lines):

diff -r bc162e944a45 -r afa4400551d6 include/liblas/lasbounds.hpp
--- a/include/liblas/lasbounds.hpp	Sun Jul 25 22:06:57 2010 -0500
+++ b/include/liblas/lasbounds.hpp	Mon Jul 26 10:12:52 2010 -0500
@@ -51,7 +51,6 @@
 #include <vector>
 
 #include <boost/array.hpp>
-#include <boost/shared_ptr.hpp>
 
 namespace liblas
 {
@@ -70,6 +69,8 @@
             double maxy, 
             double minz, 
             double maxz);
+    
+    Bounds( const Point& min, const Point& max);
 
     Bounds( double minx, 
             double miny, 
@@ -78,17 +79,33 @@
     Bounds(Bounds const& other);
     Bounds& operator=(Bounds const& rhs);
     
-    double min(liblas::uint32_t i) const { return (*mins)[i]; }
-    double max(liblas::uint32_t i) const { return (*maxs)[i]; }
+    double min(liblas::uint32_t i) const { return mins[i]; }
+    double max(liblas::uint32_t i) const { return maxs[i]; }
+
+    bool equal(Bounds const& other) const;
+    bool intersects2d(Bounds const& other) const;
+    bool intersects3d(Bounds const& other) const;
     
 private:
-    ArrayPtr mins;
-    ArrayPtr maxs;
+    Array mins;
+    Array maxs;
     
     void verify();
     
 };
 
+template <typename T>
+bool operator==(Bounds const& lhs, Bounds const& rhs)
+{
+    return lhs.equal(rhs);
+}
+
+template <typename T>
+bool operator!=(Bounds const& lhs, Bounds const& rhs)
+{
+    return (!lhs.equal(rhs));
+}
+
 
 
 } // namespace liblas
diff -r bc162e944a45 -r afa4400551d6 src/lasbounds.cpp
--- a/src/lasbounds.cpp	Sun Jul 25 22:06:57 2010 -0500
+++ b/src/lasbounds.cpp	Mon Jul 26 10:12:52 2010 -0500
@@ -49,11 +49,10 @@
 
 
 Bounds::Bounds()
-    : mins(ArrayPtr()), maxs(ArrayPtr())
 {
     for (int i = 0; i < 3; ++i) {
-        (*mins)[i] = 0;
-        (*maxs)[i] = 0;
+        mins[i] = 0;
+        maxs[i] = 0;
     }
 }
 
@@ -63,14 +62,27 @@
                 double maxy, 
                 double minz, 
                 double maxz)
-    : mins(ArrayPtr()), maxs(ArrayPtr())
 {
-    (*mins)[0] = minx;
-    (*mins)[1] = miny;
-    (*mins)[2] = minz;
-    (*maxs)[0] = maxx;
-    (*maxs)[1] = maxy;
-    (*maxs)[2] = maxz;
+    mins[0] = minx;
+    mins[1] = miny;
+    mins[2] = minz;
+    maxs[0] = maxx;
+    maxs[1] = maxy;
+    maxs[2] = maxz;
+    
+#ifdef DEBUG
+    verify();
+#endif
+
+}
+Bounds::Bounds( const Point& min, const Point& max)
+{
+    mins[0] = min.GetX();
+    mins[1] = min.GetY();
+    mins[2] = min.GetZ();
+    maxs[0] = max.GetX();
+    maxs[1] = max.GetY();
+    maxs[2] = max.GetZ();
     
 #ifdef DEBUG
     verify();
@@ -82,14 +94,13 @@
                 double miny, 
                 double maxx, 
                 double maxy)
-    : mins(ArrayPtr(new Array())), maxs(ArrayPtr(new Array()))
 {
-    (*mins)[0] = minx;
-    (*mins)[1] = miny;
-    (*mins)[2] = 0;
-    (*maxs)[0] = maxx;
-    (*maxs)[1] = maxy;
-    (*maxs)[2] = 0;
+    mins[0] = minx;
+    mins[1] = miny;
+    mins[2] = 0;
+    maxs[0] = maxx;
+    maxs[1] = maxy;
+    maxs[2] = 0;
     
 #ifdef DEBUG
     verify();
@@ -118,11 +129,11 @@
 
     for (uint32_t d = 0; d < 3; ++d)
     {
-        if ((*mins)[d] > (*maxs)[d])
+        if (min(d) > max(d) )
         {
             // check for infinitive region
-            if (!((*mins)[d] == std::numeric_limits<double>::max() ||
-                 (*maxs)[d] == -std::numeric_limits<double>::max() ))
+            if (!(min(d) == std::numeric_limits<double>::max() ||
+                 max(d) == -std::numeric_limits<double>::max() ))
             {
                 std::ostringstream msg; 
                 msg << "liblas::Bounds::verify: Minimum point at dimension " << d << 
@@ -135,4 +146,36 @@
 
 }
 
+
+bool Bounds::equal(Bounds const& other) const
+{
+    for (uint32_t i = 0; i < 3; i++) {
+        if (!(min(i) == other.min(i)) && !(max(i) == other.max(i))) 
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
+bool Bounds::intersects2d(Bounds const& other) const
+{
+
+    return ( ( other.min(0) < max(0) && other.min(0) > min(0) &&
+        other.min(1) < max(1) && other.min(1) > max(1) ) ||
+        ( other.max(0) < max(0) && other.max(0) > min(0) &&
+          other.min(1) < max(1) && other.min(1) > max(1) ) ||
+        ( other.min(0) < max(0) && other.min(0) > min(0) &&
+          other.max(1) < max(1) && other.max(1) > max(1) ) ||
+        ( other.max(0) < max(0) && other.max(0) > min(0) &&
+          other.max(1) < max(1) && other.max(1) > max(1) ) );
+
+}
+
+bool Bounds::intersects3d(Bounds const& other) const
+{
+    // not implemented
+    throw    std::runtime_error("not implemented");
+
+}
 } // namespace liblas


More information about the Liblas-commits mailing list