Skip to content
Permalink
Browse files
Merge pull request #46062 from qgis/backport-46022-to-release-3_22
[Backport release-3_22] Poly2tri library update to fix crash with self-intersecting ring & fix random marker fill
  • Loading branch information
m-kuhn committed Nov 16, 2021
2 parents c82edcd + 183a15e commit 955fcb8367a5484e37ff27abddc855d8ba676f9a
@@ -35,14 +35,18 @@

namespace p2t {

Point::Point(double x, double y) : x(x), y(y)
{
}

std::ostream& operator<<(std::ostream& out, const Point& point) {
return out << point.x << "," << point.y;
}

Triangle::Triangle(Point& a, Point& b, Point& c)
{
points_[0] = &a; points_[1] = &b; points_[2] = &c;
neighbors_[0] = NULL; neighbors_[1] = NULL; neighbors_[2] = NULL;
neighbors_[0] = nullptr; neighbors_[1] = nullptr; neighbors_[2] = nullptr;
constrained_edge[0] = constrained_edge[1] = constrained_edge[2] = false;
delaunay_edge[0] = delaunay_edge[1] = delaunay_edge[2] = false;
interior_ = false;
@@ -85,36 +89,36 @@ void Triangle::Clear()
for( int i=0; i<3; i++ )
{
t = neighbors_[i];
if( t != NULL )
if( t != nullptr )
{
t->ClearNeighbor( this );
}
}
ClearNeighbors();
points_[0]=points_[1]=points_[2] = NULL;
points_[0]=points_[1]=points_[2] = nullptr;
}

void Triangle::ClearNeighbor(const Triangle *triangle )
{
if( neighbors_[0] == triangle )
{
neighbors_[0] = NULL;
neighbors_[0] = nullptr;
}
else if( neighbors_[1] == triangle )
{
neighbors_[1] = NULL;
neighbors_[1] = nullptr;
}
else
{
neighbors_[2] = NULL;
neighbors_[2] = nullptr;
}
}

void Triangle::ClearNeighbors()
{
neighbors_[0] = NULL;
neighbors_[1] = NULL;
neighbors_[2] = NULL;
neighbors_[0] = nullptr;
neighbors_[1] = nullptr;
neighbors_[2] = nullptr;
}

void Triangle::ClearDelunayEdges()
@@ -226,7 +230,7 @@ Point* Triangle::PointCW(const Point& point)
return points_[1];
}
assert(0);
return NULL;
return nullptr;
}

// The point counter-clockwise to given point
@@ -240,7 +244,18 @@ Point* Triangle::PointCCW(const Point& point)
return points_[0];
}
assert(0);
return NULL;
return nullptr;
}

// The neighbor across to given point
Triangle* Triangle::NeighborAcross(const Point& point)
{
if (&point == points_[0]) {
return neighbors_[0];
} else if (&point == points_[1]) {
return neighbors_[1];
}
return neighbors_[2];
}

// The neighbor clockwise to given point
@@ -349,17 +364,6 @@ void Triangle::SetDelunayEdgeCW(const Point& p, bool e)
}
}

// The neighbor across to given point
Triangle& Triangle::NeighborAcross(const Point& opoint)
{
if (&opoint == points_[0]) {
return *neighbors_[0];
} else if (&opoint == points_[1]) {
return *neighbors_[1];
}
return *neighbors_[2];
}

void Triangle::DebugPrint()
{
std::cout << *points_[0] << " " << *points_[1] << " " << *points_[2] << std::endl;
@@ -57,7 +57,7 @@ struct Point {
std::vector<Edge*> edge_list;

/// Construct using coordinates.
Point(double x, double y) : x(x), y(y) {}
Point(double x, double y);

/// Set this point to all zeros.
void set_zero()
@@ -176,6 +176,7 @@ void MarkConstrainedEdge(Point* p, Point* q);
int Index(const Point* p);
int EdgeIndex(const Point* p1, const Point* p2);

Triangle* NeighborAcross(const Point& point);
Triangle* NeighborCW(const Point& point);
Triangle* NeighborCCW(const Point& point);
bool GetConstrainedEdgeCCW(const Point& p);
@@ -203,8 +204,6 @@ void ClearDelunayEdges();
inline bool IsInterior();
inline void IsInterior(bool b);

Triangle& NeighborAcross(const Point& opoint);

void DebugPrint();

bool CircumcicleContains(const Point&) const;
@@ -260,7 +259,7 @@ inline bool operator ==(const Point& a, const Point& b)

inline bool operator !=(const Point& a, const Point& b)
{
return !(a.x == b.x) && !(a.y == b.y);
return !(a.x == b.x) || !(a.y == b.y);
}

/// Peform the dot product on two vectors.
@@ -46,21 +46,21 @@ Node* AdvancingFront::LocateNode(double x)
Node* node = search_node_;

if (x < node->value) {
while ((node = node->prev) != NULL) {
while ((node = node->prev) != nullptr) {
if (x >= node->value) {
search_node_ = node;
return node;
}
}
} else {
while ((node = node->next) != NULL) {
while ((node = node->next) != nullptr) {
if (x < node->value) {
search_node_ = node->prev;
return node->prev;
}
}
}
return NULL;
return nullptr;
}

Node* AdvancingFront::FindSearchNode(double x)
@@ -88,13 +88,13 @@ Node* AdvancingFront::LocatePoint(const Point* point)
}
}
} else if (px < nx) {
while ((node = node->prev) != NULL) {
while ((node = node->prev) != nullptr) {
if (point == node->point) {
break;
}
}
} else {
while ((node = node->next) != NULL) {
while ((node = node->next) != nullptr) {
if (point == node->point)
break;
}
@@ -1,5 +1,5 @@
/*
* Poly2Tri Copyright (c) 2009-2018, Poly2Tri Contributors
* Poly2Tri Copyright (c) 2009-2021, Poly2Tri Contributors
* https://github.com/jhasse/poly2tri
*
* All rights reserved.
@@ -68,4 +68,4 @@ CDT::~CDT()
delete sweep_;
}

}
} // namespace p2t
Loading

0 comments on commit 955fcb8

Please sign in to comment.