GEOS  3.11.0
HalfEdge.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 
16 #pragma once
17 
18 #include <geos/export.h>
19 #include <string>
20 #include <cassert>
21 #include <geos/geom/Coordinate.h>
22 
23 // Forward declarations
24 namespace geos {
25 namespace geom {
26 class Coordinate;
27 }
28 }
29 
30 namespace geos {
31 namespace edgegraph { // geos.edgegraph
32 
63 class GEOS_DLL HalfEdge {
64 
65 private:
66 
67  /* members */
68  geom::Coordinate m_orig;
69  HalfEdge* m_sym;
70  HalfEdge* m_next;
71 
72 
78  void setSym(HalfEdge* e) { m_sym = e; };
79 
89  HalfEdge* insertionEdge(HalfEdge* eAdd);
90 
98  void insertAfter(HalfEdge* e);
99 
106  const HalfEdge* findLowest() const;
107 
108 protected:
109 
119  virtual const geom::Coordinate& directionPt() const { return dest(); };
120 
121 
122 public:
123 
129  HalfEdge(const geom::Coordinate& p_orig) :
130  m_orig(p_orig)
131  {};
132 
133  virtual ~HalfEdge() {};
134 
142  static HalfEdge* create(const geom::Coordinate& p0, const geom::Coordinate& p1);
143 
150  void link(HalfEdge* p_sym);
151 
157  const geom::Coordinate& orig() const { return m_orig; };
158 
164  const geom::Coordinate& dest() const { return m_sym->m_orig; }
165 
171  double directionX() const { return directionPt().x - m_orig.x; }
172 
178  double directionY() const { return directionPt().y - m_orig.y; }
179 
185  HalfEdge* sym() const { return m_sym; };
186 
195  HalfEdge* next() const { return m_next; };
196 
208  HalfEdge* prev() const;
209 
218  HalfEdge* oNext() const { return m_sym->m_next; };
219 
225  void setNext(HalfEdge* e) { m_next = e; };
226 
237 
245  bool equals(const geom::Coordinate& p0, const geom::Coordinate& p1) const;
246 
255  void insert(HalfEdge* eAdd);
256 
265  bool isEdgesSorted() const;
266 
289  int compareAngularDirection(const HalfEdge* e) const;
290  int compareTo(const HalfEdge* e) const { return compareAngularDirection(e); };
291 
299  int degree();
300 
311 
312  friend std::ostream& operator<< (std::ostream& os, const HalfEdge& el);
313  static void toStringNode(const HalfEdge* he, std::ostream& os);
314 
315 };
316 
317 
318 } // namespace geos.edgegraph
319 } // namespace geos
320 
321 
322 
Definition: HalfEdge.h:63
HalfEdge * next() const
Definition: HalfEdge.h:195
HalfEdge(const geom::Coordinate &p_orig)
Definition: HalfEdge.h:129
HalfEdge * find(const geom::Coordinate &dest)
double directionX() const
Definition: HalfEdge.h:171
int compareAngularDirection(const HalfEdge *e) const
HalfEdge * sym() const
Definition: HalfEdge.h:185
void setNext(HalfEdge *e)
Definition: HalfEdge.h:225
void insert(HalfEdge *eAdd)
HalfEdge * prev() const
const geom::Coordinate & orig() const
Definition: HalfEdge.h:157
bool equals(const geom::Coordinate &p0, const geom::Coordinate &p1) const
const geom::Coordinate & dest() const
Definition: HalfEdge.h:164
void link(HalfEdge *p_sym)
double directionY() const
Definition: HalfEdge.h:178
virtual const geom::Coordinate & directionPt() const
Definition: HalfEdge.h:119
HalfEdge * oNext() const
Definition: HalfEdge.h:218
static HalfEdge * create(const geom::Coordinate &p0, const geom::Coordinate &p1)
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
double y
y-coordinate
Definition: Coordinate.h:81
double x
x-coordinate
Definition: Coordinate.h:78
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25