GEOS 3.11.1
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#pragma once
20
21#include <cmath>
22#include <memory>
23#include <cstring>
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
31namespace geos {
32namespace triangulate {
33namespace quadedge {
34class QuadEdge;
35}
36}
37}
38
39namespace geos {
40namespace triangulate { //geos.triangulate
41namespace quadedge { //geos.triangulate.quadedge
42
60class GEOS_DLL Vertex {
61public:
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;
69private:
71
72public:
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 return p.equals2D(_x.p);
116 }
117
118 inline bool
119 equals(const Vertex& _x, double tolerance) const
120 {
121 if(p.distance(_x.getCoordinate()) < tolerance) {
122 return true;
123 }
124 return false;
125 }
126
127 int classify(const Vertex& p0, const Vertex& p1);
128
135 inline double
136 crossProduct(const Vertex& v) const
137 {
138 return (p.x * v.getY() - p.y * v.getX());
139 }
140
147 inline double
148 dot(Vertex v) const
149 {
150 return (p.x * v.getX() + p.y * v.getY());
151 }
152
159 inline std::unique_ptr<Vertex>
160 times(double c) const
161 {
162 return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
163 }
164
165 /* Vector addition */
166 inline std::unique_ptr<Vertex>
167 sum(Vertex v) const
168 {
169 return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
170 }
171
172 /* and subtraction */
173 inline std::unique_ptr<Vertex>
174 sub(const Vertex& v) const
175 {
176 return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
177 }
178
179 /* magnitude of vector */
180 inline double
181 magn() const
182 {
183 return (std::sqrt(p.x * p.x + p.y * p.y));
184 }
185
186 /* returns k X v (cross product). this is a vector perpendicular to v */
187 inline std::unique_ptr<Vertex>
188 cross() const
189 {
190 return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
191 }
192
194 /***********************************************************************************************
195 * Geometric primitives /
196 **********************************************************************************************/
197
207 bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const {
209 }
210
219 inline bool
220 isCCW(const Vertex& b, const Vertex& c) const
221 {
222 // check if signed area is positive
223 return (b.p.x - p.x) * (c.p.y - p.y)
224 > (b.p.y - p.y) * (c.p.x - p.x);
225 }
226
227 bool rightOf(const QuadEdge& e) const;
228 bool leftOf(const QuadEdge& e) const;
229
230private:
231 static std::unique_ptr<algorithm::HCoordinate> bisector(const Vertex& a, const Vertex& b);
232
233 inline double
234 distance(const Vertex& v1, const Vertex& v2)
235 {
236 return std::sqrt(pow(v2.getX() - v1.getX(), 2.0) +
237 pow(v2.getY() - v1.getY(), 2.0));
238 }
239
250 double circumRadiusRatio(const Vertex& b, const Vertex& c);
251
258 std::unique_ptr<Vertex> midPoint(const Vertex& a);
259
267 std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
268
273 double interpolateZValue(const Vertex& v0, const Vertex& v1, const Vertex& v2) const;
274
288 static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
289 const geom::Coordinate& v1, const geom::Coordinate& v2);
290
299 static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
300 const geom::Coordinate& p1);
301};
302
303inline bool
304operator<(const Vertex& v1, const Vertex& v2)
305{
306 return v1.getCoordinate() < v2.getCoordinate();
307}
308
309} //namespace geos.triangulate.quadedge
310} //namespace geos.triangulate
311} //namespace geos
312
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
double distance(const Coordinate &p) const
Definition: Coordinate.h:191
double y
y-coordinate
Definition: Coordinate.h:81
double x
x-coordinate
Definition: Coordinate.h:78
double z
z-coordinate
Definition: Coordinate.h:84
A class that represents the edge data structure which implements the quadedge algebra.
Definition: QuadEdge.h:53
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:60
double crossProduct(const Vertex &v) const
Definition: Vertex.h:136
double dot(Vertex v) const
Definition: Vertex.h:148
bool isCCW(const Vertex &b, const Vertex &c) const
Definition: Vertex.h:220
std::unique_ptr< Vertex > times(double c) const
Definition: Vertex.h:160
bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const
Definition: Vertex.h:207
Basic namespace for all GEOS functionalities.
Definition: geos.h:39