Additional sanity checks for triangulate operation

This commit is contained in:
Piotr Kania 2021-04-29 11:51:05 +02:00
parent 4a323bf6d5
commit 905a765c0f
3 changed files with 25 additions and 7 deletions

View File

@ -77,7 +77,13 @@ void Sweep::FinalizationPolygon(SweepContext& tcx)
Node& Sweep::PointEvent(SweepContext& tcx, Point& point)
{
Node& node = tcx.LocateNode(point);
Node* node_ptr = tcx.LocateNode(point);
if (!node_ptr || !node_ptr->point || !node_ptr->next || !node_ptr->next->point)
{
throw std::runtime_error("PointEvent - null node");
}
Node& node = *node_ptr;
Node& new_node = NewFrontTriangle(tcx, point, node);
// Only need to check +epsilon since point never have smaller
@ -775,10 +781,22 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
if (ot_ptr == nullptr) {
throw std::runtime_error("FlipScanEdgeEvent - null neighbor across");
}
Triangle& ot = *ot_ptr;
Point& op = *ot.OppositePoint(t, p);
if (InScanArea(eq, *flip_triangle.PointCCW(eq), *flip_triangle.PointCW(eq), op)) {
Point* op_ptr = ot_ptr->OppositePoint(t, p);
if (op_ptr == nullptr) {
throw std::runtime_error("FlipScanEdgeEvent - null opposing point");
}
Point* p1 = flip_triangle.PointCCW(eq);
Point* p2 = flip_triangle.PointCW(eq);
if (p1 == nullptr || p2 == nullptr) {
throw std::runtime_error("FlipScanEdgeEvent - null on either of points");
}
Triangle& ot = *ot_ptr;
Point& op = *op_ptr;
if (InScanArea(eq, *p1, *p2, op)) {
// flip with new edge op->eq
FlipEdgeEvent(tcx, eq, op, &ot, op);
// TODO: Actually I just figured out that it should be possible to

View File

@ -114,10 +114,10 @@ void SweepContext::AddToMap(Triangle* triangle)
map_.push_back(triangle);
}
Node& SweepContext::LocateNode(const Point& point)
Node* SweepContext::LocateNode(const Point& point)
{
// TODO implement search tree
return *front_->LocateNode(point.x);
return front_->LocateNode(point.x);
}
void SweepContext::CreateAdvancingFront()

View File

@ -66,7 +66,7 @@ Point* tail() const;
size_t point_count() const;
Node& LocateNode(const Point& point);
Node* LocateNode(const Point& point);
void RemoveNode(Node* node);