GEOS: Vertex.h Source File

GEOS 3.5.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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 r524
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:
71 geom::Coordinate p;
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
82 inline double getX() const {
83 return p.x;
84 }
85
86 inline double getY() const {
87 return p.y;
88 }
89
90 inline double getZ() const {
91 return p.z;
92 }
93
94 inline void setZ(double _z) {
95 p.z = _z;
96 }
97
98 inline const geom::Coordinate& getCoordinate() const {
99 return p;
100 }
101
102 inline bool equals(const Vertex &_x) const
103 {
104 if (p.x == _x.getX() && p.y == _x.getY())
105 return true;
106 return false;
107 }
108
109 inline bool equals(const Vertex &_x, double tolerance) const
110 {
111 if (p.distance(_x.getCoordinate()) < tolerance)
112 return true;
113 return false;
114 }
115
116 virtual int classify(const Vertex &p0, const Vertex &p1);
117
124 inline double crossProduct(const Vertex &v) const
125 {
126 return (p.x * v.getY() - p.y * v.getX());
127 }
128
135 inline double dot(Vertex v) const
136 {
137 return (p.x * v.getX() + p.y * v.getY());
138 }
139
146 inline std::auto_ptr<Vertex> times(double c) const {
147 return std::auto_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
148 }
149
150 /* Vector addition */
151 inline std::auto_ptr<Vertex> sum(Vertex v) const {
152 return std::auto_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
153 }
154
155 /* and subtraction */
156 inline std::auto_ptr<Vertex> sub(const Vertex &v) const {
157 return std::auto_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
158 }
159
160 /* magnitude of vector */
161 inline double magn() const {
162 return (sqrt(p.x * p.x + p.y * p.y));
163 }
164
165 /* returns k X v (cross product). this is a vector perpendicular to v */
166 inline std::auto_ptr<Vertex> cross() const {
167 return std::auto_ptr<Vertex>(new Vertex(p.y, -p.x));
168 }
169
171 /***********************************************************************************************
172 * Geometric primitives /
173 **********************************************************************************************/
174
184 virtual bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const;
185
194 inline bool isCCW(const Vertex &b, const Vertex &c) const
195 {
196 // is equal to the signed area of the triangle
197
198 return (b.p.x - p.x) * (c.p.y - p.y)
199 - (b.p.y - p.y) * (c.p.x - p.x) > 0;
200 }
201
202 bool rightOf(const QuadEdge &e) const;
203 bool leftOf(const QuadEdge &e) const;
204
205 private:
206 static std::auto_ptr<algorithm::HCoordinate> bisector(const Vertex &a, const Vertex &b);
207
208 inline double distance(const Vertex &v1, const Vertex &v2)
209 {
210 return sqrt(pow(v2.getX() - v1.getX(), 2.0)
211 + pow(v2.getY() - v1.getY(), 2.0));
212 }
213
224 virtual double circumRadiusRatio(const Vertex &b, const Vertex &c);
225
232 virtual std::auto_ptr<Vertex> midPoint(const Vertex &a);
233
241 virtual std::auto_ptr<Vertex> circleCenter(const Vertex &b, const Vertex &c) const;
242
247 virtual double interpolateZValue(const Vertex &v0, const Vertex &v1,
248 const Vertex &v2) const;
249
253 static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &v0,
254 const geom::Coordinate &v1, const geom::Coordinate &v2);
255
264 static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0,
265 const geom::Coordinate &p1);
266 };
267
268 inline bool operator<(const Vertex& v1, const Vertex& v2) {
269 return v1.getCoordinate() < v2.getCoordinate();
270 }
271
272 } //namespace geos.triangulate.quadedge
273 } //namespace geos.triangulate
274 } //namespace geos
275
276 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
277
geos::triangulate::quadedge::Vertex::times
std::auto_ptr< Vertex > times(double c) const
Definition: Vertex.h:146
geos::triangulate::quadedge::Vertex::isCCW
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:194
geos::geom::Coordinate::y
double y
y-coordinate
Definition: Coordinate.h:83
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::triangulate::quadedge::Vertex
Definition: Vertex.h:61
geos::triangulate::quadedge::Vertex::dot
double dot(Vertex v) const
Definition: Vertex.h:135
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::Coordinate::distance
double distance(const Coordinate &p) const
geos::geom::Coordinate::x
double x
x-coordinate
Definition: Coordinate.h:80
geos::geom::Coordinate::z
double z
z-coordinate
Definition: Coordinate.h:86
geos::triangulate::quadedge::QuadEdge
Definition: QuadEdge.h:51
geos::triangulate::quadedge::Vertex::crossProduct
double crossProduct(const Vertex &v) const
Definition: Vertex.h:124