GEOS 3.9.1
operation/overlayng/Edge.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/operation/overlayng/OverlayLabel.h>
18#include <geos/geom/Coordinate.h>
19#include <geos/export.h>
20
21#include <memory>
22
23// Forward declarations
24namespace geos {
25namespace geom {
26class Coordinate;
27class CoordinateSequence;
28}
29namespace operation {
30namespace overlayng {
31class EdgeSourceInfo;
32}
33}
34}
35
36namespace geos { // geos.
37namespace operation { // geos.operation
38namespace overlayng { // geos.operation.overlayng
39
40
62class GEOS_DLL Edge {
63
64private:
65
66 // Members
67 int aDim = OverlayLabel::DIM_UNKNOWN;
68 int aDepthDelta = 0;
69 bool aIsHole = false;
70 int bDim = OverlayLabel::DIM_UNKNOWN;
71 int bDepthDelta = 0;
72 bool bIsHole = false;
73 std::unique_ptr<geom::CoordinateSequence> pts;
74
75 // Methods
76
92 void initLabel(OverlayLabel& lbl, int geomIndex, int dim, int depthDelta, bool isHole) const;
93
94 int labelDim(int dim, int depthDelta) const;
95 bool isHole(int index) const;
96 bool isBoundary(int geomIndex) const;
97
102 bool isShell(int geomIndex) const;
103
104 geom::Location locationRight(int depthDelta) const;
105 geom::Location locationLeft(int depthDelta) const;
106
107 int delSign(int depthDel) const;
108 void copyInfo(const EdgeSourceInfo* info);
109 bool isHoleMerged(int geomIndex, const Edge* edge1, const Edge* edge2) const;
110
111
112public:
113
114 Edge()
115 : aDim(OverlayLabel::DIM_UNKNOWN)
116 , aDepthDelta(0)
117 , aIsHole(false)
118 , bDim(OverlayLabel::DIM_UNKNOWN)
119 , bDepthDelta(0)
120 , bIsHole(false)
121 , pts(nullptr)
122 {};
123
124 friend std::ostream& operator<<(std::ostream& os, const Edge& e);
125
126 static bool isCollapsed(const geom::CoordinateSequence* pts);
127
128 // takes ownership of pts from caller
129 Edge(geom::CoordinateSequence* p_pts, const EdgeSourceInfo* info);
130
131 // return a clone of the underlying points
132 std::unique_ptr<geom::CoordinateSequence> getCoordinates();
133 // return a read-only pointer to the underlying points
134 const geom::CoordinateSequence* getCoordinatesRO() const;
135 // release the underlying points to the caller
136 geom::CoordinateSequence* releaseCoordinates();
137
138 const geom::Coordinate& getCoordinate(size_t index) const;
139
140 std::size_t size() const;
141 bool direction() const;
142
147 bool relativeDirection(const Edge* edge2) const;
148 int dimension(int geomIndex) const;
149
154 void merge(const Edge* edge);
155
156 void populateLabel(OverlayLabel &ovl) const;
157
158 /*public*/
159 bool compareTo(const Edge& e) const
160 {
161 const geom::Coordinate& ca = getCoordinate(0);
162 const geom::Coordinate& cb = e.getCoordinate(0);
163 if(ca.compareTo(cb) < 0) {
164 return true;
165 }
166 else if (ca.compareTo(cb) > 0) {
167 return false;
168 }
169 else {
170 const geom::Coordinate& cca = getCoordinate(1);
171 const geom::Coordinate& ccb = e.getCoordinate(1);
172 if(cca.compareTo(ccb) < 0) {
173 return true;
174 }
175 else if (cca.compareTo(ccb) > 0) {
176 return false;
177 }
178 else {
179 return false;
180 }
181 }
182 }
183
184};
185
186bool EdgeComparator(const Edge* a, const Edge* b);
187
188
189
190} // namespace geos.operation.overlayng
191} // namespace geos.operation
192} // namespace geos
193
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:58
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
int compareTo(const Coordinate &other) const
TODO: deprecate this, move logic to CoordinateLessThen instead.
Definition EdgeSourceInfo.h:38
Definition operation/overlayng/Edge.h:62
bool relativeDirection(const Edge *edge2) const
void merge(const Edge *edge)
Definition OverlayLabel.h:90
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:34
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:26