gui: clang-format

This commit is contained in:
Sergiusz Bazanski 2018-07-27 01:22:29 +01:00
parent 0eb40da749
commit 5a7fe84a04
4 changed files with 134 additions and 136 deletions

View File

@ -31,11 +31,9 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
FPGAViewWidget::FPGAViewWidget(QWidget *parent) : FPGAViewWidget::FPGAViewWidget(QWidget *parent)
QOpenGLWidget(parent), ctx_(nullptr), paintTimer_(this), : QOpenGLWidget(parent), ctx_(nullptr), paintTimer_(this), lineShader_(this), zoom_(10.0f),
lineShader_(this), zoom_(10.0f), rendererArgs_(new FPGAViewWidget::RendererArgs), rendererData_(new FPGAViewWidget::RendererData)
rendererArgs_(new FPGAViewWidget::RendererArgs),
rendererData_(new FPGAViewWidget::RendererData)
{ {
colors_.background = QColor("#000000"); colors_.background = QColor("#000000");
colors_.grid = QColor("#333"); colors_.grid = QColor("#333");
@ -126,52 +124,54 @@ float FPGAViewWidget::PickedElement::distance(Context *ctx, float wx, float wy)
// Go over its' GraphicElements, and calculate the distance to them. // Go over its' GraphicElements, and calculate the distance to them.
std::vector<float> distances; std::vector<float> distances;
std::transform(graphics.begin(), graphics.end(), std::back_inserter(distances), [&](const GraphicElement &ge) -> float { std::transform(graphics.begin(), graphics.end(), std::back_inserter(distances),
switch(ge.type) { [&](const GraphicElement &ge) -> float {
case GraphicElement::TYPE_BOX: switch (ge.type) {
{ case GraphicElement::TYPE_BOX: {
// If outside the box, return unit distance to closest border. // If outside the box, return unit distance to closest border.
float outside_x = -1, outside_y = -1; float outside_x = -1, outside_y = -1;
if (dx < ge.x1 || dx > ge.x2) { if (dx < ge.x1 || dx > ge.x2) {
outside_x = std::min(std::abs(dx - ge.x1), std::abs(dx - ge.x2)); outside_x = std::min(std::abs(dx - ge.x1), std::abs(dx - ge.x2));
} }
if (dy < ge.y1 || dy > ge.y2) { if (dy < ge.y1 || dy > ge.y2) {
outside_y = std::min(std::abs(dy - ge.y1), std::abs(dy - ge.y2)); outside_y = std::min(std::abs(dy - ge.y1), std::abs(dy - ge.y2));
} }
if (outside_x != -1 && outside_y != -1) if (outside_x != -1 && outside_y != -1)
return std::min(outside_x, outside_y); return std::min(outside_x, outside_y);
// If in box, return 0. // If in box, return 0.
return 0; return 0;
} }
case GraphicElement::TYPE_LINE: case GraphicElement::TYPE_LINE:
case GraphicElement::TYPE_ARROW: case GraphicElement::TYPE_ARROW: {
{ // Return somewhat primitively calculated distance to segment.
// Return somewhat primitively calculated distance to segment. // TODO(q3k): consider coming up with a better algorithm
// TODO(q3k): consider coming up with a better algorithm QVector2D w(wx, wy);
QVector2D w(wx, wy); QVector2D a(ge.x1, ge.y1);
QVector2D a(ge.x1, ge.y1); QVector2D b(ge.x2, ge.y2);
QVector2D b(ge.x2, ge.y2); float dw = a.distanceToPoint(w) + b.distanceToPoint(w);
float dw = a.distanceToPoint(w) + b.distanceToPoint(w); float dab = a.distanceToPoint(b);
float dab = a.distanceToPoint(b); return std::abs(dw - dab) / dab;
return std::abs(dw-dab) / dab; }
} default:
default: // Not close to antyhing.
// Not close to antyhing. return -1;
return -1; }
} });
});
// Find smallest non -1 distance. // Find smallest non -1 distance.
// Find closest element. // Find closest element.
return *std::min_element(distances.begin(), distances.end(), [&](float a, float b) { return *std::min_element(distances.begin(), distances.end(), [&](float a, float b) {
if (a == -1) return false; if (a == -1)
if (b == -1) return true; return false;
if (b == -1)
return true;
return a < b; return a < b;
}); });
} }
void FPGAViewWidget::renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x, float y) void FPGAViewWidget::renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x,
float y)
{ {
if (el.type == GraphicElement::TYPE_BOX) { if (el.type == GraphicElement::TYPE_BOX) {
auto line = PolyLine(true); auto line = PolyLine(true);
@ -234,15 +234,15 @@ void FPGAViewWidget::populateQuadTree(RendererData *data, const DecalXY &decal,
if (el.type == GraphicElement::TYPE_BOX) { if (el.type == GraphicElement::TYPE_BOX) {
// Boxes are bounded by themselves. // Boxes are bounded by themselves.
data->qt->insert(PickQuadTree::BoundingBox(x+el.x1, y+el.y1, x+el.x2, y+el.y2), element); data->qt->insert(PickQuadTree::BoundingBox(x + el.x1, y + el.y1, x + el.x2, y + el.y2), element);
} }
if (el.type == GraphicElement::TYPE_LINE || el.type == GraphicElement::TYPE_ARROW) { if (el.type == GraphicElement::TYPE_LINE || el.type == GraphicElement::TYPE_ARROW) {
// Lines are bounded by their AABB slightly enlarged. // Lines are bounded by their AABB slightly enlarged.
float x0 = x+el.x1; float x0 = x + el.x1;
float y0 = y+el.y1; float y0 = y + el.y1;
float x1 = x+el.x2; float x1 = x + el.x2;
float y1 = y+el.y2; float y1 = y + el.y2;
if (x1 < x0) if (x1 < x0)
std::swap(x0, x1); std::swap(x0, x1);
if (y1 < y0) if (y1 < y0)
@ -301,7 +301,8 @@ void FPGAViewWidget::paintGL()
// Render Arch graphics. // Render Arch graphics.
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_FRAME], colors_.frame, thick11Px, matrix); lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_FRAME], colors_.frame, thick11Px, matrix);
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_HIDDEN], colors_.hidden, thick11Px, matrix); lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_HIDDEN], colors_.hidden, thick11Px, matrix);
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_INACTIVE], colors_.inactive, thick11Px, matrix); lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_INACTIVE], colors_.inactive, thick11Px,
matrix);
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_ACTIVE], colors_.active, thick11Px, matrix); lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_ACTIVE], colors_.active, thick11Px, matrix);
// Draw highlighted items. // Draw highlighted items.
@ -313,7 +314,7 @@ void FPGAViewWidget::paintGL()
flags = rendererData_->flags; flags = rendererData_->flags;
} }
{ {
QMutexLocker locker(&rendererArgsLock_); QMutexLocker locker(&rendererArgsLock_);
rendererArgs_->flags.clear(); rendererArgs_->flags.clear();
@ -410,7 +411,6 @@ void FPGAViewWidget::renderLines(void)
flags = rendererArgs_->flags; flags = rendererArgs_->flags;
} }
// Render decals if necessary. // Render decals if necessary.
if (decalsChanged) { if (decalsChanged) {
auto data = std::unique_ptr<FPGAViewWidget::RendererData>(new FPGAViewWidget::RendererData); auto data = std::unique_ptr<FPGAViewWidget::RendererData>(new FPGAViewWidget::RendererData);
@ -469,7 +469,7 @@ void FPGAViewWidget::renderLines(void)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
data->gfxHighlighted[i] = rendererData_->gfxHighlighted[i]; data->gfxHighlighted[i] = rendererData_->gfxHighlighted[i];
} }
rendererData_ = std::move(data); rendererData_ = std::move(data);
} }
} }
@ -549,15 +549,16 @@ boost::optional<FPGAViewWidget::PickedElement> FPGAViewWidget::pickElement(float
// Calculate distances to all elements picked. // Calculate distances to all elements picked.
using ElemDist = std::pair<const PickedElement *, float>; using ElemDist = std::pair<const PickedElement *, float>;
std::vector<ElemDist> distances; std::vector<ElemDist> distances;
std::transform(elems.begin(), elems.end(), std::back_inserter(distances), std::transform(elems.begin(), elems.end(), std::back_inserter(distances), [&](const PickedElement &e) -> ElemDist {
[&](const PickedElement &e) -> ElemDist { return std::make_pair(&e, e.distance(ctx_, worldx, worldy));
return std::make_pair(&e, e.distance(ctx_, worldx, worldy)); });
});
// Find closest non -1 element. // Find closest non -1 element.
auto closest = std::min_element(distances.begin(), distances.end(), [&](const ElemDist &a, const ElemDist &b){ auto closest = std::min_element(distances.begin(), distances.end(), [&](const ElemDist &a, const ElemDist &b) {
if (a.second == -1) return false; if (a.second == -1)
if (b.second == -1) return true; return false;
if (b.second == -1)
return true;
return a.second < b.second; return a.second < b.second;
}); });
@ -619,7 +620,6 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event)
update(); update();
} }
// Invert the projection matrix to calculate screen/mouse to world/grid // Invert the projection matrix to calculate screen/mouse to world/grid
// coordinates. // coordinates.
QVector4D FPGAViewWidget::mouseToWorldCoordinates(int x, int y) QVector4D FPGAViewWidget::mouseToWorldCoordinates(int x, int y)
@ -640,8 +640,8 @@ QVector4D FPGAViewWidget::mouseToWorldCoordinates(int x, int y)
// operation properly. // operation properly.
QVector3D ray = vec.toVector3DAffine(); QVector3D ray = vec.toVector3DAffine();
ray.normalize(); ray.normalize();
ray.setX((ray.x()/-ray.z()) * zoom_); ray.setX((ray.x() / -ray.z()) * zoom_);
ray.setY((ray.y()/ray.z()) * zoom_); ray.setY((ray.y() / ray.z()) * zoom_);
ray.setZ(1.0); ray.setZ(1.0);
vec = viewMove_.inverted() * QVector4D(ray.x(), ray.y(), ray.z(), 1.0); vec = viewMove_.inverted() * QVector4D(ray.x(), ray.y(), ray.z(), 1.0);
@ -677,7 +677,6 @@ void FPGAViewWidget::zoom(int level)
zoom_ -= level / 100.0; zoom_ -= level / 100.0;
} else { } else {
zoom_ -= level / 10.0; zoom_ -= level / 10.0;
} }
if (zoom_ < zoomNear_) if (zoom_ < zoomNear_)
@ -708,12 +707,12 @@ void FPGAViewWidget::zoomOutbound()
float h = y1 - y0; float h = y1 - y0;
viewMove_.setToIdentity(); viewMove_.setToIdentity();
viewMove_.translate(-w/2, -h/2); viewMove_.translate(-w / 2, -h / 2);
// Our FOV is π/2, so distance for camera to see a plane of width H is H/2. // Our FOV is π/2, so distance for camera to see a plane of width H is H/2.
// We add 1 unit to cover half a unit of extra space around. // We add 1 unit to cover half a unit of extra space around.
float distance_w = w/2 + 1; float distance_w = w / 2 + 1;
float distance_h = h/2 + 1; float distance_h = h / 2 + 1;
zoom_ = std::max(distance_w, distance_h); zoom_ = std::max(distance_w, distance_h);
update(); update();
} }

