diff options
author | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-26 22:41:10 +0100 |
---|---|---|
committer | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-26 22:41:10 +0100 |
commit | 402be30268bbd6930c9f76547f8dab3e304005c3 (patch) | |
tree | 6b39fea792d8144d89bb9c8f0a9bcfe0171b0ed8 /gui | |
parent | df908374dc233c23aef0790cbce65aa0a58c81ec (diff) | |
download | nextpnr-402be30268bbd6930c9f76547f8dab3e304005c3.tar.gz nextpnr-402be30268bbd6930c9f76547f8dab3e304005c3.tar.bz2 nextpnr-402be30268bbd6930c9f76547f8dab3e304005c3.zip |
gui: after review of quadtree by msgctl, tougher tests
Diffstat (limited to 'gui')
-rw-r--r-- | gui/quadtree.h | 20 |
1 files changed, 15 insertions, 5 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; } }; |