OGS
SimplePolygonTree.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "SimplePolygonTree.h"
5
6#include <range/v3/algorithm/find_if.hpp>
7
8namespace GeoLib
9{
15
17{
18 for (auto const* child : _children)
19 {
20 delete child;
21 }
22}
23
25{
26 return _parent == nullptr;
27}
28
30 const SimplePolygonTree* polygon_hierarchy) const
31{
32 return _node_polygon->isPolylineInPolygon(polygon_hierarchy->polygon());
33}
34
36{
37 return _parent;
38}
39
41 SimplePolygonTree* polygon_hierarchy)
42{
43 auto const child = ranges::find_if(
44 _children, [&p = polygon_hierarchy->polygon()](auto const* c)
45 { return c->polygon().isPolylineInPolygon(p); });
46
47 if (child != std::end(_children))
48 {
49 (*child)->insertSimplePolygonTree(polygon_hierarchy);
50 }
51 else
52 {
53 _children.push_back(polygon_hierarchy);
54 polygon_hierarchy->_parent = this;
55 }
56}
57
63{
64 return *_node_polygon;
65}
66
67} // end namespace GeoLib
std::list< SimplePolygonTree * > _children
bool isPolygonInside(const SimplePolygonTree *polygon_hierarchy) const
SimplePolygonTree(Polygon *polygon, SimplePolygonTree *parent)
const SimplePolygonTree * parent() const
void insertSimplePolygonTree(SimplePolygonTree *polygon_hierarchy)
Polygon const & polygon() const
SimplePolygonTree * _parent