26template <
typename POINT>
62 "QuadTree(): lower left: ({:f},{:f},{:f}), upper right: "
63 "({:f},{:f},{:f}), depth: {:d}",
92 if ((*pnt)[0] <
_ll[0])
96 if ((*pnt)[0] >=
_ur[0])
100 if ((*pnt)[1] <
_ll[1])
104 if ((*pnt)[1] >=
_ur[1])
113 {
return child->addPoint(pnt); });
117 bool pnt_in_quadtree(
false);
118 for (std::size_t k(0); k <
_pnts.size() && !pnt_in_quadtree; k++)
120 const double v0((*(
_pnts[k]))[0] - (*pnt)[0]);
121 const double v1((*(
_pnts[k]))[1] - (*pnt)[1]);
122 const double sqr_dist(v0 * v0 + v1 * v1);
123 if (sqr_dist < std::numeric_limits<double>::epsilon())
125 pnt_in_quadtree =
true;
128 if (!pnt_in_quadtree)
130 _pnts.push_back(pnt);
153 std::list<QuadTree<POINT>*> leaf_list;
156 while (!leaf_list.empty())
159 leaf_list.pop_front();
173 if (north_neighbor !=
nullptr)
177 if (north_neighbor->
isLeaf())
179 leaf_list.push_back(north_neighbor);
186 if (west_neighbor !=
nullptr)
190 if (west_neighbor->
isLeaf())
192 leaf_list.push_back(west_neighbor);
199 if (south_neighbor !=
nullptr)
203 if (south_neighbor->
isLeaf())
205 leaf_list.push_back(south_neighbor);
212 if (east_neighbor !=
nullptr)
216 if (east_neighbor->
isLeaf())
218 leaf_list.push_back(east_neighbor);
235 leaf_list.push_back(
this);
241 child->getLeafs(leaf_list);
263 if (pnt[0] <= 0.5 * (
_ur[0] +
_ll[0]))
265 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
278 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
316 child->getMaxDepth(max_depth);
330 return _children[
static_cast<int>(quadrant)];
337 return _children[
static_cast<int>(quadrant)] == tree;
357 if (north_neighbor ==
nullptr)
361 if (north_neighbor->
isLeaf())
363 return north_neighbor;
391 if (south_neighbor ==
nullptr)
395 if (south_neighbor->
isLeaf())
397 return south_neighbor;
425 if (east_neighbor ==
nullptr)
429 if (east_neighbor->
isLeaf())
431 return east_neighbor;
459 if (west_neighbor ==
nullptr)
463 if (west_neighbor->
isLeaf())
465 return west_neighbor;
488 std::size_t max_points_per_leaf)
501 mid_point[0] += (
_ur[0] -
_ll[0]) / 2.0;
502 mid_point[1] += (
_ur[1] -
_ll[1]) / 2.0;
506 POINT h_ll(mid_point), h_ur(mid_point);
516 h_ll[0] = mid_point[0];
518 h_ur[1] = mid_point[1];
524 for (std::size_t j(0); j <
_pnts.size(); j++)
527 for (std::size_t k(0); k < 4 && nfound; k++)
542 if (north_neighbor !=
nullptr)
546 if (!north_neighbor->
isLeaf())
561 if (west_neighbor !=
nullptr)
565 if (!west_neighbor->
isLeaf())
580 if (south_neighbor !=
nullptr)
584 if (!south_neighbor->
isLeaf())
599 if (east_neighbor !=
nullptr)
603 if (!east_neighbor->
isLeaf())
627 std::array<QuadTree<POINT>*, 4>
_children = {
nullptr,
nullptr,
nullptr,
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
QuadTree< POINT > * _father
QuadTree< POINT > * getNorthNeighbor() const
bool isChild(QuadTree< POINT > const *const tree, Quadrant quadrant) const
static bool needToRefine(QuadTree< POINT > const *const node)
QuadTree< POINT > const * getChild(Quadrant quadrant) const
std::array< QuadTree< POINT > *, 4 > _children
QuadTree< POINT > const * getFather() const
std::size_t getDepth() const
void getMaxDepth(std::size_t &max_depth) const
void getLeafs(std::list< QuadTree< POINT > * > &leaf_list)
const std::vector< POINT const * > & getPoints() const
QuadTree< POINT > * getWestNeighbor() const
const std::size_t _max_points_per_leaf
std::vector< POINT const * > _pnts
void getLeaf(const POINT &pnt, POINT &ll, POINT &ur)
QuadTree< POINT > * getSouthNeighbor() const
bool addPoint(POINT const *pnt)
QuadTree< POINT > * getChild(Quadrant quadrant)
QuadTree< POINT > * getEastNeighbor() const
void getSquarePoints(POINT &ll, POINT &ur) const
QuadTree(POINT ll, POINT ur, QuadTree *father, std::size_t depth, std::size_t max_points_per_leaf)
QuadTree(POINT ll, POINT ur, std::size_t max_points_per_leaf)