diff --git a/include/bounce/quickhull/qh_hull.h b/include/bounce/quickhull/qh_hull.h index 90a3d8e..50da172 100644 --- a/include/bounce/quickhull/qh_hull.h +++ b/include/bounce/quickhull/qh_hull.h @@ -120,9 +120,11 @@ public: return m_iteration; } - // Return if this hull is valid. - bool IsConsistent() const; - + // Validate this hull. + void Validate() const; + void Validate(const qhFace* face) const; + void Validate(const qhHalfEdge* edge) const; + // Draw this hull. void Draw() const; private: diff --git a/src/bounce/collision/shapes/hull.cpp b/src/bounce/collision/shapes/hull.cpp index 5dbcd19..2f7242b 100644 --- a/src/bounce/collision/shapes/hull.cpp +++ b/src/bounce/collision/shapes/hull.cpp @@ -40,21 +40,14 @@ void b3Hull::Validate() const void b3Hull::Validate(const b3Face* face) const { - bool ok = false; const b3HalfEdge* begin = GetEdge(face->edge); const b3HalfEdge* edge = begin; do - { - if (GetFace(edge->face) == face) - { - ok = true; - break; - } + { + B3_ASSERT(GetFace(edge->face) == face); edge = edges + edge->next; } while (edge != begin); - B3_ASSERT(ok); - Validate(edges + face->edge); } @@ -69,12 +62,14 @@ void b3Hull::Validate(const b3HalfEdge* e) const B3_ASSERT(twin->twin == edgeIndex); u32 count = 0; + const b3HalfEdge* begin = e; do { - const b3HalfEdge* next = edges + e->next; - e = edges + next->twin; B3_ASSERT(count < edgeCount); ++count; + + const b3HalfEdge* next = edges + e->next; + e = edges + next->twin; } while (e != begin); } \ No newline at end of file diff --git a/src/bounce/quickhull/qh_hull.cpp b/src/bounce/quickhull/qh_hull.cpp index 6411850..2714eb7 100644 --- a/src/bounce/quickhull/qh_hull.cpp +++ b/src/bounce/quickhull/qh_hull.cpp @@ -108,6 +108,8 @@ void qhHull::Construct(void* memory, const b3Array& vs) return; } + Validate(); + qhVertex* eye = NextVertex(); while (eye) { @@ -274,12 +276,7 @@ bool qhHull::BuildInitialHull(const b3Array& vertices) } // Connectivity check. - bool ok = IsConsistent(); - B3_ASSERT(ok); - if (!ok) - { - return false; - } + Validate(); // Add remaining points to the hull. // Assign closest face plane to each of them. @@ -714,28 +711,45 @@ void qhHull::MergeFaces(b3Array& newFaces) } } -bool qhHull::IsConsistent() const +void qhHull::Validate(const qhHalfEdge* edge) const { + const qhHalfEdge* twin = edge->twin; + B3_ASSERT(twin->twin == edge); + + b3Vec3 A = edge->tail->position; + b3Vec3 B = twin->tail->position; + B3_ASSERT(b3DistanceSquared(A, B) > B3_EPSILON * B3_EPSILON); + u32 count = 0; - - qhFace* f = m_faceList.head; - while (f) + const qhHalfEdge* begin = edge; + do { - B3_ASSERT(f->state != qhFace::e_deleted); - qhHalfEdge* e = f->edge; - do - { - ++count; - //B3_ASSERT(e->face == f); - B3_ASSERT(e->twin->twin == e); - B3_ASSERT(count < 10000); - e = e->next; - } while (e != f->edge); + ++count; + const qhHalfEdge* next = edge->next; + edge = next->twin; + } while (edge != begin); +} - f = f->next; +void qhHull::Validate(const qhFace* face) const +{ + const qhHalfEdge* begin = face->edge; + const qhHalfEdge* edge = begin; + do + { + B3_ASSERT(edge->face == face); + edge = edge->next; + } while (edge != begin); + + Validate(face->edge); +} + +void qhHull::Validate() const +{ + for (qhFace* face = m_faceList.head; face != NULL; face = face->next) + { + B3_ASSERT(face->state != face->e_deleted); + Validate(face); } - - return true; } void qhHull::Draw() const