GEOS  3.8.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 #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
36 namespace geos {
37 namespace geom {
38 //class Coordinate;
39 class Envelope;
40 }
41 }
42 
43 namespace geos {
44 namespace index { // geos::index
45 namespace quadtree { // geos::index::quadtree
46 
55 class GEOS_DLL Node: public NodeBase {
56 
57 private:
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 
76 protected:
77 
78  bool
79  isSearchMatch(const geom::Envelope& searchEnv) const override
80  {
81  return env->intersects(searchEnv);
82  }
83 
84 public:
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
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
The base class for nodes in a Quadtree.
Definition: quadtree/NodeBase.h:55
double getMinY() const
Returns the Envelope minimum y-value. min y > max y indicates that this is a null Envelope...
double getMaxY() const
Returns the Envelope maximum y-value. min y > max y indicates that this is a null Envelope...
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
double getMaxX() const
Returns the Envelope maximum x-value. min x > max x indicates that this is a null Envelope...
geom::Envelope * getEnvelope()
Definition: index/quadtree/Node.h:111
double getMinX() const
Returns the Envelope minimum x-value. min x > max x indicates that this is a null Envelope...
Represents a node of a Quadtree.
Definition: index/quadtree/Node.h:55