GEOS  3.9.0dev
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 <math.h>
23 #include <memory>
24 
25 #include <geos/geom/Coordinate.h>
26 #include <geos/algorithm/HCoordinate.h>
27 #include <geos/triangulate/quadedge/TrianglePredicate.h>
28 
29 
30 //fwd declarations
31 namespace geos {
32 namespace triangulate {
33 namespace quadedge {
34 class QuadEdge;
35 }
36 }
37 }
38 
39 namespace geos {
40 namespace triangulate { //geos.triangulate
41 namespace quadedge { //geos.triangulate.quadedge
42 
60 class GEOS_DLL Vertex {
61 public:
62  static const int LEFT = 0;
63  static const int RIGHT = 1;
64  static const int BEYOND = 2;
65  static const int BEHIND = 3;
66  static const int BETWEEN = 4;
67  static const int ORIGIN = 5;
68  static const int DESTINATION = 6;
69 private:
71 
72 public:
73  Vertex(double _x, double _y);
74 
75  Vertex(double _x, double _y, double _z);
76 
77  Vertex(const geom::Coordinate& _p);
78 
79  Vertex();
80  ~Vertex() {};
81 
82  inline double
83  getX() const
84  {
85  return p.x;
86  }
87 
88  inline double
89  getY() const
90  {
91  return p.y;
92  }
93 
94  inline double
95  getZ() const
96  {
97  return p.z;
98  }
99 
100  inline void
101  setZ(double _z)
102  {
103  p.z = _z;
104  }
105 
106  inline const geom::Coordinate&
107  getCoordinate() const
108  {
109  return p;
110  }
111 
112  inline bool
113  equals(const Vertex& _x) const
114  {
115  if(p.x == _x.getX() && p.y == _x.getY()) {
116  return true;
117  }
118  return false;
119  }
120 
121  inline bool
122  equals(const Vertex& _x, double tolerance) const
123  {
124  if(p.distance(_x.getCoordinate()) < tolerance) {
125  return true;
126  }
127  return false;
128  }
129 
130  int classify(const Vertex& p0, const Vertex& p1);
131 
138  inline double
139  crossProduct(const Vertex& v) const
140  {
141  return (p.x * v.getY() - p.y * v.getX());
142  }
143 
150  inline double
151  dot(Vertex v) const
152  {
153  return (p.x * v.getX() + p.y * v.getY());
154  }
155 
162  inline std::unique_ptr<Vertex>
163  times(double c) const
164  {
165  return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
166  }
167 
168  /* Vector addition */
169  inline std::unique_ptr<Vertex>
170  sum(Vertex v) const
171  {
172  return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
173  }
174 
175  /* and subtraction */
176  inline std::unique_ptr<Vertex>
177  sub(const Vertex& v) const
178  {
179  return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
180  }
181 
182  /* magnitude of vector */
183  inline double
184  magn() const
185  {
186  return (sqrt(p.x * p.x + p.y * p.y));
187  }
188 
189  /* returns k X v (cross product). this is a vector perpendicular to v */
190  inline std::unique_ptr<Vertex>
191  cross() const
192  {
193  return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
194  }
195 
197  /***********************************************************************************************
198  * Geometric primitives /
199  **********************************************************************************************/
200 
210  bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const {
211  return geom::TrianglePredicate::isInCircleRobust(a.p, b.p, c.p, this->p);
212  }
213 
222  inline bool
223  isCCW(const Vertex& b, const Vertex& c) const
224  {
225  // check if signed area is positive
226  return (b.p.x - p.x) * (c.p.y - p.y)
227  > (b.p.y - p.y) * (c.p.x - p.x);
228  }
229 
230  bool rightOf(const QuadEdge& e) const;
231  bool leftOf(const QuadEdge& e) const;
232 
233 private:
234  static std::unique_ptr<algorithm::HCoordinate> bisector(const Vertex& a, const Vertex& b);
235 
236  inline double
237  distance(const Vertex& v1, const Vertex& v2)
238  {
239  return sqrt(pow(v2.getX() - v1.getX(), 2.0)
240  + pow(v2.getY() - v1.getY(), 2.0));
241  }
242 
253  double circumRadiusRatio(const Vertex& b, const Vertex& c);
254 
261  std::unique_ptr<Vertex> midPoint(const Vertex& a);
262 
270  std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
271 
276  double interpolateZValue(const Vertex& v0, const Vertex& v1, const Vertex& v2) const;
277 
291  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
292  const geom::Coordinate& v1, const geom::Coordinate& v2);
293 
302  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
303  const geom::Coordinate& p1);
304 };
305 
306 inline bool
307 operator<(const Vertex& v1, const Vertex& v2)
308 {
309  return v1.getCoordinate() < v2.getCoordinate();
310 }
311 
312 } //namespace geos.triangulate.quadedge
313 } //namespace geos.triangulate
314 } //namespace geos
315 
316 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
317 
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:223
double y
y-coordinate
Definition: Coordinate.h:83
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
std::unique_ptr< Vertex > times(double c) const
Definition: Vertex.h:163
Models a site (node) in a QuadEdgeSubdivision.
Definition: Vertex.h:60
bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const
Definition: Vertex.h:210
double dot(Vertex v) const
Definition: Vertex.h:151
static bool isInCircleRobust(const Coordinate &a, const Coordinate &b, const Coordinate &c, const Coordinate &p)
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
double distance(const Coordinate &p) const
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
double crossProduct(const Vertex &v) const
Definition: Vertex.h:139