GEOS  3.8.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 
28 
29 //fwd declarations
30 namespace geos {
31 namespace triangulate {
32 namespace quadedge {
33 class QuadEdge;
34 }
35 }
36 }
37 
38 namespace geos {
39 namespace triangulate { //geos.triangulate
40 namespace quadedge { //geos.triangulate.quadedge
41 
59 class GEOS_DLL Vertex {
60 public:
61  static const int LEFT = 0;
62  static const int RIGHT = 1;
63  static const int BEYOND = 2;
64  static const int BEHIND = 3;
65  static const int BETWEEN = 4;
66  static const int ORIGIN = 5;
67  static const int DESTINATION = 6;
68 private:
70 
71 public:
72  Vertex(double _x, double _y);
73 
74  Vertex(double _x, double _y, double _z);
75 
76  Vertex(const geom::Coordinate& _p);
77 
78  Vertex();
79  virtual ~Vertex() {};
80 
81  inline double
82  getX() const
83  {
84  return p.x;
85  }
86 
87  inline double
88  getY() const
89  {
90  return p.y;
91  }
92 
93  inline double
94  getZ() const
95  {
96  return p.z;
97  }
98 
99  inline void
100  setZ(double _z)
101  {
102  p.z = _z;
103  }
104 
105  inline const geom::Coordinate&
106  getCoordinate() const
107  {
108  return p;
109  }
110 
111  inline bool
112  equals(const Vertex& _x) const
113  {
114  if(p.x == _x.getX() && p.y == _x.getY()) {
115  return true;
116  }
117  return false;
118  }
119 
120  inline bool
121  equals(const Vertex& _x, double tolerance) const
122  {
123  if(p.distance(_x.getCoordinate()) < tolerance) {
124  return true;
125  }
126  return false;
127  }
128 
129  virtual int classify(const Vertex& p0, const Vertex& p1);
130 
137  inline double
138  crossProduct(const Vertex& v) const
139  {
140  return (p.x * v.getY() - p.y * v.getX());
141  }
142 
149  inline double
150  dot(Vertex v) const
151  {
152  return (p.x * v.getX() + p.y * v.getY());
153  }
154 
161  inline std::unique_ptr<Vertex>
162  times(double c) const
163  {
164  return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
165  }
166 
167  /* Vector addition */
168  inline std::unique_ptr<Vertex>
169  sum(Vertex v) const
170  {
171  return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
172  }
173 
174  /* and subtraction */
175  inline std::unique_ptr<Vertex>
176  sub(const Vertex& v) const
177  {
178  return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
179  }
180 
181  /* magnitude of vector */
182  inline double
183  magn() const
184  {
185  return (sqrt(p.x * p.x + p.y * p.y));
186  }
187 
188  /* returns k X v (cross product). this is a vector perpendicular to v */
189  inline std::unique_ptr<Vertex>
190  cross() const
191  {
192  return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
193  }
194 
196  /***********************************************************************************************
197  * Geometric primitives /
198  **********************************************************************************************/
199 
209  virtual bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const;
210 
219  inline bool
220  isCCW(const Vertex& b, const Vertex& c) const
221  {
222  // is equal to the signed area of the triangle
223 
224  return (b.p.x - p.x) * (c.p.y - p.y)
225  - (b.p.y - p.y) * (c.p.x - p.x) > 0;
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 sqrt(pow(v2.getX() - v1.getX(), 2.0)
238  + pow(v2.getY() - v1.getY(), 2.0));
239  }
240 
251  virtual double circumRadiusRatio(const Vertex& b, const Vertex& c);
252 
259  virtual std::unique_ptr<Vertex> midPoint(const Vertex& a);
260 
268  virtual std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
269 
274  virtual double interpolateZValue(const Vertex& v0, const Vertex& v1,
275  const Vertex& v2) const;
276 
290  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
291  const geom::Coordinate& v1, const geom::Coordinate& v2);
292 
301  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
302  const geom::Coordinate& p1);
303 };
304 
305 inline bool
306 operator<(const Vertex& v1, const Vertex& v2)
307 {
308  return v1.getCoordinate() < v2.getCoordinate();
309 }
310 
311 } //namespace geos.triangulate.quadedge
312 } //namespace geos.triangulate
313 } //namespace geos
314 
315 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
316 
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:220
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:162
Models a site (node) in a QuadEdgeSubdivision.
Definition: Vertex.h:59
double dot(Vertex v) const
Definition: Vertex.h:150
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
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:51
double crossProduct(const Vertex &v) const
Definition: Vertex.h:138