GEOS 3.10.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/inline.h>
18#include <geos/operation/overlayng/OverlayLabel.h>
19#include <geos/geom/Coordinate.h>
20#include <geos/geom/CoordinateSequence.h>
21#include <geos/export.h>
22
23#include <memory>
24
25// Forward declarations
26namespace geos {
27namespace geom {
28class Coordinate;
29}
30namespace operation {
31namespace overlayng {
32class EdgeSourceInfo;
33}
34}
35}
36
37namespace geos { // geos.
38namespace operation { // geos.operation
39namespace overlayng { // geos.operation.overlayng
40
41
63class GEOS_DLL Edge {
64
65private:
66
67 // Members
68 int aDim = OverlayLabel::DIM_UNKNOWN;
69 int aDepthDelta = 0;
70 bool aIsHole = false;
71 int bDim = OverlayLabel::DIM_UNKNOWN;
72 int bDepthDelta = 0;
73 bool bIsHole = false;
74 std::unique_ptr<geom::CoordinateSequence> pts;
75
76 // Methods
77
93 static void initLabel(OverlayLabel& lbl, uint8_t geomIndex, int dim, int depthDelta, bool p_isHole);
94
95 static int labelDim(int dim, int depthDelta);
96 bool isHole(int index) const;
97 bool isBoundary(int geomIndex) const;
98
103 bool isShell(int geomIndex) const;
104
105 static geom::Location locationRight(int depthDelta);
106 static geom::Location locationLeft(int depthDelta);
107
108 static int delSign(int depthDel);
109 void copyInfo(const EdgeSourceInfo* info);
110 static bool isHoleMerged(int geomIndex, const Edge* edge1, const Edge* edge2);
111
112
113public:
114
115 Edge()
116 : aDim(OverlayLabel::DIM_UNKNOWN)
117 , aDepthDelta(0)
118 , aIsHole(false)
119 , bDim(OverlayLabel::DIM_UNKNOWN)
120 , bDepthDelta(0)
121 , bIsHole(false)
122 , pts(nullptr)
123 {};
124
125 friend std::ostream& operator<<(std::ostream& os, const Edge& e);
126
127 static bool isCollapsed(const geom::CoordinateSequence* pts);
128
129 // takes ownership of pts from caller
130 Edge(geom::CoordinateSequence* p_pts, const EdgeSourceInfo* info);
131
132 // return a clone of the underlying points
133 std::unique_ptr<geom::CoordinateSequence> getCoordinates();
134 // return a read-only pointer to the underlying points
135 const geom::CoordinateSequence* getCoordinatesRO() const;
136 // release the underlying points to the caller
137 geom::CoordinateSequence* releaseCoordinates();
138
139 const geom::Coordinate& getCoordinate(std::size_t index) const;
140
141 std::size_t size() const;
142 bool direction() const;
143
148 bool relativeDirection(const Edge* edge2) const;
149 int dimension(int geomIndex) const;
150
155 void merge(const Edge* edge);
156
157 void populateLabel(OverlayLabel &lbl) const;
158
159 /*public*/
160 bool compareTo(const Edge& e) const
161 {
162 const geom::Coordinate& ca = getCoordinate(0);
163 const geom::Coordinate& cb = e.getCoordinate(0);
164 if(ca.compareTo(cb) < 0) {
165 return true;
166 }
167 else if (ca.compareTo(cb) > 0) {
168 return false;
169 }
170 else {
171 const geom::Coordinate& cca = getCoordinate(1);
172 const geom::Coordinate& ccb = e.getCoordinate(1);
173 if(cca.compareTo(ccb) < 0) {
174 return true;
175 }
176 else if (cca.compareTo(ccb) > 0) {
177 return false;
178 }
179 else {
180 return false;
181 }
182 }
183 }
184
185};
186
187bool EdgeComparator(const Edge* a, const Edge* b);
188
189
190
191} // namespace geos.operation.overlayng
192} // namespace geos.operation
193} // namespace geos
194
195#ifdef GEOS_INLINE
196#include "geos/operation/overlayng/Edge.inl"
197#endif
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:63
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: geos.h:40