GEOS  3.10.2
Vertex.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2012 Excensus LLC.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: triangulate/quadedge/Vertex.java r705
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
20 #define GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
21 
22 #include <cmath>
23 #include <memory>
24 #include <cstring>
25 
26 #include <geos/geom/Coordinate.h>
27 #include <geos/algorithm/HCoordinate.h>
28 #include <geos/triangulate/quadedge/TrianglePredicate.h>
29 
30 
31 //fwd declarations
32 namespace geos {
33 namespace triangulate {
34 namespace quadedge {
35 class QuadEdge;
36 }
37 }
38 }
39 
40 namespace geos {
41 namespace triangulate { //geos.triangulate
42 namespace quadedge { //geos.triangulate.quadedge
43 
61 class GEOS_DLL Vertex {
62 public:
63  static const int LEFT = 0;
64  static const int RIGHT = 1;
65  static const int BEYOND = 2;
66  static const int BEHIND = 3;
67  static const int BETWEEN = 4;
68  static const int ORIGIN = 5;
69  static const int DESTINATION = 6;
70 private:
72 
73 public:
74  Vertex(double _x, double _y);
75 
76  Vertex(double _x, double _y, double _z);
77 
78  Vertex(const geom::Coordinate& _p);
79 
80  Vertex();
81  ~Vertex() {};
82 
83  inline double
84  getX() const
85  {
86  return p.x;
87  }
88 
89  inline double
90  getY() const
91  {
92  return p.y;
93  }
94 
95  inline double
96  getZ() const
97  {
98  return p.z;
99  }
100 
101  inline void
102  setZ(double _z)
103  {
104  p.z = _z;
105  }
106 
107  inline const geom::Coordinate&
108  getCoordinate() const
109  {
110  return p;
111  }
112 
113  inline bool
114  equals(const Vertex& _x) const
115  {
116  return p.equals2D(_x.p);
117  }
118 
119  inline bool
120  equals(const Vertex& _x, double tolerance) const
121  {
122  if(p.distance(_x.getCoordinate()) < tolerance) {
123  return true;
124  }
125  return false;
126  }
127 
128  int classify(const Vertex& p0, const Vertex& p1);
129 
136  inline double
137  crossProduct(const Vertex& v) const
138  {
139  return (p.x * v.getY() - p.y * v.getX());
140  }
141 
148  inline double
149  dot(Vertex v) const
150  {
151  return (p.x * v.getX() + p.y * v.getY());
152  }
153 
160  inline std::unique_ptr<Vertex>
161  times(double c) const
162  {
163  return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
164  }
165 
166  /* Vector addition */
167  inline std::unique_ptr<Vertex>
168  sum(Vertex v) const
169  {
170  return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
171  }
172 
173  /* and subtraction */
174  inline std::unique_ptr<Vertex>
175  sub(const Vertex& v) const
176  {
177  return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
178  }
179 
180  /* magnitude of vector */
181  inline double
182  magn() const
183  {
184  return (sqrt(p.x * p.x + p.y * p.y));
185  }
186 
187  /* returns k X v (cross product). this is a vector perpendicular to v */
188  inline std::unique_ptr<Vertex>
189  cross() const
190  {
191  return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
192  }
193 
195  /***********************************************************************************************
196  * Geometric primitives /
197  **********************************************************************************************/
198 
208  bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const {
209  return triangulate::quadedge::TrianglePredicate::isInCircleRobust(a.p, b.p, c.p, this->p);
210  }
211 
220  inline bool
221  isCCW(const Vertex& b, const Vertex& c) const
222  {
223  // check if signed area is positive
224  return (b.p.x - p.x) * (c.p.y - p.y)
225  > (b.p.y - p.y) * (c.p.x - p.x);
226  }
227 
228  bool rightOf(const QuadEdge& e) const;
229  bool leftOf(const QuadEdge& e) const;
230 
231 private:
232  static std::unique_ptr<algorithm::HCoordinate> bisector(const Vertex& a, const Vertex& b);
233 
234  inline double
235  distance(const Vertex& v1, const Vertex& v2)
236  {
237  return std::sqrt(pow(v2.getX() - v1.getX(), 2.0) +
238  pow(v2.getY() - v1.getY(), 2.0));
239  }
240 
251  double circumRadiusRatio(const Vertex& b, const Vertex& c);
252 
259  std::unique_ptr<Vertex> midPoint(const Vertex& a);
260 
268  std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
269 
274  double interpolateZValue(const Vertex& v0, const Vertex& v1, const Vertex& v2) const;
275 
289  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
290  const geom::Coordinate& v1, const geom::Coordinate& v2);
291 
300  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
301  const geom::Coordinate& p1);
302 };
303 
304 inline bool
305 operator<(const Vertex& v1, const Vertex& v2)
306 {
307  return v1.getCoordinate() < v2.getCoordinate();
308 }
309 
310 } //namespace geos.triangulate.quadedge
311 } //namespace geos.triangulate
312 } //namespace geos
313 
314 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
315 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
double distance(const Coordinate &p) const
double y
y-coordinate
Definition: Coordinate.h:83
double x
x-coordinate
Definition: Coordinate.h:80
double z
z-coordinate
Definition: Coordinate.h:86
A class that represents the edge data structure which implements the quadedge algebra.
Definition: QuadEdge.h:54
static bool isInCircleRobust(const Coordinate &a, const Coordinate &b, const Coordinate &c, const Coordinate &p)
Models a site (node) in a QuadEdgeSubdivision.
Definition: Vertex.h:61
double crossProduct(const Vertex &v) const
Definition: Vertex.h:137
std::unique_ptr< Vertex > times(double c) const
Definition: Vertex.h:161
double dot(Vertex v) const
Definition: Vertex.h:149
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:221
bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const
Definition: Vertex.h:208
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26