From 4338a2be10ffa2334bf0dd4ef8fff6bef7c0ac62 Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Fri, 22 Jan 2010 09:57:49 -0500 Subject: [PATCH] bug hunting --- poly2tri/common/shapes.h | 2 ++ poly2tri/common/utils.h | 2 +- poly2tri/sweep/advancing_front.cc | 8 ++++---- poly2tri/sweep/advancing_front.h | 2 +- poly2tri/sweep/sweep.cc | 13 ++++++++----- poly2tri/sweep/sweep_context.cc | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/poly2tri/common/shapes.h b/poly2tri/common/shapes.h index 76c144b..e349b30 100644 --- a/poly2tri/common/shapes.h +++ b/poly2tri/common/shapes.h @@ -43,6 +43,7 @@ struct Node; struct Edge; struct Point { + double x, y; /// Default constructor does nothing (for performance). @@ -118,6 +119,7 @@ struct Point { // Represents a simple polygon's edge struct Edge { + Point* p, *q; /// Constructor diff --git a/poly2tri/common/utils.h b/poly2tri/common/utils.h index a91377a..61ae8f0 100644 --- a/poly2tri/common/utils.h +++ b/poly2tri/common/utils.h @@ -62,7 +62,7 @@ Orientation Orient2d(Point& pa, Point& pb, Point& pc) double val = detleft - detright; if (val > -EPSILON && val < EPSILON) { return COLLINEAR; - } else if (val > 0) { + } else if (val > EPSILON) { return CCW; } return CW; diff --git a/poly2tri/sweep/advancing_front.cc b/poly2tri/sweep/advancing_front.cc index 0381385..daf352b 100644 --- a/poly2tri/sweep/advancing_front.cc +++ b/poly2tri/sweep/advancing_front.cc @@ -37,10 +37,11 @@ AdvancingFront::AdvancingFront(Node& head, Node& tail) search_node_ = &head; } -Node* AdvancingFront::Locate(const double& x) +Node* AdvancingFront::LocateNode(const double& x) { Node* node = search_node_; - + //printf("L: %p - %p\n", node, node->next); + if (x < node->value) { //printf("<: - %f,%f - %p\n", x, node->value, node->next); while ((node = node->prev) != NULL) { @@ -76,7 +77,7 @@ Node* AdvancingFront::LocatePoint(const Point* point) const double px = point->x; Node* node = FindSearchNode(px); const double nx = node->point->x; - printf("AF: %p - %p\n", node, node->next); + //printf("LP: %p - %p\n", node, node->next); if (px == nx) { if (point != node->point) { @@ -104,7 +105,6 @@ Node* AdvancingFront::LocatePoint(const Point* point) } } search_node_ = node; - printf("\nSN: %p - %p\n", search_node_, search_node_->next); return node; } diff --git a/poly2tri/sweep/advancing_front.h b/poly2tri/sweep/advancing_front.h index 71e06f3..71e9eaa 100644 --- a/poly2tri/sweep/advancing_front.h +++ b/poly2tri/sweep/advancing_front.h @@ -69,7 +69,7 @@ Node* search(); void set_search(Node* node); /// Locate insertion point along advancing front -Node* Locate(const double& x); +Node* LocateNode(const double& x); Node* LocatePoint(const Point* point); diff --git a/poly2tri/sweep/sweep.cc b/poly2tri/sweep/sweep.cc index 05af544..0a7af20 100644 --- a/poly2tri/sweep/sweep.cc +++ b/poly2tri/sweep/sweep.cc @@ -47,13 +47,13 @@ void Sweep::SweepPoints(SweepContext& tcx) { for (int i = 1; i < tcx.point_count(); i++) { Point& point = *tcx.GetPoint(i); - printf("%i = %f,%f ", i, point.x, point.y); + //printf("%i = %f,%f ", i, point.x, point.y); Node& node = PointEvent(tcx, point); - printf("1..."); + //printf("1..."); for (int i = 0; i < point.edge_list.size(); i++) { EdgeEvent(tcx, point.edge_list[i], node); } - printf("2!\n"); + //printf("2!\n"); } } @@ -707,7 +707,7 @@ void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& t, Triangle& ot = t.NeighborAcross(p); Point& op = *ot.OppositePoint(t, p); - if (&t.NeighborAcross(p) == NULL) { + if (&ot == NULL) { // If we want to integrate the fillEdgeEvent do it here // With current implementation we should never get here //throw new RuntimeException( "[BUG:FIXME] FLIP failed due to missing triangle"); @@ -730,6 +730,7 @@ void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& t, // XXX: I think one of the triangles should be legalized here? } } else { + //printf("flip again!\n"); Orientation o = Orient2d(eq, op, ep); t = NextFlipTriangle(tcx, (int)o, t, ot, p, op); FlipEdgeEvent(tcx, ep, eq, t, p); @@ -741,8 +742,9 @@ void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& t, } } -Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op) +Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op) { + //printf("enum %i,%i\n", o, CCW); if (o == CCW) { // ot is not crossing edge after flip int edge_index = ot.EdgeIndex(&p, &op); @@ -754,6 +756,7 @@ Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triang // t is not crossing edge after flip int edge_index = t.EdgeIndex(&p, &op); + //printf("edge_index = %i\n", edge_index); t.delaunay_edge[edge_index] = true; Legalize(tcx, t); t.ClearDelunayEdges(); diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index 8ff9e45..c77730a 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -99,7 +99,7 @@ void SweepContext::AddToMap(Triangle* triangle) Node& SweepContext::LocateNode(Point& point) { // TODO implement search tree - return *front_->Locate(point.x); + return *front_->LocateNode(point.x); } void SweepContext::CreateAdvancingFront() @@ -132,7 +132,7 @@ void SweepContext::RemoveNode(Node* node) void SweepContext::MapTriangleToNodes(Triangle& t) { for (int i = 0; i < 3; i++) { - if (t.GetNeighbor(i) == NULL) { + if (!t.GetNeighbor(i)) { Node* n = front_->LocatePoint(t.PointCW(*t.GetPoint(i))); if (n) n->triangle = &t;