|
@@ -1,6 +1,6 @@
|
|
/*
|
|
/*
|
|
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
|
|
|
- * http://code.google.com/p/poly2tri/
|
|
|
|
|
|
+ * Poly2Tri Copyright (c) 2009-2018, Poly2Tri Contributors
|
|
|
|
+ * https://github.com/jhasse/poly2tri
|
|
*
|
|
*
|
|
* All rights reserved.
|
|
* All rights reserved.
|
|
*
|
|
*
|
|
@@ -28,24 +28,21 @@
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
*/
|
|
-#include <stdexcept>
|
|
|
|
#include "sweep.h"
|
|
#include "sweep.h"
|
|
#include "sweep_context.h"
|
|
#include "sweep_context.h"
|
|
#include "advancing_front.h"
|
|
#include "advancing_front.h"
|
|
#include "../common/utils.h"
|
|
#include "../common/utils.h"
|
|
|
|
|
|
-namespace p2t {
|
|
|
|
|
|
+#include <cassert>
|
|
|
|
+#include <stdexcept>
|
|
|
|
|
|
-#ifdef _MSC_VER
|
|
|
|
-# pragma warning(push)
|
|
|
|
-# pragma warning( disable : 4702 )
|
|
|
|
-#endif // _MSC_VER
|
|
|
|
|
|
+namespace p2t {
|
|
|
|
|
|
// Triangulate simple polygon with holes
|
|
// Triangulate simple polygon with holes
|
|
void Sweep::Triangulate(SweepContext& tcx)
|
|
void Sweep::Triangulate(SweepContext& tcx)
|
|
{
|
|
{
|
|
tcx.InitTriangulation();
|
|
tcx.InitTriangulation();
|
|
- tcx.CreateAdvancingFront(nodes_);
|
|
|
|
|
|
+ tcx.CreateAdvancingFront();
|
|
// Sweep points; build mesh
|
|
// Sweep points; build mesh
|
|
SweepPoints(tcx);
|
|
SweepPoints(tcx);
|
|
// Clean up
|
|
// Clean up
|
|
@@ -57,8 +54,8 @@ void Sweep::SweepPoints(SweepContext& tcx)
|
|
for (size_t i = 1; i < tcx.point_count(); i++) {
|
|
for (size_t i = 1; i < tcx.point_count(); i++) {
|
|
Point& point = *tcx.GetPoint(i);
|
|
Point& point = *tcx.GetPoint(i);
|
|
Node* node = &PointEvent(tcx, point);
|
|
Node* node = &PointEvent(tcx, point);
|
|
- for (unsigned int ii = 0; ii < point.edge_list.size(); ii++) {
|
|
|
|
- EdgeEvent(tcx, point.edge_list[ii], node);
|
|
|
|
|
|
+ for (auto& j : point.edge_list) {
|
|
|
|
+ EdgeEvent(tcx, j, node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -68,17 +65,25 @@ void Sweep::FinalizationPolygon(SweepContext& tcx)
|
|
// Get an Internal triangle to start with
|
|
// Get an Internal triangle to start with
|
|
Triangle* t = tcx.front()->head()->next->triangle;
|
|
Triangle* t = tcx.front()->head()->next->triangle;
|
|
Point* p = tcx.front()->head()->next->point;
|
|
Point* p = tcx.front()->head()->next->point;
|
|
- while (!t->GetConstrainedEdgeCW(*p)) {
|
|
|
|
|
|
+ while (t && !t->GetConstrainedEdgeCW(*p)) {
|
|
t = t->NeighborCCW(*p);
|
|
t = t->NeighborCCW(*p);
|
|
}
|
|
}
|
|
|
|
|
|
// Collect interior triangles constrained by edges
|
|
// Collect interior triangles constrained by edges
|
|
- tcx.MeshClean(*t);
|
|
|
|
|
|
+ if (t) {
|
|
|
|
+ tcx.MeshClean(*t);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
Node& Sweep::PointEvent(SweepContext& tcx, Point& point)
|
|
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);
|
|
Node& new_node = NewFrontTriangle(tcx, point, node);
|
|
|
|
|
|
// Only need to check +epsilon since point never have smaller
|
|
// Only need to check +epsilon since point never have smaller
|
|
@@ -111,9 +116,9 @@ void Sweep::EdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
|
|
|
|
|
|
void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point)
|
|
void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point)
|
|
{
|
|
{
|
|
- if (triangle == nullptr)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
|
|
+ if (triangle == nullptr) {
|
|
|
|
+ throw std::runtime_error("EdgeEvent - null triangle");
|
|
|
|
+ }
|
|
if (IsEdgeSideOfTriangle(*triangle, ep, eq)) {
|
|
if (IsEdgeSideOfTriangle(*triangle, ep, eq)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -121,17 +126,14 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl
|
|
Point* p1 = triangle->PointCCW(point);
|
|
Point* p1 = triangle->PointCCW(point);
|
|
Orientation o1 = Orient2d(eq, *p1, ep);
|
|
Orientation o1 = Orient2d(eq, *p1, ep);
|
|
if (o1 == COLLINEAR) {
|
|
if (o1 == COLLINEAR) {
|
|
-
|
|
|
|
-
|
|
|
|
- if( triangle->Contains(&eq, p1)) {
|
|
|
|
- triangle->MarkConstrainedEdge(&eq, p1 );
|
|
|
|
|
|
+ if (triangle->Contains(&eq, p1)) {
|
|
|
|
+ triangle->MarkConstrainedEdge(&eq, p1);
|
|
// We are modifying the constraint maybe it would be better to
|
|
// We are modifying the constraint maybe it would be better to
|
|
// not change the given constraint and just keep a variable for the new constraint
|
|
// not change the given constraint and just keep a variable for the new constraint
|
|
tcx.edge_event.constrained_edge->q = p1;
|
|
tcx.edge_event.constrained_edge->q = p1;
|
|
- triangle = &triangle->NeighborAcross(point);
|
|
|
|
- EdgeEvent( tcx, ep, *p1, triangle, *p1 );
|
|
|
|
|
|
+ triangle = triangle->NeighborAcross(point);
|
|
|
|
+ EdgeEvent(tcx, ep, *p1, triangle, *p1);
|
|
} else {
|
|
} else {
|
|
- // ASSIMP_CHANGE (aramis_acg)
|
|
|
|
throw std::runtime_error("EdgeEvent - collinear points not supported");
|
|
throw std::runtime_error("EdgeEvent - collinear points not supported");
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -140,18 +142,14 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl
|
|
Point* p2 = triangle->PointCW(point);
|
|
Point* p2 = triangle->PointCW(point);
|
|
Orientation o2 = Orient2d(eq, *p2, ep);
|
|
Orientation o2 = Orient2d(eq, *p2, ep);
|
|
if (o2 == COLLINEAR) {
|
|
if (o2 == COLLINEAR) {
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if( triangle->Contains(&eq, p2)) {
|
|
|
|
- triangle->MarkConstrainedEdge(&eq, p2 );
|
|
|
|
|
|
+ if (triangle->Contains(&eq, p2)) {
|
|
|
|
+ triangle->MarkConstrainedEdge(&eq, p2);
|
|
// We are modifying the constraint maybe it would be better to
|
|
// We are modifying the constraint maybe it would be better to
|
|
// not change the given constraint and just keep a variable for the new constraint
|
|
// not change the given constraint and just keep a variable for the new constraint
|
|
tcx.edge_event.constrained_edge->q = p2;
|
|
tcx.edge_event.constrained_edge->q = p2;
|
|
- triangle = &triangle->NeighborAcross(point);
|
|
|
|
- EdgeEvent( tcx, ep, *p2, triangle, *p2 );
|
|
|
|
|
|
+ triangle = triangle->NeighborAcross(point);
|
|
|
|
+ EdgeEvent(tcx, ep, *p2, triangle, *p2);
|
|
} else {
|
|
} else {
|
|
- // ASSIMP_CHANGE (aramis_acg)
|
|
|
|
throw std::runtime_error("EdgeEvent - collinear points not supported");
|
|
throw std::runtime_error("EdgeEvent - collinear points not supported");
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -162,12 +160,13 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl
|
|
// that will cross edge
|
|
// that will cross edge
|
|
if (o1 == CW) {
|
|
if (o1 == CW) {
|
|
triangle = triangle->NeighborCCW(point);
|
|
triangle = triangle->NeighborCCW(point);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
triangle = triangle->NeighborCW(point);
|
|
triangle = triangle->NeighborCW(point);
|
|
}
|
|
}
|
|
EdgeEvent(tcx, ep, eq, triangle, point);
|
|
EdgeEvent(tcx, ep, eq, triangle, point);
|
|
} else {
|
|
} else {
|
|
// This triangle crosses constraint so lets flippin start!
|
|
// This triangle crosses constraint so lets flippin start!
|
|
|
|
+ assert(triangle);
|
|
FlipEdgeEvent(tcx, ep, eq, triangle, point);
|
|
FlipEdgeEvent(tcx, ep, eq, triangle, point);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -228,7 +227,6 @@ void Sweep::Fill(SweepContext& tcx, Node& node)
|
|
if (!Legalize(tcx, *triangle)) {
|
|
if (!Legalize(tcx, *triangle)) {
|
|
tcx.MapTriangleToNodes(*triangle);
|
|
tcx.MapTriangleToNodes(*triangle);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|
void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|
@@ -237,7 +235,7 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|
// Fill right holes
|
|
// Fill right holes
|
|
Node* node = n.next;
|
|
Node* node = n.next;
|
|
|
|
|
|
- while (node->next) {
|
|
|
|
|
|
+ while (node && node->next) {
|
|
// if HoleAngle exceeds 90 degrees then break.
|
|
// if HoleAngle exceeds 90 degrees then break.
|
|
if (LargeHole_DontFill(node)) break;
|
|
if (LargeHole_DontFill(node)) break;
|
|
Fill(tcx, *node);
|
|
Fill(tcx, *node);
|
|
@@ -247,7 +245,7 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|
// Fill left holes
|
|
// Fill left holes
|
|
node = n.prev;
|
|
node = n.prev;
|
|
|
|
|
|
- while (node->prev) {
|
|
|
|
|
|
+ while (node && node->prev) {
|
|
// if HoleAngle exceeds 90 degrees then break.
|
|
// if HoleAngle exceeds 90 degrees then break.
|
|
if (LargeHole_DontFill(node)) break;
|
|
if (LargeHole_DontFill(node)) break;
|
|
Fill(tcx, *node);
|
|
Fill(tcx, *node);
|
|
@@ -264,6 +262,35 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|
}
|
|
}
|
|
|
|
|
|
// True if HoleAngle exceeds 90 degrees.
|
|
// True if HoleAngle exceeds 90 degrees.
|
|
|
|
+// LargeHole_DontFill checks if the advancing front has a large hole.
|
|
|
|
+// A "Large hole" is a triangle formed by a sequence of points in the advancing
|
|
|
|
+// front where three neighbor points form a triangle.
|
|
|
|
+// And angle between left-top, bottom, and right-top points is more than 90 degrees.
|
|
|
|
+// The first part of the algorithm reviews only three neighbor points, e.g. named A, B, C.
|
|
|
|
+// Additional part of this logic reviews a sequence of 5 points -
|
|
|
|
+// additionally reviews one point before and one after the sequence of three (A, B, C),
|
|
|
|
+// e.g. named X and Y.
|
|
|
|
+// In this case, angles are XBC and ABY and this if angles are negative or more
|
|
|
|
+// than 90 degrees LargeHole_DontFill returns true.
|
|
|
|
+// But there is a configuration when ABC has a negative angle but XBC or ABY is less
|
|
|
|
+// than 90 degrees and positive.
|
|
|
|
+// Then function LargeHole_DontFill return false and initiates filling.
|
|
|
|
+// This filling creates a triangle ABC and adds it to the advancing front.
|
|
|
|
+// But in the case when angle ABC is negative this triangle goes inside the advancing front
|
|
|
|
+// and can intersect previously created triangles.
|
|
|
|
+// This triangle leads to making wrong advancing front and problems in triangulation in the future.
|
|
|
|
+// Looks like such a triangle should not be created.
|
|
|
|
+// The simplest way to check and fix it is to check an angle ABC.
|
|
|
|
+// If it is negative LargeHole_DontFill should return true and
|
|
|
|
+// not initiate creating the ABC triangle in the advancing front.
|
|
|
|
+// X______A Y
|
|
|
|
+// \ /
|
|
|
|
+// \ /
|
|
|
|
+// \ B /
|
|
|
|
+// | /
|
|
|
|
+// | /
|
|
|
|
+// |/
|
|
|
|
+// C
|
|
bool Sweep::LargeHole_DontFill(const Node* node) const {
|
|
bool Sweep::LargeHole_DontFill(const Node* node) const {
|
|
|
|
|
|
const Node* nextNode = node->next;
|
|
const Node* nextNode = node->next;
|
|
@@ -271,20 +298,28 @@ bool Sweep::LargeHole_DontFill(const Node* node) const {
|
|
if (!AngleExceeds90Degrees(node->point, nextNode->point, prevNode->point))
|
|
if (!AngleExceeds90Degrees(node->point, nextNode->point, prevNode->point))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
+ if (AngleIsNegative(node->point, nextNode->point, prevNode->point))
|
|
|
|
+ return true;
|
|
|
|
+
|
|
// Check additional points on front.
|
|
// Check additional points on front.
|
|
const Node* next2Node = nextNode->next;
|
|
const Node* next2Node = nextNode->next;
|
|
// "..Plus.." because only want angles on same side as point being added.
|
|
// "..Plus.." because only want angles on same side as point being added.
|
|
- if ((next2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, next2Node->point, prevNode->point))
|
|
|
|
|
|
+ if ((next2Node != nullptr) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, next2Node->point, prevNode->point))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
const Node* prev2Node = prevNode->prev;
|
|
const Node* prev2Node = prevNode->prev;
|
|
// "..Plus.." because only want angles on same side as point being added.
|
|
// "..Plus.." because only want angles on same side as point being added.
|
|
- if ((prev2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, nextNode->point, prev2Node->point))
|
|
|
|
|
|
+ if ((prev2Node != nullptr) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, nextNode->point, prev2Node->point))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool Sweep::AngleIsNegative(const Point* origin, const Point* pa, const Point* pb) const {
|
|
|
|
+ const double angle = Angle(origin, pa, pb);
|
|
|
|
+ return angle < 0;
|
|
|
|
+}
|
|
|
|
+
|
|
bool Sweep::AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const {
|
|
bool Sweep::AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const {
|
|
const double angle = Angle(origin, pa, pb);
|
|
const double angle = Angle(origin, pa, pb);
|
|
return ((angle > PI_div2) || (angle < -PI_div2));
|
|
return ((angle > PI_div2) || (angle < -PI_div2));
|
|
@@ -306,7 +341,7 @@ double Sweep::Angle(const Point* origin, const Point* pa, const Point* pb) const
|
|
*/
|
|
*/
|
|
const double px = origin->x;
|
|
const double px = origin->x;
|
|
const double py = origin->y;
|
|
const double py = origin->y;
|
|
- const double ax = pa->x- px;
|
|
|
|
|
|
+ const double ax = pa->x - px;
|
|
const double ay = pa->y - py;
|
|
const double ay = pa->y - py;
|
|
const double bx = pb->x - px;
|
|
const double bx = pb->x - px;
|
|
const double by = pb->y - py;
|
|
const double by = pb->y - py;
|
|
@@ -599,7 +634,7 @@ void Sweep::FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) {
|
|
if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) {
|
|
// Concave
|
|
// Concave
|
|
FillRightConcaveEdgeEvent(tcx, edge, node);
|
|
FillRightConcaveEdgeEvent(tcx, edge, node);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Convex
|
|
// Convex
|
|
FillRightConvexEdgeEvent(tcx, edge, node);
|
|
FillRightConvexEdgeEvent(tcx, edge, node);
|
|
// Retry this one
|
|
// Retry this one
|
|
@@ -623,7 +658,6 @@ void Sweep::FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Sweep::FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
void Sweep::FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
@@ -632,13 +666,13 @@ void Sweep::FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
if (Orient2d(*node.next->point, *node.next->next->point, *node.next->next->next->point) == CCW) {
|
|
if (Orient2d(*node.next->point, *node.next->next->point, *node.next->next->next->point) == CCW) {
|
|
// Concave
|
|
// Concave
|
|
FillRightConcaveEdgeEvent(tcx, edge, *node.next);
|
|
FillRightConcaveEdgeEvent(tcx, edge, *node.next);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Convex
|
|
// Convex
|
|
// Next above or below edge?
|
|
// Next above or below edge?
|
|
if (Orient2d(*edge->q, *node.next->next->point, *edge->p) == CCW) {
|
|
if (Orient2d(*edge->q, *node.next->next->point, *edge->p) == CCW) {
|
|
// Below
|
|
// Below
|
|
FillRightConvexEdgeEvent(tcx, edge, *node.next);
|
|
FillRightConvexEdgeEvent(tcx, edge, *node.next);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Above
|
|
// Above
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -677,13 +711,13 @@ void Sweep::FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
if (Orient2d(*node.prev->point, *node.prev->prev->point, *node.prev->prev->prev->point) == CW) {
|
|
if (Orient2d(*node.prev->point, *node.prev->prev->point, *node.prev->prev->prev->point) == CW) {
|
|
// Concave
|
|
// Concave
|
|
FillLeftConcaveEdgeEvent(tcx, edge, *node.prev);
|
|
FillLeftConcaveEdgeEvent(tcx, edge, *node.prev);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Convex
|
|
// Convex
|
|
// Next above or below edge?
|
|
// Next above or below edge?
|
|
if (Orient2d(*edge->q, *node.prev->prev->point, *edge->p) == CW) {
|
|
if (Orient2d(*edge->q, *node.prev->prev->point, *edge->p) == CW) {
|
|
// Below
|
|
// Below
|
|
FillLeftConvexEdgeEvent(tcx, edge, *node.prev);
|
|
FillLeftConvexEdgeEvent(tcx, edge, *node.prev);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Above
|
|
// Above
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -699,17 +733,22 @@ void Sweep::FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
|
|
if (Orient2d(*node.point, *node.prev->point, *node.prev->prev->point) == CW) {
|
|
if (Orient2d(*node.point, *node.prev->point, *node.prev->prev->point) == CW) {
|
|
// Next is concave
|
|
// Next is concave
|
|
FillLeftConcaveEdgeEvent(tcx, edge, node);
|
|
FillLeftConcaveEdgeEvent(tcx, edge, node);
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
// Next is convex
|
|
// Next is convex
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* t, Point& p)
|
|
void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* t, Point& p)
|
|
{
|
|
{
|
|
- Triangle& ot = t->NeighborAcross(p);
|
|
|
|
|
|
+ assert(t);
|
|
|
|
+ Triangle* ot_ptr = t->NeighborAcross(p);
|
|
|
|
+ if (ot_ptr == nullptr)
|
|
|
|
+ {
|
|
|
|
+ throw std::runtime_error("FlipEdgeEvent - null neighbor across");
|
|
|
|
+ }
|
|
|
|
+ Triangle& ot = *ot_ptr;
|
|
Point& op = *ot.OppositePoint(*t, p);
|
|
Point& op = *ot.OppositePoint(*t, p);
|
|
|
|
|
|
if (InScanArea(p, *t->PointCCW(p), *t->PointCW(p), op)) {
|
|
if (InScanArea(p, *t->PointCCW(p), *t->PointCW(p), op)) {
|
|
@@ -775,10 +814,26 @@ Point& Sweep::NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op)
|
|
void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle,
|
|
void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle,
|
|
Triangle& t, Point& p)
|
|
Triangle& t, Point& p)
|
|
{
|
|
{
|
|
- Triangle& ot = t.NeighborAcross(p);
|
|
|
|
- Point& op = *ot.OppositePoint(t, p);
|
|
|
|
|
|
+ Triangle* ot_ptr = t.NeighborAcross(p);
|
|
|
|
+ if (ot_ptr == nullptr) {
|
|
|
|
+ throw std::runtime_error("FlipScanEdgeEvent - null neighbor across");
|
|
|
|
+ }
|
|
|
|
|
|
- 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
|
|
// flip with new edge op->eq
|
|
FlipEdgeEvent(tcx, eq, op, &ot, op);
|
|
FlipEdgeEvent(tcx, eq, op, &ot, op);
|
|
// TODO: Actually I just figured out that it should be possible to
|
|
// TODO: Actually I just figured out that it should be possible to
|
|
@@ -788,7 +843,7 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
|
|
// also need to set a new flip_triangle first
|
|
// also need to set a new flip_triangle first
|
|
// Turns out at first glance that this is somewhat complicated
|
|
// Turns out at first glance that this is somewhat complicated
|
|
// so it will have to wait.
|
|
// so it will have to wait.
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
Point& newP = NextFlipPoint(ep, eq, ot, op);
|
|
Point& newP = NextFlipPoint(ep, eq, ot, op);
|
|
FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP);
|
|
FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP);
|
|
}
|
|
}
|
|
@@ -797,14 +852,9 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
|
|
Sweep::~Sweep() {
|
|
Sweep::~Sweep() {
|
|
|
|
|
|
// Clean up memory
|
|
// Clean up memory
|
|
- for(size_t i = 0; i < nodes_.size(); i++) {
|
|
|
|
- delete nodes_[i];
|
|
|
|
|
|
+ for (auto& node : nodes_) {
|
|
|
|
+ delete node;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef _MSC_VER
|
|
|
|
-# pragma warning( pop )
|
|
|
|
-#endif // _MSC_VER
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+} // namespace p2t
|