diff options
| -rw-r--r-- | gui/quadtree.h | 20 | ||||
| -rw-r--r-- | tests/gui/quadtree.cc | 6 | 
2 files changed, 18 insertions, 8 deletions
| diff --git a/gui/quadtree.h b/gui/quadtree.h index 2b5a9df5..f803f770 100644 --- a/gui/quadtree.h +++ b/gui/quadtree.h @@ -61,6 +61,15 @@ class QuadTreeNode                  return false;              return true;          } + +        // Sort the bounding box coordinates. +        void fixup() +        { +            if (x1_ < x0_) +                std::swap(x0_, x1_); +            if (y1_ < y0_) +                std::swap(y0_, y1_); +        }      };    private: @@ -281,7 +290,7 @@ class QuadTreeNode      // Return count of BoundingBoxes/Elements contained.      // @returns count of elements contained. -    size_t size(void) const +    size_t size() const      {          size_t res = elems_.size();          if (children_ != nullptr) { @@ -351,20 +360,21 @@ class QuadTree      // @param k Bounding box at which to store value.      // @param v Value at a given bounding box.      // @returns Whether the insert was succesful. -    bool insert(const BoundingBox &k, ElementT v) +    bool insert(BoundingBox k, ElementT v)      { +        k.fixup();          return root_.insert(k, v);      }      // Dump a human-readable representation of the tree to stdout. -    void dump(void) const +    void dump() const      {          root_.dump(0);      }      // Return count of BoundingBoxes/Elements contained.      // @returns count of elements contained. -    size_t size(void) const +    size_t size() const      {          return root_.size();      } @@ -378,7 +388,7 @@ class QuadTree      {          std::vector<ElementT> res;          root_.get(x, y, res); -        return std::move(res); +        return res;      }  }; diff --git a/tests/gui/quadtree.cc b/tests/gui/quadtree.cc index ca90a426..083a0057 100644 --- a/tests/gui/quadtree.cc +++ b/tests/gui/quadtree.cc @@ -58,7 +58,7 @@ TEST_F(QuadTreeTest, insert_count)      auto rng = NEXTPNR_NAMESPACE::DeterministicRNG();      // Add 10000 random rectangles. -    for (int i = 0; i < 10000; i++) { +    for (unsigned int i = 0; i < 10000; i++) {          int x0 = rng.rng(width_);          int y0 = rng.rng(height_);          int w = rng.rng(width_ - x0); @@ -69,7 +69,7 @@ TEST_F(QuadTreeTest, insert_count)          ASSERT_EQ(qt_->size(), i+1);      }      // Add 100000 random points. -    for (int i = 0; i < 100000; i++) { +    for (unsigned int i = 0; i < 100000; i++) {          int x0 = rng.rng(width_);          int y0 = rng.rng(height_);          int x1 = x0; @@ -113,7 +113,7 @@ TEST_F(QuadTreeTest, insert_retrieve_same)          auto res = qt_->get(x, y);          // Somewhat arbirary test to make sure we don't return obscene          // amounts of data. -        ASSERT_LT(res.size(), 200); +        ASSERT_LT(res.size(), 200UL);          bool found = false;          for (auto elem : res) {              // Is this what we're looking for? | 
