GEOS 3.11.1
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
40namespace geos {
41namespace geom {
42class IntersectionMatrix;
43class Coordinate;
44}
45namespace algorithm {
46class LineIntersector;
47}
48namespace geomgraph {
49class Node;
50class EdgeEndStar;
51class Label;
52class NodeFactory;
53namespace index {
55}
56}
57}
58
59namespace geos {
60namespace geomgraph { // geos.geomgraph
61
63class GEOS_DLL Edge: public GraphComponent {
64 using GraphComponent::updateIM;
65
66private:
67
69 std::unique_ptr<index::MonotoneChainEdge> mce;
70
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
79public:
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
96
98 Edge(geom::CoordinateSequence* newPts, const Label& newLabel);
99
102
103 ~Edge() override;
104
105 virtual size_t
106 getNumPoints() const
107 {
108 return pts->getSize();
109 }
110
111 virtual const geom::CoordinateSequence*
112 getCoordinates() const
113 {
114 testInvariant();
115 return pts.get();
116 }
117
118 virtual const geom::Coordinate&
119 getCoordinate(std::size_t i) const
120 {
121 testInvariant();
122 return pts->getAt(i);
123 }
124
125 virtual const geom::Coordinate&
126 getCoordinate() const
127 {
128 testInvariant();
129 return pts->getAt(0);
130 }
131
132
133 virtual Depth&
134 getDepth()
135 {
136 testInvariant();
137 return depth;
138 }
139
145 virtual int
147 {
148 testInvariant();
149 return depthDelta;
150 }
151
152 virtual void
153 setDepthDelta(int newDepthDelta)
154 {
155 depthDelta = newDepthDelta;
156 testInvariant();
157 }
158
159 virtual size_t
160 getMaximumSegmentIndex() const
161 {
162 testInvariant();
163 return getNumPoints() - 1;
164 }
165
166 virtual EdgeIntersectionList&
167 getEdgeIntersectionList()
168 {
169 testInvariant();
170 return eiList;
171 }
172
178
179 virtual bool
180 isClosed() const
181 {
182 testInvariant();
183 return pts->getAt(0) == pts->getAt(getNumPoints() - 1);
184 }
185
190 virtual bool isCollapsed() const;
191
192 virtual Edge* getCollapsedEdge();
193
194 virtual void
195 setIsolated(bool newIsIsolated)
196 {
197 isIsolatedVar = newIsIsolated;
198 testInvariant();
199 }
200
201 bool
202 isIsolated() const override
203 {
204 testInvariant();
205 return isIsolatedVar;
206 }
207
212 virtual void addIntersections(algorithm::LineIntersector* li, std::size_t segmentIndex,
213 std::size_t geomIndex);
214
216 //
220 virtual void addIntersection(algorithm::LineIntersector* li, std::size_t segmentIndex,
221 std::size_t geomIndex, std::size_t intIndex);
222
224 //
228 void
230 {
231 updateIM(label, im);
232 testInvariant();
233 }
234
236 virtual bool isPointwiseEqual(const Edge* e) const;
237
238 virtual std::string print() const;
239
240 virtual std::string printReverse() const;
241
249 virtual bool equals(const Edge& e) const;
250
251 virtual bool
252 equals(const Edge* e) const
253 {
254 assert(e);
255 return equals(*e);
256 }
257
258 virtual const geom::Envelope* getEnvelope();
259};
260
261
262//Operators
263inline bool
264operator==(const Edge& a, const Edge& b)
265{
266 return a.equals(b);
267}
268
269std::ostream& operator<< (std::ostream& os, const Edge& el);
270
271
272} // namespace geos.geomgraph
273} // namespace geos
274
275#ifdef _MSC_VER
276#pragma warning(pop)
277#endif
278
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:50
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
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:40
A list of edge intersections along an Edge.
Definition: EdgeIntersectionList.h:57
Definition: geomgraph/Edge.h:63
virtual void addIntersection(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex, std::size_t intIndex)
Add an EdgeIntersection for intersection intIndex.
Edge(geom::CoordinateSequence *newPts, const Label &newLabel)
Takes ownership of CoordinateSequence.
void computeIM(geom::IntersectionMatrix &im) override
Update the IM with the contribution for this component.
Definition: geomgraph/Edge.h:229
virtual bool isCollapsed() const
An Edge is collapsed if it is an Area edge and it consists of two segments which are equal and opposi...
virtual index::MonotoneChainEdge * getMonotoneChainEdge()
Return this Edge's index::MonotoneChainEdge, ownership is retained by this object.
virtual bool isPointwiseEqual(const Edge *e) const
return true if the coordinate sequences of the Edges are identical
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.
virtual 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...
virtual int getDepthDelta() const
The depthDelta is the change in depth as an edge is crossed from R to L.
Definition: geomgraph/Edge.h:146
virtual bool equals(const Edge &e) const
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: geos.h:39