GEOS 3.9.1
index/quadtree/Node.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: index/quadtree/Node.java rev 1.8 (JTS-1.10)
16 *
17 **********************************************************************/
18
19#ifndef GEOS_IDX_QUADTREE_NODE_H
20#define GEOS_IDX_QUADTREE_NODE_H
21
22#include <geos/export.h>
23#include <geos/index/quadtree/NodeBase.h> // for inheritance
24#include <geos/geom/Coordinate.h> // for composition
25#include <geos/geom/Envelope.h> // for inline
26
27#include <string>
28#include <memory>
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33#endif
34
35// Forward declarations
36namespace geos {
37namespace geom {
38//class Coordinate;
39class Envelope;
40}
41}
42
43namespace geos {
44namespace index { // geos::index
45namespace quadtree { // geos::index::quadtree
46
55class GEOS_DLL Node: public NodeBase {
56
57private:
58
60 std::unique_ptr<geom::Envelope> env;
61
62 geom::Coordinate centre;
63
64 int level;
65
72 Node* getSubnode(int index);
73
74 std::unique_ptr<Node> createSubnode(int index);
75
76protected:
77
78 bool
79 isSearchMatch(const geom::Envelope& searchEnv) const override
80 {
81 return env->intersects(searchEnv);
82 }
83
84public:
85
86 // Create a node computing level from given envelope
87 static std::unique_ptr<Node> createNode(const geom::Envelope& env);
88
90 //
94 static std::unique_ptr<Node> createExpanded(std::unique_ptr<Node> node,
95 const geom::Envelope& addEnv);
96
97 Node(std::unique_ptr<geom::Envelope> nenv, int nlevel)
98 :
99 env(std::move(nenv)),
100 centre((env->getMinX() + env->getMaxX()) / 2,
101 (env->getMinY() + env->getMaxY()) / 2),
102 level(nlevel)
103 {
104 }
105
106 ~Node() override {}
107
112 {
113 return env.get();
114 }
115
121 Node* getNode(const geom::Envelope* searchEnv);
122
127 NodeBase* find(const geom::Envelope* searchEnv);
128
129 void insertNode(std::unique_ptr<Node> node);
130
131 std::string toString() const override;
132
133};
134
135} // namespace geos::index::quadtree
136} // namespace geos::index
137} // namespace geos
138
139#ifdef _MSC_VER
140#pragma warning(pop)
141#endif
142
143#endif // GEOS_IDX_QUADTREE_NODE_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
The base class for nodes in a Quadtree.
Definition: quadtree/NodeBase.h:55
Represents a node of a Quadtree.
Definition: index/quadtree/Node.h:55
NodeBase * find(const geom::Envelope *searchEnv)
Returns the smallest existing node containing the envelope.
static std::unique_ptr< Node > createExpanded(std::unique_ptr< Node > node, const geom::Envelope &addEnv)
Create a node containing the given node and envelope.
Node * getNode(const geom::Envelope *searchEnv)
Returns the subquad containing the envelope. Creates the subquad if it does not already exist.
geom::Envelope * getEnvelope()
Definition: index/quadtree/Node.h:111
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26