GEOS  3.14.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 #pragma once
23 
24 #include <geos/export.h>
25 #include <string>
26 #include <cassert>
27 
28 #include <geos/geomgraph/GraphComponent.h> // for inheritance
29 #include <geos/geomgraph/Depth.h> // for member
30 #include <geos/geomgraph/EdgeIntersectionList.h> // for composition
31 #include <geos/geom/CoordinateSequence.h> // for inlines
32 #include <geos/geom/Envelope.h>
33 
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 #endif
38 
39 // Forward declarations
40 namespace geos {
41 namespace geom {
42 class IntersectionMatrix;
43 class Coordinate;
44 }
45 namespace algorithm {
46 class LineIntersector;
47 }
48 namespace geomgraph {
49 class Node;
50 class EdgeEndStar;
51 class Label;
52 class NodeFactory;
53 namespace index {
54 class MonotoneChainEdge;
55 }
56 }
57 }
58 
59 namespace geos {
60 namespace geomgraph { // geos.geomgraph
61 
63 class GEOS_DLL Edge final: public GraphComponent {
64  using GraphComponent::updateIM;
65 
66 private:
67 
69  std::unique_ptr<index::MonotoneChainEdge> mce;
70 
71  geom::Envelope env;
72 
73  Depth depth;
74 
75  int depthDelta; // the change in area depth from the R to L side of this edge
76 
77  bool isIsolatedVar;
78 
79 public:
80 
81  void
82  testInvariant() const
83  {
84  assert(pts);
85  assert(pts->size() > 1);
86  }
87 
88  friend std::ostream& operator<< (std::ostream& os, const Edge& el);
89 
90  static void updateIM(const Label& lbl, geom::IntersectionMatrix& im);
91 
93  std::unique_ptr<geom::CoordinateSequence> pts;
94 
95  EdgeIntersectionList eiList;
96 
98  Edge(geom::CoordinateSequence* newPts, const Label& newLabel);
99 
102 
103  ~Edge() override;
104 
105  size_t
106  getNumPoints() const
107  {
108  return pts->getSize();
109  }
110 
112  getCoordinates() const
113  {
114  testInvariant();
115  return pts.get();
116  }
117 
118  const geom::Coordinate&
119  getCoordinate(std::size_t i) const
120  {
121  testInvariant();
122  return pts->getAt(i);
123  }
124 
125  const geom::Coordinate&
126  getCoordinate() const
127  {
128  testInvariant();
129  return pts->getAt(0);
130  }
131 
132 
133  const Depth&
134  getDepth() const
135  {
136  testInvariant();
137  return depth;
138  }
139 
145  int
147  {
148  testInvariant();
149  return depthDelta;
150  }
151 
152  void
153  setDepthDelta(int newDepthDelta)
154  {
155  depthDelta = newDepthDelta;
156  testInvariant();
157  }
158 
159  size_t
160  getMaximumSegmentIndex() const
161  {
162  testInvariant();
163  return getNumPoints() - 1;
164  }
165 
166  EdgeIntersectionList&
167  getEdgeIntersectionList()
168  {
169  testInvariant();
170  return eiList;
171  }
172 
173  const EdgeIntersectionList&
174  getEdgeIntersectionList() const
175  {
176  testInvariant();
177  return eiList;
178  }
179 
185 
186  bool
187  isClosed() const
188  {
189  testInvariant();
190  return pts->getAt(0) == pts->getAt(getNumPoints() - 1);
191  }
192 
197  bool isCollapsed() const;
198 
199  Edge* getCollapsedEdge();
200 
201  void
202  setIsolated(bool newIsIsolated)
203  {
204  isIsolatedVar = newIsIsolated;
205  testInvariant();
206  }
207 
208  bool
209  isIsolated() const override
210  {
211  testInvariant();
212  return isIsolatedVar;
213  }
214 
219  void addIntersections(algorithm::LineIntersector* li, std::size_t segmentIndex,
220  std::size_t geomIndex);
221 
223  //
227  void addIntersection(algorithm::LineIntersector* li, std::size_t segmentIndex,
228  std::size_t geomIndex, std::size_t intIndex);
229 
231  //
235  void
237  {
238  updateIM(label, im);
239  testInvariant();
240  }
241 
243  bool isPointwiseEqual(const Edge* e) const;
244 
245  std::string print() const;
246 
247  std::string printReverse() const;
248 
256  bool equals(const Edge& e) const;
257 
258  bool
259  equals(const Edge* e) const
260  {
261  assert(e);
262  return equals(*e);
263  }
264 
265  const geom::Envelope* getEnvelope();
266 };
267 
268 
269 //Operators
270 inline bool
271 operator==(const Edge& a, const Edge& b)
272 {
273  return a.equals(b);
274 }
275 
276 std::ostream& operator<< (std::ostream& os, const Edge& el);
277 
278 
279 } // namespace geos.geomgraph
280 } // namespace geos
281 
282 #ifdef _MSC_VER
283 #pragma warning(pop)
284 #endif
285 
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:53
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Implementation of Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix.
Definition: IntersectionMatrix.h:51
A Depth object records the topological depth of the sides of an Edge for up to two Geometries.
Definition: Depth.h:41
A list of edge intersections along an Edge.
Definition: EdgeIntersectionList.h:57
Definition: geomgraph/Edge.h:63
bool isPointwiseEqual(const Edge *e) const
return true if the coordinate sequences of the Edges are identical
int getDepthDelta() const
The depthDelta is the change in depth as an edge is crossed from R to L.
Definition: geomgraph/Edge.h:146
bool equals(const Edge &e) const
bool isCollapsed() const
An Edge is collapsed if it is an Area edge and it consists of two segments which are equal and opposi...
Edge(geom::CoordinateSequence *newPts, const Label &newLabel)
Takes ownership of CoordinateSequence.
void addIntersections(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex)
Adds EdgeIntersections for one or both intersections found for a segment of an edge to the edge inter...
index::MonotoneChainEdge * getMonotoneChainEdge()
Return this Edge's index::MonotoneChainEdge, ownership is retained by this object.
void computeIM(geom::IntersectionMatrix &im) override
Update the IM with the contribution for this component.
Definition: geomgraph/Edge.h:236
std::unique_ptr< geom::CoordinateSequence > pts
Externally-set, owned by Edge. FIXME: refuse ownership.
Definition: geomgraph/Edge.h:93
Edge(geom::CoordinateSequence *newPts)
Takes ownership of CoordinateSequence.
void addIntersection(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex, std::size_t intIndex)
Add an EdgeIntersection for intersection intIndex.
A GraphComponent is the parent class for the objects' that form a graph.
Definition: geomgraph/GraphComponent.h:45
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
MonotoneChains are a way of partitioning the segments of an edge to allow for fast searching of inter...
Definition: MonotoneChainEdge.h:45
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25