/src/geos/include/geos/planargraph/Node.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
7 | | * Copyright (C) 2005-2006 Refractions Research Inc. |
8 | | * |
9 | | * This is free software; you can redistribute and/or modify it under |
10 | | * the terms of the GNU Lesser General Public Licence as published |
11 | | * by the Free Software Foundation. |
12 | | * See the COPYING file for more information. |
13 | | * |
14 | | **********************************************************************/ |
15 | | |
16 | | #pragma once |
17 | | |
18 | | #include <geos/export.h> |
19 | | |
20 | | #include <geos/planargraph/GraphComponent.h> // for inheritance |
21 | | #include <geos/planargraph/DirectedEdgeStar.h> // for inlines |
22 | | #include <geos/geom/Coordinate.h> // for composition |
23 | | |
24 | | // Forward declarations |
25 | | namespace geos { |
26 | | namespace planargraph { |
27 | | //class DirectedEdgeStar; |
28 | | class DirectedEdge; |
29 | | } |
30 | | } |
31 | | |
32 | | namespace geos { |
33 | | namespace planargraph { // geos.planargraph |
34 | | |
35 | | /** |
36 | | * \brief A node in a PlanarGraph is a location where 0 or more Edge meet. |
37 | | * |
38 | | * A node is connected to each of its incident Edges via an outgoing |
39 | | * DirectedEdge. Some clients using a <code>PlanarGraph</code> may want to |
40 | | * subclass <code>Node</code> to add their own application-specific |
41 | | * data and methods. |
42 | | * |
43 | | */ |
44 | | class GEOS_DLL Node: public GraphComponent { |
45 | | protected: |
46 | | |
47 | | /// The location of this Node |
48 | | geom::CoordinateXY pt; |
49 | | |
50 | | /// The collection of DirectedEdges that leave this Node |
51 | | DirectedEdgeStar* deStar; |
52 | | |
53 | | public: |
54 | | |
55 | | friend std::ostream& operator << (std::ostream& os, const Node&); |
56 | | |
57 | | /** \brief |
58 | | * Returns all Edges that connect the two nodes (which are |
59 | | * assumed to be different). |
60 | | * |
61 | | * Note: returned vector is newly allocated, ownership to |
62 | | * the caller. |
63 | | */ |
64 | | static std::vector<Edge*>* getEdgesBetween(Node* node0, |
65 | | Node* node1); |
66 | | |
67 | | /// Constructs a Node with the given location. |
68 | | Node(const geom::CoordinateXY& newPt) |
69 | | : |
70 | 0 | pt(newPt) |
71 | 0 | { |
72 | 0 | deStar = new DirectedEdgeStar(); |
73 | 0 | } |
74 | | |
75 | | ~Node() override |
76 | 0 | { |
77 | 0 | delete deStar; |
78 | 0 | } |
79 | | |
80 | | /** |
81 | | * \brief |
82 | | * Constructs a Node with the given location and |
83 | | * collection of outgoing DirectedEdges. |
84 | | * Takes ownership of the given DirectedEdgeStar!! |
85 | | */ |
86 | | Node(geom::Coordinate& newPt, DirectedEdgeStar* newDeStar) |
87 | | : |
88 | | pt(newPt), |
89 | | deStar(newDeStar) |
90 | 0 | {} |
91 | | |
92 | | /** |
93 | | * \brief Returns the location of this Node. |
94 | | */ |
95 | | geom::CoordinateXY& |
96 | | getCoordinate() |
97 | 0 | { |
98 | 0 | return pt; |
99 | 0 | } |
100 | | |
101 | | /** |
102 | | * \brief Adds an outgoing DirectedEdge to this Node. |
103 | | */ |
104 | | void |
105 | | addOutEdge(DirectedEdge* de) |
106 | 0 | { |
107 | 0 | deStar->add(de); |
108 | 0 | } |
109 | | |
110 | | /** |
111 | | * \brief Returns the collection of DirectedEdges that |
112 | | * leave this Node. |
113 | | */ |
114 | | DirectedEdgeStar* |
115 | | getOutEdges() |
116 | 0 | { |
117 | 0 | return deStar; |
118 | 0 | } |
119 | | const DirectedEdgeStar* |
120 | | getOutEdges() const |
121 | 0 | { |
122 | 0 | return deStar; |
123 | 0 | } |
124 | | |
125 | | /** |
126 | | * \brief Returns the number of edges around this Node. |
127 | | */ |
128 | | size_t |
129 | | getDegree() const |
130 | 0 | { |
131 | 0 | return deStar->getDegree(); |
132 | 0 | } |
133 | | |
134 | | /** |
135 | | * \brief Returns the zero-based index of the given Edge, |
136 | | * after sorting in ascending order by angle with |
137 | | * the positive x-axis. |
138 | | */ |
139 | | int |
140 | | getIndex(Edge* edge) |
141 | 0 | { |
142 | 0 | return deStar->getIndex(edge); |
143 | 0 | } |
144 | | |
145 | | private: |
146 | | |
147 | | Node(const Node&) = delete; |
148 | | Node& operator=(const Node&) = delete; |
149 | | |
150 | | }; |
151 | | |
152 | | /// Print a Node |
153 | | std::ostream& operator<<(std::ostream& os, const Node& n); |
154 | | |
155 | | |
156 | | } // namespace geos::planargraph |
157 | | } // namespace geos |
158 | | |