GEOS  3.9.1dev
operation/overlayng/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) 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 
18 #include <geos/geom/Coordinate.h>
19 #include <geos/export.h>
20 
21 #include <memory>
22 
23 // Forward declarations
24 namespace geos {
25 namespace geom {
26 class Coordinate;
27 class CoordinateSequence;
28 }
29 namespace operation {
30 namespace overlayng {
31 class EdgeSourceInfo;
32 }
33 }
34 }
35 
36 namespace geos { // geos.
37 namespace operation { // geos.operation
38 namespace overlayng { // geos.operation.overlayng
39 
40 
62 class GEOS_DLL Edge {
63 
64 private:
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 
112 public:
113 
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 
186 bool EdgeComparator(const Edge* a, const Edge* b);
187 
188 
189 
190 } // namespace geos.operation.overlayng
191 } // namespace geos.operation
192 } // namespace geos
193 
#define GEOS_DLL
Definition: export.h:28
const geom::Coordinate & getCoordinate(size_t index) const
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:34
Basic namespace for all GEOS functionalities.
std::unique_ptr< geom::CoordinateSequence > pts
int compareTo(const Coordinate &other) const
TODO: deprecate this, move logic to CoordinateLessThen instead.
The internal representation of a list of coordinates inside a Geometry.
bool EdgeComparator(const Edge *a, const Edge *b)