From 402be30268bbd6930c9f76547f8dab3e304005c3 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Thu, 26 Jul 2018 22:41:10 +0100 Subject: gui: after review of quadtree by msgctl, tougher tests --- gui/quadtree.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'gui') 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 res; root_.get(x, y, res); - return std::move(res); + return res; } }; -- cgit v1.2.3