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/unordered_map.hpp>
101#include <boost/unordered_set.hpp>
106using boost::make_tuple;
109using boost::unordered_map;
110using boost::unordered_set;
113std::string to_string(
const T& value)
115 return boost::lexical_cast<std::string>(value);
122#define CDT_ENSURE_PRECISE_MATH \
123 __pragma(float_control(push)) \
124 __pragma(float_control(precise, on)) \
125 __pragma(fp_contract(off))
126#elif defined(__clang__)
127#define CDT_ENSURE_PRECISE_MATH \
128 _Pragma("float_control(push)") \
129 _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") \
134 _Pragma("GCC optimize(\"no-fast-math\")") \
135 _Pragma("GCC optimize(\"fp-contract=off\")")
137#define CDT_ENSURE_PRECISE_MATH _Pragma("STDC FP_CONTRACT OFF")
142#define CDT_RESTORE_MATH_SETTINGS __pragma(float_control(pop))
143#elif defined(__clang__)
144#define CDT_RESTORE_MATH_SETTINGS _Pragma("float_control(pop)")
145#elif defined(__GNUC__)
146#define CDT_RESTORE_MATH_SETTINGS _Pragma("GCC pop_options")
148#define CDT_RESTORE_MATH_SETTINGS _Pragma("STDC FP_CONTRACT DEFAULT")
152#ifdef CDT_ENSURE_PRECISE_MATH_IN_CONSTRUCTIONS
153#define CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS CDT_ENSURE_PRECISE_MATH
154#define CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS CDT_RESTORE_MATH_SETTINGS
156#define CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS
157#define CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS
164void handleException(
const T& error)
166#ifdef CDT_DISABLE_EXCEPTIONS
175array<T, 3>
arr3(
const T& v0,
const T& v1,
const T& v2)
177 const array<T, 3> out = {v0, v1, v2};
185 const array<T, 3> out = {v, v, v};
227 return lhs.
x == rhs.
x && lhs.
y == rhs.
y;
234 return !(lhs == rhs);
237#ifdef CDT_USE_64_BIT_INDEX_TYPE
238typedef unsigned long long IndexSizeType;
240typedef unsigned int IndexSizeType;
243#ifdef CDT_USE_STRONG_TYPING
260const static Index invalidIndex(std::numeric_limits<Index>::max());
262const static IndexSizeType
263 invalidIndexSizeType(std::numeric_limits<IndexSizeType>::max());
266const static IndexSizeType nSuperTriVerts(3);
268const static TriInd noNeighbor(invalidIndexSizeType);
270const static VertInd noVertex(invalidIndexSizeType);
285 :
min(std::numeric_limits<T>::
max(), std::numeric_limits<T>::
max())
286 ,
max(-std::numeric_limits<T>::
max(), -std::numeric_limits<T>::
max())
298 min.x = std::min(x,
min.x);
299 max.x = std::max(x,
max.x);
300 min.y = std::min(y,
min.y);
301 max.y = std::max(y,
max.y);
307 typename TVertexIter,
308 typename TGetVertexCoordX,
309 typename TGetVertexCoordY>
313 TGetVertexCoordX getX,
314 TGetVertexCoordY getY)
316 for(; first != last; ++first)
338 iV1 < iV2 ? std::make_pair(iV1, iV2) : std::make_pair(iV2, iV1))
344 return m_vertices == other.m_vertices;
357 return m_vertices < other.m_vertices;
363 return m_vertices.first;
369 return m_vertices.second;
373 const std::pair<VertInd, VertInd>&
verts()
const
379 std::pair<VertInd, VertInd> m_vertices;
397 return Edge(iV1, iV2);
511CDT_EXPORT T
orient2D(
const V2d<T>& p,
const V2d<T>& v1,
const V2d<T>& v2);
519 T orientationTolerance = T(0));
541CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
545CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
549CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
553CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
Index
557CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
TriInd
561CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
TriInd
565CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
VertInd
577CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
bool
582CDT_EXPORT T
distance(
const V2d<T>& a,
const V2d<T>& b);
589CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY
bool
597bool isEncroachingOnEdge(
599 const V2d<T>& edgeStart,
600 const V2d<T>& edgeEnd);
604T doubledArea(
const V2d<T>& a,
const V2d<T>& b,
const V2d<T>& c);
608T sineOfSmallestAngle(
const V2d<T>& a,
const V2d<T>& b,
const V2d<T>& c);
630#ifndef CDT_USE_AS_COMPILED_LIBRARY
637#ifdef CDT_CXX11_IS_SUPPORTED
644#ifdef CDT_USE_STRONG_TYPING
653 return std::hash<std::size_t>()(vi.t);
664 return std::hash<std::size_t>()(vi.t);
681 static void hashCombine(std::size_t& seed,
const CDT::VertInd& key)
683#ifdef CDT_CXX11_IS_SUPPORTED
684 typedef std::hash<CDT::VertInd> Hasher;
686 typedef boost::hash<CDT::VertInd> Hasher;
688 seed ^= Hasher()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
691 static std::size_t hashEdge(
const CDT::Edge& e)
694 hashCombine(seed, e.
v1());
695 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.