Vertex.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2012 Excensus LLC.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: triangulate/quadedge/Vertex.java r705
*
**********************************************************************/
#pragma once
#include <cmath>
#include <memory>
#include <cstring>
#include <geos/geom/Coordinate.h>
#include <geos/algorithm/HCoordinate.h>
#include <geos/triangulate/quadedge/TrianglePredicate.h>
//fwd declarations
namespace geos {
namespace triangulate {
namespace quadedge {
class QuadEdge;
}
}
}
namespace geos {
namespace triangulate { //geos.triangulate
namespace quadedge { //geos.triangulate.quadedge
class GEOS_DLL Vertex {
public:
static const int LEFT = 0;
static const int RIGHT = 1;
static const int BEYOND = 2;
static const int BEHIND = 3;
static const int BETWEEN = 4;
static const int ORIGIN = 5;
static const int DESTINATION = 6;
private:
geom::Coordinate p;
public:
Vertex(double _x, double _y);
Vertex(double _x, double _y, double _z);
Vertex(const geom::Coordinate& _p);
Vertex();
~Vertex() {};
inline double
getX() const
{
return p.x;
}
inline double
getY() const
{
return p.y;
}
inline double
getZ() const
{
return p.z;
}
inline void
setZ(double _z)
{
p.z = _z;
}
inline const geom::Coordinate&
getCoordinate() const
{
return p;
}
inline bool
equals(const Vertex& _x) const
{
return p.equals2D(_x.p);
}
inline bool
equals(const Vertex& _x, double tolerance) const
{
if(p.distance(_x.getCoordinate()) < tolerance) {
return true;
}
return false;
}
int classify(const Vertex& p0, const Vertex& p1);
inline double
crossProduct(const Vertex& v) const
{
return (p.x * v.getY() - p.y * v.getX());
}
inline double
dot(Vertex v) const
{
return (p.x * v.getX() + p.y * v.getY());
}
inline std::unique_ptr<Vertex>
times(double c) const
{
return std::unique_ptr<Vertex>(new Vertex(c * p.x, c * p.y));
}
/* Vector addition */
inline std::unique_ptr<Vertex>
sum(Vertex v) const
{
return std::unique_ptr<Vertex>(new Vertex(p.x + v.getX(), p.y + v.getY()));
}
/* and subtraction */
inline std::unique_ptr<Vertex>
sub(const Vertex& v) const
{
return std::unique_ptr<Vertex>(new Vertex(p.x - v.getX(), p.y - v.getY()));
}
/* magnitude of vector */
inline double
magn() const
{
return (std::sqrt(p.x * p.x + p.y * p.y));
}
/* returns k X v (cross product). this is a vector perpendicular to v */
inline std::unique_ptr<Vertex>
cross() const
{
return std::unique_ptr<Vertex>(new Vertex(p.y, -p.x));
}
/***********************************************************************************************
* Geometric primitives /
**********************************************************************************************/
bool isInCircle(const Vertex& a, const Vertex& b, const Vertex& c) const {
return triangulate::quadedge::TrianglePredicate::isInCircleRobust(a.p, b.p, c.p, this->p) == geom::Location::INTERIOR;
}
inline bool
isCCW(const Vertex& b, const Vertex& c) const
{
// check if signed area is positive
return (b.p.x - p.x) * (c.p.y - p.y)
> (b.p.y - p.y) * (c.p.x - p.x);
}
bool rightOf(const QuadEdge& e) const;
bool leftOf(const QuadEdge& e) const;
private:
static std::unique_ptr<algorithm::HCoordinate> bisector(const Vertex& a, const Vertex& b);
inline double
distance(const Vertex& v1, const Vertex& v2)
{
return std::sqrt(pow(v2.getX() - v1.getX(), 2.0) +
pow(v2.getY() - v1.getY(), 2.0));
}
double circumRadiusRatio(const Vertex& b, const Vertex& c);
std::unique_ptr<Vertex> midPoint(const Vertex& a);
std::unique_ptr<Vertex> circleCenter(const Vertex& b, const Vertex& c) const;
double interpolateZValue(const Vertex& v0, const Vertex& v1, const Vertex& v2) const;
static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& v0,
const geom::Coordinate& v1, const geom::Coordinate& v2);
static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0,
const geom::Coordinate& p1);
};
inline bool
operator<(const Vertex& v1, const Vertex& v2)
{
return v1.getCoordinate() < v2.getCoordinate();
}
} //namespace geos.triangulate.quadedge
} //namespace geos.triangulate
} //namespace geos
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::triangulate::quadedge::QuadEdge
A class that represents the edge data structure which implements the quadedge algebra.
Definition QuadEdge.h:53
geos::triangulate::quadedge::TrianglePredicate::isInCircleRobust
static geom::Location isInCircleRobust(const CoordinateXY &a, const CoordinateXY &b, const CoordinateXY &c, const CoordinateXY &p)
geos::triangulate::quadedge::Vertex
Models a site (node) in a QuadEdgeSubdivision.
Definition Vertex.h:60
geos::triangulate::quadedge::Vertex::crossProduct
double crossProduct(const Vertex &v) const
Definition Vertex.h:136
geos::triangulate::quadedge::Vertex::dot
double dot(Vertex v) const
Definition Vertex.h:148
geos::triangulate::quadedge::Vertex::isCCW
bool isCCW(const Vertex &b, const Vertex &c) const
Definition Vertex.h:220
geos::triangulate::quadedge::Vertex::times
std::unique_ptr< Vertex > times(double c) const
Definition Vertex.h:160
geos::triangulate::quadedge::Vertex::isInCircle
bool isInCircle(const Vertex &a, const Vertex &b, const Vertex &c) const
Definition Vertex.h:207
geos::geom::Location::INTERIOR
@ INTERIOR
Definition Location.h:43
geos::triangulate::quadedge
Classes to implement a topological subdivision of quadeges, to support creating triangulations and Vo...
Definition ConcaveHull.h:33
geos::triangulate
Classes to compute Delaunay triangulations.
Definition ConcaveHull.h:32
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38