10#ifndef CDT_obwOaxOTdAWcLNTlNnaq
11#define CDT_obwOaxOTdAWcLNTlNnaq
13#ifdef CDT_DONT_USE_BOOST_RTREE
15typedef char CDT_DONT_USE_BOOST_RTREE__was__replaced__with__CDT_USE_BOOST[-1];
21#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
22#define CDT_CXX11_IS_SUPPORTED
23#elif !defined(__cplusplus) && !defined(_MSC_VER)
29#ifdef CDT_CXX11_IS_SUPPORTED
31#define CDT_NOEXCEPT noexcept
33#define CDT_NOEXCEPT throw()
39#ifdef CDT_USE_AS_COMPILED_LIBRARY
40#define CDT_INLINE_IF_HEADER_ONLY
41#include "cdt_export.h"
47#define CDT_INLINE_IF_HEADER_ONLY inline
62#define CDT_M_PI 3.14159265358979323846
65#ifdef CDT_USE_STRONG_TYPING
66#include <boost/serialization/strong_typedef.hpp>
70#ifdef CDT_CXX11_IS_SUPPORTED
76#include <unordered_map>
77#include <unordered_set>
79#ifdef CDT_DISABLE_EXCEPTIONS
91using std::unordered_map;
92using std::unordered_set;
96#include <boost/array.hpp>
97#include <boost/functional/hash.hpp>
98#include <boost/lexical_cast.hpp>
99#include <boost/tuple/tuple.hpp>
100#include <boost/tuple/tuple_comparison.hpp>
101#include <boost/unordered_map.hpp>
102#include <boost/unordered_set.hpp>
107using boost::make_tuple;
110using boost::unordered_map;
111using boost::unordered_set;
114std::string to_string(
const T& value)
116 return boost::lexical_cast<std::string>(value);
124#define CDT_ENSURE_PRECISE_MATH \
125 __pragma(float_control(push)) __pragma(float_control(precise, on)) \
126 __pragma(fp_contract(off))
127#elif defined(__clang__)
128#define CDT_ENSURE_PRECISE_MATH \
129 _Pragma("float_control(push)") _Pragma("float_control(precise, on)") \
130 _Pragma("clang fp contract(off)")
131#elif defined(__GNUC__)
132#define CDT_ENSURE_PRECISE_MATH \
133 _Pragma("GCC push_options") _Pragma("GCC optimize(\"no-fast-math\")") \
134 _Pragma("GCC optimize(\"fp-contract=off\")")
136#define CDT_ENSURE_PRECISE_MATH _Pragma("STDC FP_CONTRACT OFF")
141#define CDT_RESTORE_MATH_SETTINGS __pragma(float_control(pop))
142#elif defined(__clang__)
143#define CDT_RESTORE_MATH_SETTINGS _Pragma("float_control(pop)")
144#elif defined(__GNUC__)
145#define CDT_RESTORE_MATH_SETTINGS _Pragma("GCC pop_options")
147#define CDT_RESTORE_MATH_SETTINGS _Pragma("STDC FP_CONTRACT DEFAULT")
151#ifdef CDT_ENSURE_PRECISE_MATH_IN_CONSTRUCTIONS
152#define CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS CDT_ENSURE_PRECISE_MATH
153#define CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS CDT_RESTORE_MATH_SETTINGS
155#define CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS
156#define CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS
163void handleException(
const T& error)
165#ifdef CDT_DISABLE_EXCEPTIONS
174array<T, 3>
arr3(
const T& v0,
const T& v1,
const T& v2)
176 const array<T, 3> out = {v0, v1, v2};
184 const array<T, 3> out = {v, v, v};
226 return lhs.
x == rhs.
x && lhs.
y == rhs.
y;
233 return !(lhs == rhs);
236#ifdef CDT_USE_64_BIT_INDEX_TYPE
237typedef unsigned long long IndexSizeType;
239typedef unsigned int IndexSizeType;
242#ifdef CDT_USE_STRONG_TYPING
259const static Index invalidIndex(std::numeric_limits<Index>::max());
261const static IndexSizeType
262 invalidIndexSizeType(std::numeric_limits<IndexSizeType>::max());
265const static IndexSizeType nSuperTriVerts(3);
267const static TriInd noNeighbor(invalidIndexSizeType);
269const static VertInd noVertex(invalidIndexSizeType);
284 :
min(std::numeric_limits<T>::
max(), std::numeric_limits<T>::
max())
285 ,
max(-std::numeric_limits<T>::
max(), -std::numeric_limits<T>::
max())
297 min.x = std::min(x,
min.x);
298 max.x = std::max(x,
max.x);
299 min.y = std::min(y,
min.y);
300 max.y = std::max(y,
max.y);
306 typename TVertexIter,
307 typename TGetVertexCoordX,
308 typename TGetVertexCoordY>
312 TGetVertexCoordX getX,
313 TGetVertexCoordY getY)
315 for(; first != last; ++first)
337 iV1 < iV2 ? std::make_pair(iV1, iV2) : std::make_pair(iV2, iV1))
343 return m_vertices == other.m_vertices;
356 return m_vertices < other.m_vertices;
362 return m_vertices.first;
368 return m_vertices.second;
372 const std::pair<VertInd, VertInd>&
verts()
const
378 std::pair<VertInd, VertInd> m_vertices;
396 return Edge(iV1, iV2);
510CDT_EXPORT T
orient2D(
const V2d<T>& p,
const V2d<T>& v1,
const V2d<T>& v2);
518 T orientationTolerance = T(0));
540CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
544CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
548CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
552CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
556CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
TriInd
560CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
TriInd
564CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
VertInd
576CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
bool
581CDT_EXPORT T
distance(
const V2d<T>& a,
const V2d<T>& b);
588CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
bool
596bool isEncroachingOnEdge(
598 const V2d<T>& edgeStart,
599 const V2d<T>& edgeEnd);
603T doubledArea(
const V2d<T>& a,
const V2d<T>& b,
const V2d<T>& c);
607T sineOfSmallestAngle(
const V2d<T>& a,
const V2d<T>& b,
const V2d<T>& c);
629#ifndef CDT_USE_AS_COMPILED_LIBRARY
636#ifdef CDT_CXX11_IS_SUPPORTED
643#ifdef CDT_USE_STRONG_TYPING
652 return std::hash<std::size_t>()(vi.t);
663 return std::hash<std::size_t>()(vi.t);
680 static void hashCombine(std::size_t& seed,
const CDT::VertInd& key)
682#ifdef CDT_CXX11_IS_SUPPORTED
683 typedef std::hash<CDT::VertInd> Hasher;
685 typedef boost::hash<CDT::VertInd> Hasher;
687 seed ^= Hasher()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
690 static std::size_t hashEdge(
const CDT::Edge& e)
693 hashCombine(seed, e.
v1());
694 hashCombine(seed, e.
v2());
char couldnt_parse_cxx_standard[-1]
Error: couldn't parse standard.
Utilities and helpers - implementation.
Namespace containing triangulation functionality.
std::vector< Edge > EdgeVec
Vector of edges.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY VertInd opposedVertex(const Triangle &tri, TriInd iTopo)
Given two triangles, return vertex of first triangle opposed to the second.
unordered_set< Edge > EdgeUSet
Hash table of edges.
CDT_EXPORT T degToRad(T degrees)
Convert an angle from degrees to radians.
std::queue< TriInd > TriIndQueue
Queue of triangles.
VertInd edge_get_v2(const Edge &e)
Get edge second vertex.
CDT_EXPORT T area(const V2d< T > &a, const V2d< T > &b, const V2d< T > &c)
Surface area of a triangle ABC.
std::vector< TriInd > TriIndVec
Vector of triangle indices.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index edgeNeighborInd(const VerticesArr3 &vv, VertInd iVedge1, VertInd iVedge2)
Index of triangle's neighbor opposed to an edge.
VertInd edge_get_v1(const Edge &e)
Get edge first vertex.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index opposedTriangleInd(const VerticesArr3 &vv, VertInd iVert)
Index of triangle's neighbor opposed to a vertex.
CDT_EXPORT PtLineLocation::Enum classifyOrientation(T orientation, T orientationTolerance=T(0))
Classify value of orient2d predicate.
array< TriInd, 3 > NeighborsArr3
array of three neighbors
CDT_EXPORT T distance(const V2d< T > &a, const V2d< T > &b)
Distance between two 2D points.
IndexSizeType VertInd
Vertex index.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY bool verticesShareEdge(const TriIndVec &aTris, const TriIndVec &bTris)
Test if two vertices share at least one common triangle.
CDT_EXPORT Index cw(Index i)
Advance vertex or neighbor index clockwise.
array< VertInd, 3 > VerticesArr3
array of three vertex indices
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY bool touchesSuperTriangle(const Triangle &t)
Check if any of triangle's vertices belongs to a super-triangle.
array< T, 3 > arr3(const T &v0, const T &v1, const T &v2)
Needed for c++03 compatibility (no uniform initialization available)
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index opoVrt(Index neighborIndex)
Opposed vertex index from neighbor index.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index opoNbr(Index vertIndex)
Opposed neighbor index from vertex index.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index vertexInd(const VerticesArr3 &vv, VertInd iV)
If triangle has a given vertex return vertex-index.
CDT_EXPORT T orient2D(const V2d< T > &p, const V2d< T > &v1, const V2d< T > &v2)
Orient p against line v1-v2 2D: robust geometric predicate.
CDT_EXPORT PtLineLocation::Enum locatePointLine(const V2d< T > &p, const V2d< T > &v1, const V2d< T > &v2, T orientationTolerance=T(0))
Check if point lies to the left of, to the right of, or on a line.
CDT_EXPORT T distanceSquared(const V2d< T > &a, const V2d< T > &b)
Squared distance between two 2D points.
unordered_set< TriInd > TriIndUSet
Hash table of triangles.
CDT_EXPORT Index ccw(Index i)
Advance vertex or neighbor index counter-clockwise.
CDT_EXPORT V2d< T > circumcenter(V2d< T > a, V2d< T > b, V2d< T > c)
Position of ABC triangle circumcenter.
Edge edge_make(VertInd iV1, VertInd iV2)
Get edge second vertex.
bool operator!=(const CDT::V2d< T > &lhs, const CDT::V2d< T > &rhs)
If two 2D vectors are not exactly equal.
CDT_EXPORT Index edgeNeighbor(PtTriLocation::Enum location)
Neighbor index from a on-edge location.
unordered_map< TriInd, TriInd > TriIndUMap
Triangle hash map.
const T & getX_V2d(const V2d< T > &v)
X- coordinate getter for V2d.
bool operator==(const CDT::V2d< T > &lhs, const CDT::V2d< T > &rhs)
If two 2D vectors are exactly equal.
unsigned char Index
Index in triangle.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY TriInd opposedTriangle(const Triangle &tri, VertInd iVert)
Given triangle and a vertex find opposed triangle.
CDT_EXPORT T smallestAngle(const V2d< T > &a, const V2d< T > &b, const V2d< T > &c)
Smallest angle of triangle ABC in radians.
CDT_EXPORT bool isInCircumcircle(const V2d< T > &p, const V2d< T > &v1, const V2d< T > &v2, const V2d< T > &v3)
Test if point lies in a circumscribed circle of a triangle.
CDT_EXPORT bool isOnEdge(PtTriLocation::Enum location)
Check if location is classified as on any of three edges.
IndexSizeType TriInd
Triangle index.
CDT_EXPORT PtTriLocation::Enum locatePointTriangle(const V2d< T > &p, const V2d< T > &v1, const V2d< T > &v2, const V2d< T > &v3)
Check if point a lies inside of, outside of, or on an edge of a triangle.
std::vector< Triangle > TriangleVec
Vector of triangles.
BOOST_STRONG_TYPEDEF(unsigned char, Index)
Index in triangle.
std::queue< Edge > EdgeQueue
Queue of edges.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index opposedVertexInd(const NeighborsArr3 &nn, TriInd iTopo)
Index of triangle's vertex opposed to a triangle.
const T & getY_V2d(const V2d< T > &v)
Y-coordinate getter for V2d.
Box2d< T > & envelopPoint(const T x, const T y)
Envelop box around a point with given coordinates.
Box2d()
Box that doesn't contain any point.
V2d< T > max
max box corner
Box2d< T > & envelopPoint(const V2d< T > &p)
Envelop box around a point.
Box2d< T > & envelopPoints(TVertexIter first, TVertexIter last, TGetVertexCoordX getX, TGetVertexCoordY getY)
Envelop box around a collection of custom points.
V2d< T > min
min box corner
Box2d< T > & envelopPoints(const std::vector< V2d< T > > &vertices)
Envelop box around a collection of points.
Edge connecting two vertices: vertex with smaller index is always first.
const std::pair< VertInd, VertInd > & verts() const
Edges' vertices.
bool operator<(const Edge &other) const
Less-than operator: orders by (v1, v2); used to get a deterministic order out of hash-set iteration (...
bool operator==(const Edge &other) const
Equals operator.
VertInd v1() const
V1 getter.
bool operator!=(const Edge &other) const
Not-equals operator.
Edge(const VertInd iV1, const VertInd iV2)
Constructor.
VertInd v2() const
V2 getter.
Relative location of point to a line.
Location of point on a triangle.
VerticesArr3 vertices
triangle's three vertices
std::pair< TriInd, VertInd > prev(const VertInd i) const
Previous triangle adjacent to a vertex (counter-clockwise)
NeighborsArr3 neighbors
triangle's three neighbors
bool containsVertex(const VertInd i) const
Check if triangle contains a vertex.
Triangle(const VerticesArr3 &vertices, const NeighborsArr3 &neighbors)
Triangle with given vertices and neighbors.
Triangle()
Triangle with no vertices and no neighbors.
std::pair< TriInd, VertInd > next(const VertInd i) const
Next triangle adjacent to a vertex (clockwise)
V2d(const T x, const T y)
Vertex with given coordinates.
V2d()
Vertex with zero coordinates.
std::size_t operator()(const CDT::Edge &e) const
Hash operator.
std::size_t operator()(const CDT::TriInd &vi) const
Hash operator.
std::size_t operator()(const CDT::VertInd &vi) const
Hash operator.