12#include "predicates.h"
44 iV1 < iV2 ? std::make_pair(iV1, iV2) : std::make_pair(iV2, iV1))
49 return m_vertices == other.m_vertices;
59 return m_vertices.first;
64 return m_vertices.second;
77 return Index((i + 1) % 3);
82 return Index((i + 2) % 3);
87 return location == PtTriLocation::OnEdge1 ||
88 location == PtTriLocation::OnEdge2 ||
89 location == PtTriLocation::OnEdge3;
95 return static_cast<Index>(location - PtTriLocation::OnEdge1);
101 return predicates::adaptive::orient2d(v1.
x, v1.
y, v2.
x, v2.
y, p.
x, p.
y);
109 const T orientationTolerance)
118 if(orientation < -orientationTolerance)
119 return PtLineLocation::Right;
120 if(orientation > orientationTolerance)
121 return PtLineLocation::Left;
122 return PtLineLocation::OnLine;
132 using namespace predicates::adaptive;
135 if(edgeCheck == PtLineLocation::Right)
136 return PtTriLocation::Outside;
137 if(edgeCheck == PtLineLocation::OnLine)
138 result = PtTriLocation::OnEdge1;
140 if(edgeCheck == PtLineLocation::Right)
141 return PtTriLocation::Outside;
142 if(edgeCheck == PtLineLocation::OnLine)
144 result = (result == PtTriLocation::Inside) ? PtTriLocation::OnEdge2
145 : PtTriLocation::OnVertex;
148 if(edgeCheck == PtLineLocation::Right)
149 return PtTriLocation::Outside;
150 if(edgeCheck == PtLineLocation::OnLine)
152 result = (result == PtTriLocation::Inside) ? PtTriLocation::OnEdge3
153 : PtTriLocation::OnVertex;
160 if(vertIndex ==
Index(0))
162 if(vertIndex ==
Index(1))
164 if(vertIndex ==
Index(2))
166 assert(
false &&
"Invalid vertex index");
167 throw std::runtime_error(
"Invalid vertex index");
172 if(neighborIndex ==
Index(0))
174 if(neighborIndex ==
Index(1))
176 if(neighborIndex ==
Index(2))
178 assert(
false &&
"Invalid neighbor index");
179 throw std::runtime_error(
"Invalid neighbor index");
185 assert(vv[0] == iVert || vv[1] == iVert || vv[2] == iVert);
198 assert(vv[0] == iVedge1 || vv[1] == iVedge1 || vv[2] == iVedge1);
199 assert(vv[0] == iVedge2 || vv[1] == iVedge2 || vv[2] == iVedge2);
201 (vv[0] != iVedge1 && vv[0] != iVedge2) ||
202 (vv[1] != iVedge1 && vv[1] != iVedge2) ||
203 (vv[2] != iVedge1 && vv[2] != iVedge2));
229 assert(nn[0] == iTopo || nn[1] == iTopo || nn[2] == iTopo);
240 assert(vv[0] == iV || vv[1] == iV || vv[2] == iV);
274 using namespace predicates::adaptive;
275 return incircle(v1.
x, v1.
y, v2.
x, v2.
y, v3.
x, v3.
y, p.
x, p.
y) > T(0);
281 for(TriIndVec::const_iterator it = aTris.begin(); it != aTris.end(); ++it)
282 if(std::find(bTris.begin(), bTris.end(), *it) != bTris.end())
290 const T dx = bx - ax;
291 const T dy = by - ay;
292 return dx * dx + dy * dy;
296T
distance(
const T ax,
const T ay,
const T bx,
const T by)
#define CDT_INLINE_IF_HEADER_ONLY
Macro for inlining non-template functions when in header-only mode to avoid multiple declaration erro...
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.
std::vector< TriInd > TriIndVec
Vector of triangle indices.
Box2d< T > envelopBox(TVertexIter first, TVertexIter last, TGetVertexCoordX getX, TGetVertexCoordY getY)
Bounding box of a collection of custom 2D points given coordinate getters.
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_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 Index edgeNeighbor(PtTriLocation::Enum location)
Neighbor index from a on-edge location.
const T & getX_V2d(const V2d< T > &v)
X- coordinate getter for V2d.
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 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.
const T & getY_V2d(const V2d< T > &v)
Y-coordinate getter for V2d.
Edge connecting two vertices: vertex with smaller index is always first.
bool operator==(const Edge &other) const
Equals operator.
bool operator!=(const Edge &other) const
Not-equals operator.
const std::pair< VertInd, VertInd > & verts() const
Edges' vertices.
Edge(VertInd iV1, VertInd iV2)
Constructor.
VertInd v2() const
V2 getter.
VertInd v1() const
V1 getter.
Triangulation triangle (counter-clockwise winding)
VerticesArr3 vertices
triangle's three vertices
NeighborsArr3 neighbors
triangle's three neighbors
static V2d make(T x, T y)
Create vector from X and Y coordinates.