GEOS  3.9.1dev
geomgraph/Edge.h
Go to the documentation of this file.
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 #include <geos/geom/Envelope.h>
34 
35 #include <geos/inline.h>
36 
37 #ifdef _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
40 #endif
41 
42 // Forward declarations
43 namespace geos {
44 namespace geom {
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 
72  std::unique_ptr<index::MonotoneChainEdge> mce;
73 
75 
77 
78  int depthDelta; // the change in area depth from the R to L side of this edge
79 
81 
82 public:
83 
84  void
85  testInvariant() const
86  {
87  assert(pts);
88  assert(pts->size() > 1);
89  }
90 
91  friend std::ostream& operator<< (std::ostream& os, const Edge& el);
92 
93  static void updateIM(const Label& lbl, geom::IntersectionMatrix& im);
94 
96  std::unique_ptr<geom::CoordinateSequence> pts;
97 
99 
101  Edge(geom::CoordinateSequence* newPts, const Label& newLabel);
102 
105 
106  ~Edge() override;
107 
108  virtual size_t
109  getNumPoints() const
110  {
111  return pts->getSize();
112  }
113 
114  virtual const geom::CoordinateSequence*
116  {
117  testInvariant();
118  return pts.get();
119  }
120 
121  virtual const geom::Coordinate&
122  getCoordinate(size_t i) const
123  {
124  testInvariant();
125  return pts->getAt(i);
126  }
127 
128  virtual const geom::Coordinate&
130  {
131  testInvariant();
132  return pts->getAt(0);
133  }
134 
135 
136  virtual Depth&
138  {
139  testInvariant();
140  return depth;
141  }
142 
148  virtual int
150  {
151  testInvariant();
152  return depthDelta;
153  }
154 
155  virtual void
156  setDepthDelta(int newDepthDelta)
157  {
158  depthDelta = newDepthDelta;
159  testInvariant();
160  }
161 
162  virtual size_t
164  {
165  testInvariant();
166  return getNumPoints() - 1;
167  }
168 
169  virtual EdgeIntersectionList&
171  {
172  testInvariant();
173  return eiList;
174  }
175 
180  virtual index::MonotoneChainEdge* getMonotoneChainEdge();
181 
182  virtual bool
183  isClosed() const
184  {
185  testInvariant();
186  return pts->getAt(0) == pts->getAt(getNumPoints() - 1);
187  }
188 
193  virtual bool isCollapsed() const;
194 
195  virtual Edge* getCollapsedEdge();
196 
197  virtual void
198  setIsolated(bool newIsIsolated)
199  {
200  isIsolatedVar = newIsIsolated;
201  testInvariant();
202  }
203 
204  bool
205  isIsolated() const override
206  {
207  testInvariant();
208  return isIsolatedVar;
209  }
210 
215  virtual void addIntersections(algorithm::LineIntersector* li, size_t segmentIndex,
216  size_t geomIndex);
217 
219  //
223  virtual void addIntersection(algorithm::LineIntersector* li, size_t segmentIndex,
224  size_t geomIndex, size_t intIndex);
225 
227  //
231  void
233  {
234  updateIM(label, im);
235  testInvariant();
236  }
237 
239  virtual bool isPointwiseEqual(const Edge* e) const;
240 
241  virtual std::string print() const;
242 
243  virtual std::string printReverse() const;
244 
252  virtual bool equals(const Edge& e) const;
253 
254  virtual bool
255  equals(const Edge* e) const
256  {
257  assert(e);
258  return equals(*e);
259  }
260 
261  virtual const geom::Envelope* getEnvelope();
262 };
263 
264 
265 //Operators
266 inline bool
267 operator==(const Edge& a, const Edge& b)
268 {
269  return a.equals(b);
270 }
271 
272 std::ostream& operator<< (std::ostream& os, const Edge& el);
273 
274 
275 } // namespace geos.geomgraph
276 } // namespace geos
277 
278 #ifdef _MSC_VER
279 #pragma warning(pop)
280 #endif
281 
282 //#ifdef GEOS_INLINE
283 //# include "geos/geomgraph/Edge.inl"
284 //#endif
285 
286 #endif // ifndef GEOS_GEOMGRAPH_EDGE_H
287 
virtual Depth & getDepth()
virtual bool equals(const Edge *e) const
virtual int getDepthDelta() const
The depthDelta is the change in depth as an edge is crossed from R to L.
MonotoneChains are a way of partitioning the segments of an edge to allow for fast searching of inter...
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
virtual size_t getNumPoints() const
std::unique_ptr< geom::CoordinateSequence > pts
Externally-set, owned by Edge. FIXME: refuse ownership.
#define GEOS_DLL
Definition: export.h:28
virtual const geom::Coordinate & getCoordinate(size_t i) const
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
virtual void setDepthDelta(int newDepthDelta)
virtual void setIsolated(bool newIsIsolated)
Implementation of Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix. ...
virtual EdgeIntersectionList & getEdgeIntersectionList()
virtual bool equals(const Edge &e) const
A list of edge intersections along an Edge.
std::unique_ptr< index::MonotoneChainEdge > mce
Lazily-created, owned by Edge.
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
virtual const geom::Coordinate & getCoordinate() const
virtual size_t getMaximumSegmentIndex() const
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
EdgeIntersectionList eiList
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:59
Basic namespace for all GEOS functionalities.
void computeIM(geom::IntersectionMatrix &im) override
Update the IM with the contribution for this component.
bool isIsolated() const override
The internal representation of a list of coordinates inside a Geometry.
A Depth object records the topological depth of the sides of an Edge for up to two Geometries...
Definition: Depth.h:42
A GraphComponent is the parent class for the objects&#39; that form a graph.
void testInvariant() const
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
virtual const geom::CoordinateSequence * getCoordinates() const
geom::Envelope env
virtual bool isClosed() const