GEOS  3.13.0dev
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 #pragma once
20 
21 #include <geos/export.h>
22 #include <geos/index/quadtree/NodeBase.h> // for inheritance
23 #include <geos/geom/Coordinate.h> // for composition
24 #include <geos/geom/Envelope.h> // for inline
25 
26 #include <string>
27 #include <memory>
28 
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32 #endif
33 
34 // Forward declarations
35 namespace geos {
36 namespace geom {
37 //class Coordinate;
38 class Envelope;
39 }
40 }
41 
42 namespace geos {
43 namespace index { // geos::index
44 namespace quadtree { // geos::index::quadtree
45 
54 class GEOS_DLL Node: public NodeBase {
55 
56 private:
57 
59  std::unique_ptr<geom::Envelope> env;
60 
61  geom::Coordinate centre;
62 
63  int level;
64 
71  Node* getSubnode(int index);
72 
73  std::unique_ptr<Node> createSubnode(int index);
74 
75 protected:
76 
77  bool
78  isSearchMatch(const geom::Envelope& searchEnv) const override
79  {
80  return env->intersects(searchEnv);
81  }
82 
83 public:
84 
85  // Create a node computing level from given envelope
86  static std::unique_ptr<Node> createNode(const geom::Envelope& env);
87 
89  //
93  static std::unique_ptr<Node> createExpanded(std::unique_ptr<Node> node,
94  const geom::Envelope& addEnv);
95 
96  Node(std::unique_ptr<geom::Envelope> nenv, int nlevel)
97  :
98  env(std::move(nenv)),
99  centre((env->getMinX() + env->getMaxX()) / 2,
100  (env->getMinY() + env->getMaxY()) / 2),
101  level(nlevel)
102  {
103  }
104 
105  ~Node() override {}
106 
111  {
112  return env.get();
113  }
114 
120  Node* getNode(const geom::Envelope* searchEnv);
121 
126  NodeBase* find(const geom::Envelope* searchEnv);
127 
128  void insertNode(std::unique_ptr<Node> node);
129 
130  std::string toString() const override;
131 
132 };
133 
134 } // namespace geos::index::quadtree
135 } // namespace geos::index
136 } // namespace geos
137 
138 #ifdef _MSC_VER
139 #pragma warning(pop)
140 #endif
141 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
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:54
Represents a node of a Quadtree.
Definition: index/quadtree/Node.h:54
geom::Envelope * getEnvelope()
Definition: index/quadtree/Node.h:110
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.
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25