Vertex.h

00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2012 Excensus LLC.
00007  *
00008  * This is free software; you can redistribute and/or modify it under
00009  * the terms of the GNU Lesser General Licence as published
00010  * by the Free Software Foundation. 
00011  * See the COPYING file for more information.
00012  *
00013  **********************************************************************
00014  *
00015  * Last port: triangulate/quadedge/Vertex.java r524
00016  *
00017  **********************************************************************/
00018 
00019 #ifndef GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
00020 #define GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
00021 
00022 #include <math.h>
00023 #include <memory>
00024 
00025 #include <geos/geom/Coordinate.h>
00026 #include <geos/algorithm/HCoordinate.h>
00027 
00028 
00029 //fwd declarations
00030 namespace geos {
00031 namespace triangulate {
00032 namespace quadedge {
00033         class QuadEdge;
00034 }
00035 }
00036 }
00037 
00038 namespace geos {
00039 namespace triangulate { //geos.triangulate
00040 namespace quadedge { //geos.triangulate.quadedge
00041 
00061 class GEOS_DLL Vertex {
00062 public:
00063         static const int LEFT           = 0;
00064         static const int RIGHT     = 1;
00065         static const int BEYOND   = 2;
00066         static const int BEHIND   = 3;
00067         static const int BETWEEN         = 4;
00068         static const int ORIGIN   = 5;
00069         static const int DESTINATION = 6;
00070 private:
00071         geom::Coordinate          p;
00072 
00073 public:
00074         Vertex(double _x, double _y);
00075 
00076         Vertex(double _x, double _y, double _z);
00077 
00078         Vertex(const geom::Coordinate &_p);
00079 
00080         Vertex();
00081 
00082         inline double getX() const {
00083                 return p.x;
00084         }
00085 
00086         inline double getY() const {
00087                 return p.y;
00088         }
00089 
00090         inline double getZ() const {
00091                 return p.z;
00092         }
00093 
00094         inline void setZ(double _z) {
00095                 p.z = _z;
00096         }
00097 
00098         inline const geom::Coordinate& getCoordinate() const {
00099                 return p;
00100         }
00101 
00102         inline bool equals(const Vertex &_x) const
00103         {
00104                 if (p.x == _x.getX() && p.y == _x.getY())
00105                         return true;
00106                 return false;
00107         }
00108 
00109         inline bool equals(const Vertex &_x, double tolerance) const
00110         {
00111                 if (p.distance(_x.getCoordinate()) < tolerance)
00112                         return true;
00113                 return false;
00114         }
00115 
00116         virtual int classify(const Vertex &p0, const Vertex &p1);
00117 
00124         inline double crossProduct(const Vertex &v) const
00125         {
00126                 return (p.x * v.getY() - p.y * v.getX());
00127         }
00128 
00135         inline double dot(Vertex v) const
00136         {
00137                 return (p.x * v.getX() + p.y * v.getY());
00138         }
00139 
00146         inline std::auto_ptr<Vertex> times(double c) const {
00147                 return std::auto_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
00148         }
00149 
00150         /* Vector addition */
00151         inline std::auto_ptr<Vertex> sum(Vertex v) const {
00152                 return std::auto_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
00153         }
00154 
00155         /* and subtraction */
00156         inline std::auto_ptr<Vertex> sub(const Vertex &v) const {
00157                 return std::auto_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
00158         }
00159 
00160         /* magnitude of vector */
00161         inline double magn() const {
00162                 return (sqrt(p.x * p.x + p.y * p.y));
00163         }
00164 
00165         /* returns k X v (cross product). this is a vector perpendicular to v */
00166         inline std::auto_ptr<Vertex> cross() const {
00167                 return std::auto_ptr<Vertex>(new Vertex(p.y, -p.x));
00168         }
00169 
00171   /***********************************************************************************************
00172    * Geometric primitives /
00173    **********************************************************************************************/
00174 
00184         virtual bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const;
00185 
00194         inline bool isCCW(const Vertex &b, const Vertex &c) const 
00195         {
00196                 // is equal to the signed area of the triangle
00197 
00198                 return (b.p.x - p.x) * (c.p.y - p.y) 
00199                         - (b.p.y - p.y) * (c.p.x - p.x) > 0;
00200         }
00201 
00202         bool rightOf(const QuadEdge &e) const;
00203         bool leftOf(const QuadEdge &e) const;
00204 
00205 private:
00206         static std::auto_ptr<algorithm::HCoordinate> bisector(const Vertex &a, const Vertex &b);
00207 
00208         inline double distance(const Vertex &v1, const Vertex &v2)
00209         {
00210                 return sqrt(pow(v2.getX() - v1.getX(), 2.0)
00211                                 + pow(v2.getY() - v1.getY(), 2.0));
00212         }
00213 
00224         virtual double circumRadiusRatio(const Vertex &b, const Vertex &c);
00225 
00232         virtual std::auto_ptr<Vertex> midPoint(const Vertex &a);
00233 
00241         virtual std::auto_ptr<Vertex> circleCenter(const Vertex &b, const Vertex &c) const;
00242 
00247         virtual double interpolateZValue(const Vertex &v0, const Vertex &v1,
00248                         const Vertex &v2) const;
00249 
00253         static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &v0, 
00254                         const geom::Coordinate &v1, const geom::Coordinate &v2);
00255 
00264         static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, 
00265                         const geom::Coordinate &p1);
00266 };
00267 
00268 inline bool operator<(const Vertex& v1, const Vertex& v2) {
00269   return v1.getCoordinate() < v2.getCoordinate();
00270 }
00271 
00272 } //namespace geos.triangulate.quadedge
00273 } //namespace geos.triangulate
00274 } //namespace geos
00275 
00276 #endif //GEOS_TRIANGULATE_QUADEDGE_VERTEX_H
00277 

Generated on 30 Dec 2015 for GEOS by  doxygen 1.4.7