9#ifndef CDT_zWlHcbQZQyBBqPgxvFDT
10#define CDT_zWlHcbQZQyBBqPgxvFDT
14#include "predicates.h"
18CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS
25 return Index((i + 1) % 3);
30 return Index((i + 2) % 3);
35 return location == PtTriLocation::OnEdge1 ||
36 location == PtTriLocation::OnEdge2 ||
37 location == PtTriLocation::OnEdge3;
43 return static_cast<Index>(location - PtTriLocation::OnEdge1);
49 return predicates::orient2d(v1.
x, v1.
y, v2.
x, v2.
y, p.
x, p.
y);
57 const T orientationTolerance)
66 if(orientation < -orientationTolerance)
67 return PtLineLocation::Right;
68 if(orientation > orientationTolerance)
69 return PtLineLocation::Left;
70 return PtLineLocation::OnLine;
82 if(edgeCheck == PtLineLocation::Right)
83 return PtTriLocation::Outside;
84 if(edgeCheck == PtLineLocation::OnLine)
85 result = PtTriLocation::OnEdge1;
87 if(edgeCheck == PtLineLocation::Right)
88 return PtTriLocation::Outside;
89 if(edgeCheck == PtLineLocation::OnLine)
91 result = (result == PtTriLocation::Inside) ? PtTriLocation::OnEdge2
92 : PtTriLocation::OnVertex;
95 if(edgeCheck == PtLineLocation::Right)
96 return PtTriLocation::Outside;
97 if(edgeCheck == PtLineLocation::OnLine)
99 result = (result == PtTriLocation::Inside) ? PtTriLocation::OnEdge3
100 : PtTriLocation::OnVertex;
107 if(vertIndex ==
Index(0))
109 if(vertIndex ==
Index(1))
111 if(vertIndex ==
Index(2))
113 assert(
false &&
"Invalid vertex index");
114 handleException(std::runtime_error(
"Invalid vertex index"));
120 if(neighborIndex ==
Index(0))
122 if(neighborIndex ==
Index(1))
124 if(neighborIndex ==
Index(2))
126 assert(
false &&
"Invalid neighbor index");
127 handleException(std::runtime_error(
"Invalid neighbor index"));
131CDT_INLINE_IF_HEADER_ONLY
Index
134 assert(vv[0] == iVert || vv[1] == iVert || vv[2] == iVert);
147 assert(vv[0] == iVedge1 || vv[1] == iVedge1 || vv[2] == iVedge1);
148 assert(vv[0] == iVedge2 || vv[1] == iVedge2 || vv[2] == iVedge2);
150 (vv[0] != iVedge1 && vv[0] != iVedge2) ||
151 (vv[1] != iVedge1 && vv[1] != iVedge2) ||
152 (vv[2] != iVedge1 && vv[2] != iVedge2));
175CDT_INLINE_IF_HEADER_ONLY
Index
178 assert(nn[0] == iTopo || nn[1] == iTopo || nn[2] == iTopo);
186CDT_INLINE_IF_HEADER_ONLY
Index
189 assert(vv[0] == iV || vv[1] == iV || vv[2] == iV);
197CDT_INLINE_IF_HEADER_ONLY
TriInd
203CDT_INLINE_IF_HEADER_ONLY
VertInd
210CDT_INLINE_IF_HEADER_ONLY
TriInd
223 return predicates::incircle(v1.
x, v1.
y, v2.
x, v2.
y, v3.
x, v3.
y, p.
x, p.
y) >
227CDT_INLINE_IF_HEADER_ONLY
230 for(TriIndVec::const_iterator it = aTris.begin(); it != aTris.end(); ++it)
231 if(std::find(bTris.begin(), bTris.end(), *it) != bTris.end())
239 const T dx = bx - ax;
240 const T dy = by - ay;
241 return dx * dx + dy * dy;
245T
distance(
const T ax,
const T ay,
const T bx,
const T by)
278 return predicates::indiamcircle(
279 edgeStart.
x, edgeStart.
y, edgeEnd.
x, edgeEnd.
y, v.
x, v.
y) >
295 std::swap(sideA, sideB);
296 sideA = std::max(sideA,
distance(a, c));
311 const T denom = T(2) *
orient2D(a, b, c);
312 assert(denom != T(0));
314 a.
x -= c.
x, a.
y -= c.
y;
315 b.
x -= c.
x, b.
y -= c.
y;
316 c.
x += (b.
y * aLenSq - a.
y * bLenSq) / denom;
317 c.
y += (a.
x * bLenSq - b.
x * aLenSq) / denom;
325 assert(angleSine >= -1 && angleSine <= 1);
326 return std::asin(angleSine);
332 return degrees / T(180) * T(CDT_M_PI);
337CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS
T sineOfSmallestAngle(const V2d< T > &a, const V2d< T > &b, const V2d< T > &c)
Sine of smallest angle of triangle ABC.
bool isEncroachingOnEdge(const V2d< T > &v, const V2d< T > &edgeStart, const V2d< T > &edgeEnd)
Check if vertex V is encroaching on diametral circle of an edge.
T doubledArea(const V2d< T > &a, const V2d< T > &b, const V2d< T > &c)
Doubled surface area of a triangle ABC.
Namespace containing triangulation functionality.
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.
CDT_EXPORT T degToRad(T degrees)
Convert an angle from degrees to radians.
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.
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.
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.
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.
CDT_EXPORT Index edgeNeighbor(PtTriLocation::Enum location)
Neighbor index from a on-edge location.
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.
CDT_EXPORT CDT_INLINE_IF_HEADER_ONLY Index opposedVertexInd(const NeighborsArr3 &nn, TriInd iTopo)
Index of triangle's vertex opposed to a triangle.
Triangulation triangle (counter-clockwise winding)
VerticesArr3 vertices
triangle's three vertices
NeighborsArr3 neighbors
triangle's three neighbors