27template <
typename POINT>
63 "QuadTree(): lower left: ({:f},{:f},{:f}), upper right: "
64 "({:f},{:f},{:f}), depth: {:d}",
93 if ((*pnt)[0] <
_ll[0])
97 if ((*pnt)[0] >=
_ur[0])
101 if ((*pnt)[1] <
_ll[1])
105 if ((*pnt)[1] >=
_ur[1])
114 {
return child->addPoint(pnt); });
118 bool pnt_in_quadtree(
false);
119 for (std::size_t k(0); k <
_pnts.size() && !pnt_in_quadtree; k++)
121 const double v0((*(
_pnts[k]))[0] - (*pnt)[0]);
122 const double v1((*(
_pnts[k]))[1] - (*pnt)[1]);
123 const double sqr_dist(v0 * v0 + v1 * v1);
124 if (sqr_dist < std::numeric_limits<double>::epsilon())
126 pnt_in_quadtree =
true;
129 if (!pnt_in_quadtree)
131 _pnts.push_back(pnt);
154 std::list<QuadTree<POINT>*> leaf_list;
157 while (!leaf_list.empty())
160 leaf_list.pop_front();
174 if (north_neighbor !=
nullptr)
178 if (north_neighbor->
isLeaf())
180 leaf_list.push_back(north_neighbor);
187 if (west_neighbor !=
nullptr)
191 if (west_neighbor->
isLeaf())
193 leaf_list.push_back(west_neighbor);
200 if (south_neighbor !=
nullptr)
204 if (south_neighbor->
isLeaf())
206 leaf_list.push_back(south_neighbor);
213 if (east_neighbor !=
nullptr)
217 if (east_neighbor->
isLeaf())
219 leaf_list.push_back(east_neighbor);
236 leaf_list.push_back(
this);
242 child->getLeafs(leaf_list);
264 if (pnt[0] <= 0.5 * (
_ur[0] +
_ll[0]))
266 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
279 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
317 child->getMaxDepth(max_depth);
331 return _children[
static_cast<int>(quadrant)];
338 return _children[
static_cast<int>(quadrant)] == tree;
358 if (north_neighbor ==
nullptr)
362 if (north_neighbor->
isLeaf())
364 return north_neighbor;
392 if (south_neighbor ==
nullptr)
396 if (south_neighbor->
isLeaf())
398 return south_neighbor;
426 if (east_neighbor ==
nullptr)
430 if (east_neighbor->
isLeaf())
432 return east_neighbor;
460 if (west_neighbor ==
nullptr)
464 if (west_neighbor->
isLeaf())
466 return west_neighbor;
489 std::size_t max_points_per_leaf)
502 mid_point[0] += (
_ur[0] -
_ll[0]) / 2.0;
503 mid_point[1] += (
_ur[1] -
_ll[1]) / 2.0;
507 POINT h_ll(mid_point), h_ur(mid_point);
517 h_ll[0] = mid_point[0];
519 h_ur[1] = mid_point[1];
525 for (std::size_t j(0); j <
_pnts.size(); j++)
528 for (std::size_t k(0); k < 4 && nfound; k++)
543 if (north_neighbor !=
nullptr)
547 if (!north_neighbor->
isLeaf())
562 if (west_neighbor !=
nullptr)
566 if (!west_neighbor->
isLeaf())
581 if (south_neighbor !=
nullptr)
585 if (!south_neighbor->
isLeaf())
600 if (east_neighbor !=
nullptr)
604 if (!east_neighbor->
isLeaf())
628 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)