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 
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  virtual ~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  if(p.x == _x.getX() && p.y == _x.getY()) {
117  return true;
118  }
119  return false;
120  }
121 
122  inline bool
123  equals(const Vertex& _x, double tolerance) const
124  {
125  if(p.distance(_x.getCoordinate()) < tolerance) {
126  return true;
127  }
128  return false;
129  }
130 
131  virtual int classify(const Vertex& p0, const Vertex& p1);
132 
139  inline double
140  crossProduct(const Vertex& v) const
141  {
142  return (p.x * v.getY() - p.y * v.getX());
143  }
144 
151  inline double
152  dot(Vertex v) const
153  {
154  return (p.x * v.getX() + p.y * v.getY());
155  }
156 
163  inline std::unique_ptr<Vertex>
164  times(double c) const
165  {
166  return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
167  }
168 
169  /* Vector addition */
170  inline std::unique_ptr<Vertex>
171  sum(Vertex v) const
172  {
173  return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
174  }
175 
176  /* and subtraction */
177  inline std::unique_ptr<Vertex>
178  sub(const Vertex& v) const
179  {
180  return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
181  }
182 
183  /* magnitude of vector */
184  inline double
185  magn() const
186  {
187  return (sqrt(p.x * p.x + p.y * p.y));
188  }
189 
190  /* returns k X v (cross product). this is a vector perpendicular to v */
191  inline std::unique_ptr<Vertex>
192  cross() const
193  {
194  return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
195  }
196 
198  /***********************************************************************************************
199  * Geometric primitives /
200  **********************************************************************************************/
201 
211  virtual bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const;
212 
221  inline bool
222  isCCW(const Vertex& b, const Vertex& c) const
223  {
224  // is equal to the signed area of the triangle
225 
226  return (b.p.x - p.x) * (c.p.y - p.y)
227  - (b.p.y - p.y) * (c.p.x - p.x) > 0;
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  virtual double circumRadiusRatio(const Vertex& b, const Vertex& c);
254 
261  virtual std::unique_ptr<Vertex> midPoint(const Vertex& a);
262 
270  virtual std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
271 
276  virtual double interpolateZValue(const Vertex& v0, const Vertex& v1,
277  const Vertex& v2) const;
278 
292  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
293  const geom::Coordinate& v1, const geom::Coordinate& v2);
294 
303  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
304  const geom::Coordinate& p1);
305 };
306 
307 inline bool
308 operator<(const Vertex& v1, const Vertex& v2)
309 {
310  return v1.getCoordinate() < v2.getCoordinate();
311 }
312 
313 } //namespace geos.triangulate.quadedge
314 } //namespace geos.triangulate
315 } //namespace geos
316 
317 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
318 
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:222
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:164
double dot(Vertex v) const
Definition: Vertex.h:152
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
Definition: QuadEdge.h:51
double crossProduct(const Vertex &v) const
Definition: Vertex.h:140