View File

@ -20,7 +20,6 @@
#ifndef MAPGLWIDGET_H #ifndef MAPGLWIDGET_H
#define MAPGLWIDGET_H #define MAPGLWIDGET_H
#include <boost/optional.hpp>
#include <QMainWindow> #include <QMainWindow>
#include <QMutex> #include <QMutex>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
@ -32,11 +31,12 @@
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
#include <QWaitCondition> #include <QWaitCondition>
#include <boost/optional.hpp>
#include "designwidget.h"
#include "lineshader.h"
#include "nextpnr.h" #include "nextpnr.h"
#include "quadtree.h" #include "quadtree.h"
#include "lineshader.h"
#include "designwidget.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
@ -108,7 +108,6 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
QSize minimumSizeHint() const override; QSize minimumSizeHint() const override;
QSize sizeHint() const override; QSize sizeHint() const override;
public Q_SLOTS: public Q_SLOTS:
void newContext(Context *ctx); void newContext(Context *ctx);
void onSelectedArchItem(std::vector<DecalXY> decals); void onSelectedArchItem(std::vector<DecalXY> decals);
@ -124,14 +123,16 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
void clickedWire(WireId wire); void clickedWire(WireId wire);
private: private:
const float zoomNear_ = 0.1f; // do not zoom closer than this const float zoomNear_ = 0.1f; // do not zoom closer than this
const float zoomFar_ = 100.0f; // do not zoom further than this const float zoomFar_ = 100.0f; // do not zoom further than this
const float zoomLvl1_ = 1.0f; const float zoomLvl1_ = 1.0f;
const float zoomLvl2_ = 5.0f; const float zoomLvl2_ = 5.0f;
struct PickedElement { struct PickedElement
{
ElementType type; ElementType type;
union Inner { union Inner
{
BelId bel; BelId bel;
WireId wire; WireId wire;
PipId pip; PipId pip;
@ -202,17 +203,14 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
{ {
bool zoomOutbound; bool zoomOutbound;
PassthroughFlags() : PassthroughFlags() : zoomOutbound(false) {}
zoomOutbound(false) {} PassthroughFlags &operator=(const PassthroughFlags &other) noexcept
PassthroughFlags &operator=(const PassthroughFlags &other) noexcept { {
zoomOutbound = other.zoomOutbound; zoomOutbound = other.zoomOutbound;
return *this; return *this;
} }
void clear() void clear() { zoomOutbound = false; }
{
zoomOutbound = false;
}
}; };
struct RendererArgs struct RendererArgs
@ -253,7 +251,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
void renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x, float y); void renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x, float y);
void renderDecal(RendererData *data, LineShaderData &out, const DecalXY &decal); void renderDecal(RendererData *data, LineShaderData &out, const DecalXY &decal);
void renderArchDecal(RendererData *data, const DecalXY &decal); void renderArchDecal(RendererData *data, const DecalXY &decal);
void populateQuadTree(RendererData *data, const DecalXY &decal, const PickedElement& element); void populateQuadTree(RendererData *data, const DecalXY &decal, const PickedElement &element);
boost::optional<PickedElement> pickElement(float worldx, float worldy); boost::optional<PickedElement> pickElement(float worldx, float worldy);
QVector4D mouseToWorldCoordinates(int x, int y); QVector4D mouseToWorldCoordinates(int x, int y);
QVector4D mouseToWorldDimensions(float x, float y); QVector4D mouseToWorldDimensions(float x, float y);

View File

@ -17,8 +17,8 @@
* *
*/ */
#include "log.h"
#include "lineshader.h" #include "lineshader.h"
#include "log.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN

View File

@ -26,14 +26,16 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
// A node of a QuadTree. Internal. // A node of a QuadTree. Internal.
template <typename CoordinateT, typename ElementT> template <typename CoordinateT, typename ElementT> class QuadTreeNode
class QuadTreeNode
{ {
public: public:
class BoundingBox { class BoundingBox
friend class QuadTreeNode; {
friend class QuadTreeNode;
private: private:
CoordinateT x0_, x1_, y0_, y1_; CoordinateT x0_, x1_, y0_, y1_;
public: public:
// Standard constructor for a given (x0,y0), (x1,y1) bounding box // Standard constructor for a given (x0,y0), (x1,y1) bounding box
// //
@ -41,11 +43,11 @@ class QuadTreeNode
// @param y0 y coordinate of top-left corner of box // @param y0 y coordinate of top-left corner of box
// @param x1 x coordinate of bottom-right corner of box // @param x1 x coordinate of bottom-right corner of box
// @param y1 y coordinate of bottom-right corner of box // @param y1 y coordinate of bottom-right corner of box
BoundingBox(CoordinateT x0, CoordinateT y0, CoordinateT x1, CoordinateT y1) : BoundingBox(CoordinateT x0, CoordinateT y0, CoordinateT x1, CoordinateT y1) : x0_(x0), x1_(x1), y0_(y0), y1_(y1)
x0_(x0), x1_(x1), y0_(y0), y1_(y1) {} {
}
BoundingBox(const BoundingBox &other) : BoundingBox(const BoundingBox &other) : x0_(other.x0_), x1_(other.x1_), y0_(other.y0_), y1_(other.y1_) {}
x0_(other.x0_), x1_(other.x1_), y0_(other.y0_), y1_(other.y1_) {}
// Whether a bounding box contains a given points. // Whether a bounding box contains a given points.
// A point is defined to be in a bounding box when it's not lesser than // A point is defined to be in a bounding box when it's not lesser than
@ -74,14 +76,16 @@ class QuadTreeNode
private: private:
// A pair of Element and BoundingBox that contains it. // A pair of Element and BoundingBox that contains it.
class BoundElement { class BoundElement
friend class QuadTreeNode; {
friend class QuadTreeNode;
private: private:
BoundingBox bb_; BoundingBox bb_;
ElementT elem_; ElementT elem_;
public: public:
BoundElement(BoundingBox bb, ElementT elem) : BoundElement(BoundingBox bb, ElementT elem) : bb_(bb), elem_(elem) {}
bb_(bb), elem_(elem) {}
}; };
// The bounding box that this node describes. // The bounding box that this node describes.
@ -103,7 +107,7 @@ class QuadTreeNode
// Depth at which this node is - root is at 0, first level at 1, etc. // Depth at which this node is - root is at 0, first level at 1, etc.
int depth_; int depth_;
// Checks whether a given bounding box fits within this node - used for // Checks whether a given bounding box fits within this node - used for
// sanity checking on insertion. // sanity checking on insertion.
// @param b bounding box to check // @param b bounding box to check
// @returns whether b fits in this node entirely // @returns whether b fits in this node entirely
@ -124,7 +128,8 @@ class QuadTreeNode
// Used to describe one of 5 possible places an element can exist: // Used to describe one of 5 possible places an element can exist:
// - the node itself (THIS) // - the node itself (THIS)
// - any of the 4 children nodes. // - any of the 4 children nodes.
enum Quadrant { enum Quadrant
{
THIS = -1, THIS = -1,
NW = 0, NW = 0,
NE = 1, NE = 1,
@ -175,23 +180,19 @@ class QuadTreeNode
return true; return true;
} }
public: public:
// Standard constructor for node. // Standard constructor for node.
// @param b BoundingBox this node covers. // @param b BoundingBox this node covers.
// @param depth depth at which this node is in the tree // @param depth depth at which this node is in the tree
// @max_elems how many elements should this node contain before it splits // @max_elems how many elements should this node contain before it splits
QuadTreeNode(BoundingBox b, int depth, size_t max_elems = 4) : QuadTreeNode(BoundingBox b, int depth, size_t max_elems = 4) : bound_(b), max_elems_(max_elems), depth_(depth) {}
bound_(b), max_elems_(max_elems), depth_(depth)
{
}
// Disallow copies. // Disallow copies.
QuadTreeNode(const QuadTreeNode &other) = delete; QuadTreeNode(const QuadTreeNode &other) = delete;
QuadTreeNode &operator=(const QuadTreeNode &other) = delete; QuadTreeNode &operator=(const QuadTreeNode &other) = delete;
// Allow moves. // Allow moves.
QuadTreeNode(QuadTreeNode &&other) : QuadTreeNode(QuadTreeNode &&other)
bound_(other.bound_), max_elems_(other.max_elems_), children_(std::move(other.children_)), : bound_(other.bound_), max_elems_(other.max_elems_), children_(std::move(other.children_)),
splitx_(other.splitx_), splity_(other.splity_), elems_(std::move(other.elems_)), depth_(other.depth_) splitx_(other.splitx_), splity_(other.splity_), elems_(std::move(other.elems_)), depth_(other.depth_)
{ {
other.children_ = nullptr; other.children_ = nullptr;
} }
@ -221,14 +222,14 @@ class QuadTreeNode
// Do we have children? // Do we have children?
if (children_ != nullptr) { if (children_ != nullptr) {
// Put the element either recursively into a child if it fits // Put the element either recursively into a child if it fits
// entirely or keep it for ourselves if not. // entirely or keep it for ourselves if not.
auto quad = quadrant(k); auto quad = quadrant(k);
if (quad == THIS) { if (quad == THIS) {
elems_.push_back(BoundElement(k, std::move(v))); elems_.push_back(BoundElement(k, std::move(v)));
} else { } else {
return children_[quad].insert(k, std::move(v)); return children_[quad].insert(k, std::move(v));
} }
} else { } else {
// No children and not about to have any. // No children and not about to have any.
if (!should_split()) { if (!should_split()) {
@ -242,10 +243,17 @@ class QuadTreeNode
children_ = decltype(children_)(new QuadTreeNode<CoordinateT, ElementT>[4] { children_ = decltype(children_)(new QuadTreeNode<CoordinateT, ElementT>[4] {
// Note: not using [NW] = QuadTreeNode because that seems to // Note: not using [NW] = QuadTreeNode because that seems to
// crash g++ 7.3.0. // crash g++ 7.3.0.
/* NW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, bound_.y0_, splitx_, splity_), depth_+1, max_elems_), /* NW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, bound_.y0_, splitx_, splity_),
/* NE */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, bound_.y0_, bound_.x1_, splity_), depth_+1, max_elems_), depth_ + 1, max_elems_),
/* SW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, splity_, splitx_, bound_.y1_), depth_+1, max_elems_), /* NE */
/* SE */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, splity_, bound_.x1_, bound_.y1_), depth_+1, max_elems_), QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, bound_.y0_, bound_.x1_, splity_),
depth_ + 1, max_elems_),
/* SW */
QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, splity_, splitx_, bound_.y1_),
depth_ + 1, max_elems_),
/* SE */
QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, splity_, bound_.x1_, bound_.y1_),
depth_ + 1, max_elems_),
}); });
// Move all elements to where they belong. // Move all elements to where they belong.
auto it = elems_.begin(); auto it = elems_.begin();
@ -271,20 +279,23 @@ class QuadTreeNode
// Dump a human-readable representation of the tree to stdout. // Dump a human-readable representation of the tree to stdout.
void dump(int level) const void dump(int level) const
{ {
for (int i = 0; i < level; i++) printf(" "); for (int i = 0; i < level; i++)
printf(" ");
printf("loc: % 3d % 3d % 3d % 3d\n", bound_.x0_, bound_.y0_, bound_.x1_, bound_.y1_); printf("loc: % 3d % 3d % 3d % 3d\n", bound_.x0_, bound_.y0_, bound_.x1_, bound_.y1_);
if (elems_.size() != 0) { if (elems_.size() != 0) {
for (int i = 0; i < level; i++) printf(" "); for (int i = 0; i < level; i++)
printf(" ");
printf("elems: %zu\n", elems_.size()); printf("elems: %zu\n", elems_.size());
} }
if (children_ != nullptr) { if (children_ != nullptr) {
for (int i = 0; i < level; i++) printf(" "); for (int i = 0; i < level; i++)
printf(" ");
printf("children:\n"); printf("children:\n");
children_[NW].dump(level+1); children_[NW].dump(level + 1);
children_[NE].dump(level+1); children_[NE].dump(level + 1);
children_[SW].dump(level+1); children_[SW].dump(level + 1);
children_[SE].dump(level+1); children_[SE].dump(level + 1);
} }
} }
@ -331,8 +342,7 @@ class QuadTreeNode
// //
// @param CoodinateT scalar type of the coordinate system - int, float, ... // @param CoodinateT scalar type of the coordinate system - int, float, ...
// @param ElementT type of the contained element. Must be movable or copiable. // @param ElementT type of the contained element. Must be movable or copiable.
template <typename CoordinateT, typename ElementT> template <typename CoordinateT, typename ElementT> class QuadTree
class QuadTree
{ {
private: private:
// Root of the tree. // Root of the tree.
@ -348,10 +358,7 @@ class QuadTree
// //
// @param b Bounding box of the entire tree - all comitted elements must // @param b Bounding box of the entire tree - all comitted elements must
// fit within in. // fit within in.
QuadTree(BoundingBox b) : QuadTree(BoundingBox b) : root_(b, 0) {}
root_(b, 0)
{
}
// Inserts a new value at a given bounding box.e // Inserts a new value at a given bounding box.e
// BoundingBoxes are not deduplicated - if two are pushed with the same // BoundingBoxes are not deduplicated - if two are pushed with the same
@ -367,17 +374,11 @@ class QuadTree
} }
// Dump a human-readable representation of the tree to stdout. // Dump a human-readable representation of the tree to stdout.
void dump() const void dump() const { root_.dump(0); }
{
root_.dump(0);
}
// Return count of BoundingBoxes/Elements contained. // Return count of BoundingBoxes/Elements contained.
// @returns count of elements contained. // @returns count of elements contained.
size_t size() const size_t size() const { return root_.size(); }
{
return root_.size();
}
// Retrieve elements whose bounding boxes cover the given coordinates. // Retrieve elements whose bounding boxes cover the given coordinates.
// //