]> git.tdb.fi Git - libs/math.git/commitdiff
Some bounding box logic fixes
authorMikko Rasa <tdb@tdb.fi>
Thu, 23 May 2013 09:01:07 +0000 (12:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 23 May 2013 09:01:07 +0000 (12:01 +0300)
source/geometry/boundingbox.h
source/geometry/transformedshape.h

index 120eedbfe9aae581cb09d1a03ee8ebebd5e7676c..ac384ecd19760a5274f8a09bfa3a38adaeff3c81 100644 (file)
@@ -27,7 +27,8 @@ public:
        T get_minimum_coordinate(unsigned i) const { return min_pt[i]; }
        const LinAl::Vector<T, D> &get_maximum_point() const { return max_pt; }
        T get_maximum_coordinate(unsigned i) const { return max_pt[i]; }
-       bool is_empty() const { return empty; }
+       bool is_empty() const { return empty && !negated; }
+       bool is_space() const { return empty && negated; }
        bool is_negated() const { return negated; }
 };
 
@@ -100,8 +101,8 @@ inline BoundingBox<T, D> operator&(const BoundingBox<T, D> &bb1, const BoundingB
        {
                for(unsigned i=0; i<D; ++i)
                {
-                       result_min[i] = std::max(bb1.get_minimum_coordinate(i), bb1.get_minimum_coordinate(i));
-                       result_max[i] = std::min(bb1.get_minimum_coordinate(i), bb1.get_minimum_coordinate(i));
+                       result_min[i] = std::max(bb1.get_minimum_coordinate(i), bb2.get_minimum_coordinate(i));
+                       result_max[i] = std::min(bb1.get_maximum_coordinate(i), bb2.get_maximum_coordinate(i));
                        if(result_min[i]>result_max[i])
                                return BoundingBox<T, D>();
                }
@@ -127,8 +128,8 @@ inline BoundingBox<T, D> operator|(const BoundingBox<T, D> &bb1, const BoundingB
        LinAl::Vector<T, D> result_max;
        for(unsigned i=0; i<D; ++i)
        {
-               result_min[i] = std::min(bb1.get_minimum_coordinate(i), bb1.get_minimum_coordinate(i));
-               result_max[i] = std::max(bb1.get_minimum_coordinate(i), bb1.get_minimum_coordinate(i));
+               result_min[i] = std::min(bb1.get_minimum_coordinate(i), bb2.get_minimum_coordinate(i));
+               result_max[i] = std::max(bb1.get_maximum_coordinate(i), bb2.get_maximum_coordinate(i));
        }
 
        return BoundingBox<T, D>(result_min, result_max);
index 74912aa0b904cf1786c2efb7d78f6ec37c56d6d7..84e182c6cdd5d588245c26fc7e6387ad8829b66c 100644 (file)
@@ -91,7 +91,7 @@ inline BoundingBox<T, D> TransformedShape<T, D>::get_axis_aligned_bounding_box()
                for(unsigned j=0; j<D; ++j)
                {
                        min_pt[j] = std::min(min_pt[j], point[j]);
-                       max_pt[j] = std::max(min_pt[j], point[j]);
+                       max_pt[j] = std::max(max_pt[j], point[j]);
                }
        }