typo, ensure polygon convexity

This commit is contained in:
Irlan 2018-05-09 22:33:10 -03:00
parent 2e39ebd4e4
commit 4da08af7fa

View File

@ -698,7 +698,7 @@ static void b3ResetFaceData(qhFace* face)
v1 -= c; v1 -= c;
v2 -= c; v2 -= c;
// Apply Newew's method // Apply Newell's method
n += b3Newell(v1, v2); n += b3Newell(v1, v2);
e = e->next; e = e->next;
@ -927,25 +927,22 @@ qhFace* qhHull::RemoveEdge(qhHalfEdge* edge)
// Maintained invariants: // Maintained invariants:
// - Each vertex must have at least three neighbor faces // - Each vertex must have at least three neighbor faces
// - Face 1 must be concave // - Face 1 must be convex
// Searching a redundant vertex in face 1 boils down to // Search a incoming and outgoing edge in the face 1
// search for a incoming and outgoing edges in the face 1
// which have the same neighbour face. // which have the same neighbour face.
qhHalfEdge* ein = face1->edge; qhHalfEdge* ein = face1->edge;
do do
{ {
qhHalfEdge* eout = ein->next; qhHalfEdge* eout = ein->next;
// Has a vertex in the face 1 become redundant? // Has the outgoing vertex become redundant?
if (ein->twin->face == eout->twin->face) if (ein->twin->face == eout->twin->face)
{ {
qhHalfEdge* ein0 = ein; qhHalfEdge* ein0 = ein;
ein = eout; ein = eout;
// Fix error. // Remove the outgoing vertex.
// This is were some edges and faces might
// be deleted.
FixMerge(face1, ein0); FixMerge(face1, ein0);
continue; continue;
} }
@ -1288,15 +1285,37 @@ void qhHull::ValidateConvexity() const
// Ensure topological health // Ensure topological health
B3_ASSERT(face != other); B3_ASSERT(face != other);
// Ensure face convexity // Ensure edge convexity
float32 d1 = b3Distance(other->center, face->plane); float32 d1 = b3Distance(other->center, face->plane);
B3_ASSERT(d1 < -m_tolerance); B3_ASSERT(d1 < -m_tolerance);
float32 d2 = b3Distance(face->center, other->plane); float32 d2 = b3Distance(face->center, other->plane);
B3_ASSERT(d2 < -m_tolerance); B3_ASSERT(d2 < -m_tolerance);
// Ensure polygon convexity
b3Vec3 P = edge->tail->position;
b3Vec3 Q = edge->twin->tail->position;
b3Vec3 E = Q - P;
b3Vec3 D = b3Cross(E, face->plane.normal);
// Edge side plane
b3Plane plane;
plane.normal = b3Normalize(D);
plane.offset = b3Dot(plane.normal, P);
// All the other vertices must be behind the edge side plane
const qhHalfEdge* eother = edge->prev;
do
{
float32 d = b3Distance(eother->tail->position, plane);
B3_ASSERT(d <= 0.0f);
eother = eother->prev;
} while (eother != edge->next);
edge = edge->next; edge = edge->next;
} while (edge != face->edge); } while (edge != edge);
} }
} }