GEOS  3.8.0dev
geomgraph/Edge.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geomgraph/Edge.java r428 (JTS-1.12+)
18  *
19  **********************************************************************/
20 
21 
22 #ifndef GEOS_GEOMGRAPH_EDGE_H
23 #define GEOS_GEOMGRAPH_EDGE_H
24 
25 #include <geos/export.h>
26 #include <string>
27 #include <cassert>
28 
29 #include <geos/geomgraph/GraphComponent.h> // for inheritance
30 #include <geos/geomgraph/Depth.h> // for member
31 #include <geos/geomgraph/EdgeIntersectionList.h> // for composition
32 #include <geos/geom/CoordinateSequence.h> // for inlines
33 
34 #include <geos/inline.h>
35 
36 #ifdef _MSC_VER
37 #pragma warning(push)
38 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
39 #endif
40 
41 // Forward declarations
42 namespace geos {
43 namespace geom {
44 class Envelope;
45 class IntersectionMatrix;
46 class Coordinate;
47 }
48 namespace algorithm {
49 class LineIntersector;
50 }
51 namespace geomgraph {
52 class Node;
53 class EdgeEndStar;
54 class Label;
55 class NodeFactory;
56 namespace index {
57 class MonotoneChainEdge;
58 }
59 }
60 }
61 
62 namespace geos {
63 namespace geomgraph { // geos.geomgraph
64 
66 class GEOS_DLL Edge: public GraphComponent {
67  using GraphComponent::updateIM;
68 
69 private:
70 
71  std::string name;
72 
74  index::MonotoneChainEdge* mce;
75 
77  geom::Envelope* env;
78 
79  bool isIsolatedVar;
80 
81  Depth depth;
82 
83  int depthDelta; // the change in area depth from the R to L side of this edge
84 
85 public:
86 
87  void
88  testInvariant() const
89  {
90  assert(pts);
91  assert(pts->size() > 1);
92  }
93 
94 
95  friend std::ostream& operator<< (std::ostream& os, const Edge& el);
96 
97  static void updateIM(const Label& lbl, geom::IntersectionMatrix& im);
98 
101 
102  EdgeIntersectionList eiList;
103 
104  //Edge();
105 
107  Edge(geom::CoordinateSequence* newPts, const Label& newLabel);
108 
111 
112  ~Edge() override;
113 
114  virtual size_t
115  getNumPoints() const
116  {
117  return pts->getSize();
118  }
119 
120  virtual void
121  setName(const std::string& newName)
122  {
123  name = newName;
124  }
125 
126  virtual const geom::CoordinateSequence*
127  getCoordinates() const
128  {
129  testInvariant();
130  return pts;
131  }
132 
133  virtual const geom::Coordinate&
134  getCoordinate(size_t i) const
135  {
136  testInvariant();
137  return pts->getAt(i);
138  }
139 
140  virtual const geom::Coordinate&
141  getCoordinate() const
142  {
143  testInvariant();
144  return pts->getAt(0);
145  }
146 
147 
148  virtual Depth&
149  getDepth()
150  {
151  testInvariant();
152  return depth;
153  }
154 
160  virtual int
162  {
163  testInvariant();
164  return depthDelta;
165  }
166 
167  virtual void
168  setDepthDelta(int newDepthDelta)
169  {
170  depthDelta = newDepthDelta;
171  testInvariant();
172  }
173 
174  virtual size_t
175  getMaximumSegmentIndex() const
176  {
177  testInvariant();
178  return getNumPoints() - 1;
179  }
180 
181  virtual EdgeIntersectionList&
182  getEdgeIntersectionList()
183  {
184  testInvariant();
185  return eiList;
186  }
187 
192  virtual index::MonotoneChainEdge* getMonotoneChainEdge();
193 
194  virtual bool
195  isClosed() const
196  {
197  testInvariant();
198  return pts->getAt(0) == pts->getAt(getNumPoints() - 1);
199  }
200 
205  virtual bool isCollapsed() const;
206 
207  virtual Edge* getCollapsedEdge();
208 
209  virtual void
210  setIsolated(bool newIsIsolated)
211  {
212  isIsolatedVar = newIsIsolated;
213  testInvariant();
214  }
215 
216  bool
217  isIsolated() const override
218  {
219  testInvariant();
220  return isIsolatedVar;
221  }
222 
227  virtual void addIntersections(algorithm::LineIntersector* li, size_t segmentIndex,
228  size_t geomIndex);
229 
231  //
235  virtual void addIntersection(algorithm::LineIntersector* li, size_t segmentIndex,
236  size_t geomIndex, size_t intIndex);
237 
239  //
243  void
245  {
246  updateIM(label, im);
247  testInvariant();
248  }
249 
251  virtual bool isPointwiseEqual(const Edge* e) const;
252 
253  virtual std::string print() const;
254 
255  virtual std::string printReverse() const;
256 
264  virtual bool equals(const Edge& e) const;
265 
266  virtual bool
267  equals(const Edge* e) const
268  {
269  assert(e);
270  return equals(*e);
271  }
272 
273  virtual geom::Envelope* getEnvelope();
274 };
275 
276 
277 //Operators
278 inline bool
279 operator==(const Edge& a, const Edge& b)
280 {
281  return a.equals(b);
282 }
283 
284 std::ostream& operator<< (std::ostream& os, const Edge& el);
285 
286 
287 } // namespace geos.geomgraph
288 } // namespace geos
289 
290 #ifdef _MSC_VER
291 #pragma warning(pop)
292 #endif
293 
294 //#ifdef GEOS_INLINE
295 //# include "geos/geomgraph/Edge.inl"
296 //#endif
297 
298 #endif // ifndef GEOS_GEOMGRAPH_EDGE_H
299 
virtual int getDepthDelta() const
The depthDelta is the change in depth as an edge is crossed from R to L.
Definition: geomgraph/Edge.h:161
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
virtual std::size_t getSize() const =0
Returns the number of Coordinates (actual or otherwise, as this implementation may not store its data...
Implementation of Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix. ...
Definition: IntersectionMatrix.h:54
Definition: EdgeIntersectionList.h:59
geom::CoordinateSequence * pts
Externally-set, owned by Edge. FIXME: refuse ownership.
Definition: geomgraph/Edge.h:100
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:58
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
void computeIM(geom::IntersectionMatrix &im) override
Update the IM with the contribution for this component.
Definition: geomgraph/Edge.h:244
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
A GraphComponent is the parent class for the objects' that form a graph.
Definition: geomgraph/GraphComponent.h:47
virtual const Coordinate & getAt(std::size_t i) const =0
Returns a read-only reference to Coordinate at position i.
Definition: geomgraph/Edge.h:66