bug hunting

This commit is contained in:
zzzzrrr 2010-01-22 09:57:49 -05:00
parent 696ef826bd
commit 4338a2be10
6 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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();

View File

@ -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;