bool ConvexHull2<Real>::Update ( Edge*& hull, int i ) { // Locate an edge visible to the input point (if possible). Edge* visible = 0; Edge* current = hull; do { if ( current->GetSign( i, mQuery ) > 0 ) { visible = current; break; } current = current->E[1]; } while ( current != hull ); if ( !visible ) { // The point is inside the current hull; nothing to do. return true; } // Remove the visible edges. Edge* adj0 = visible->E[0]; assertion( adj0 != 0, "Expecting nonnull adjacent\n" ); if ( !adj0 ) { return false; } Edge* adj1 = visible->E[1]; assertion( adj1 != 0, "Expecting nonnull adjacent\n" ); if ( !adj1 ) { return false; } visible->DeleteSelf(); while ( adj0->GetSign( i, mQuery ) > 0 ) { hull = adj0; adj0 = adj0->E[0]; assertion( adj0 != 0, "Expecting nonnull adjacent\n" ); if ( !adj0 ) { return false; } adj0->E[1]->DeleteSelf(); } while ( adj1->GetSign( i, mQuery ) > 0 ) { hull = adj1; adj1 = adj1->E[1]; assertion( adj1 != 0, "Expecting nonnull adjacent\n" ); if ( !adj1 ) { return false; } adj1->E[0]->DeleteSelf(); } // Insert the new edges formed by the input point and the end points of // the polyline of invisible edges. Edge* edge0 = new0 Edge( adj0->V[1], i ); Edge* edge1 = new0 Edge( i, adj1->V[0] ); edge0->Insert( adj0, edge1 ); edge1->Insert( edge0, adj1 ); hull = edge0; return true; }
bool ConvexHull2<Real>::Update (Edge*& rpkHull, int i) { // Locate an edge visible to the input point (if possible). Edge* pkVisible = 0; Edge* pkCurrent = rpkHull; do { if (pkCurrent->GetSign(i,m_pkQuery) > 0) { pkVisible = pkCurrent; break; } pkCurrent = pkCurrent->A[1]; } while (pkCurrent != rpkHull); if (!pkVisible) { // The point is inside the current hull; nothing to do. return true; } // Remove the visible edges. Edge* pkAdj0 = pkVisible->A[0]; assert(pkAdj0); if (!pkAdj0) { return false; } Edge* pkAdj1 = pkVisible->A[1]; assert(pkAdj1); if (!pkAdj1) { return false; } pkVisible->DeleteSelf(); while (pkAdj0->GetSign(i,m_pkQuery) > 0) { rpkHull = pkAdj0; pkAdj0 = pkAdj0->A[0]; assert(pkAdj0); if (!pkAdj0) { return false; } pkAdj0->A[1]->DeleteSelf(); } while (pkAdj1->GetSign(i,m_pkQuery) > 0) { rpkHull = pkAdj1; pkAdj1 = pkAdj1->A[1]; assert(pkAdj1); if (!pkAdj1) { return false; } pkAdj1->A[0]->DeleteSelf(); } // Insert the new edges formed by the input point and the end points of // the polyline of invisible edges. Edge* pkEdge0 = WM4_NEW Edge(pkAdj0->V[1],i); Edge* pkEdge1 = WM4_NEW Edge(i,pkAdj1->V[0]); pkEdge0->Insert(pkAdj0,pkEdge1); pkEdge1->Insert(pkEdge0,pkAdj1); rpkHull = pkEdge0; return true; }