void CardShuffler<Card>::operator()(Card** head) { //count the number of cards int size = 0; Card* it = *head; while (it) it = it->GetNext(), size++; //shuffle the cards Card* tmpHead = nullptr; while(size) { PushFront(&tmpHead, PopRandom(head, size)); size--; } *head = tmpHead; }
std::vector<sPoint> GeneratePoissonPoints( float MinDist, int NewPointsCount, size_t NumPoints ) { std::vector<sPoint> SamplePoints; std::vector<sPoint> ProcessList; // create the grid float CellSize = MinDist / sqrt( 2.0f ); int GridW = ( int )ceil( 1.0f / CellSize ); int GridH = ( int )ceil( 1.0f / CellSize ); sGrid Grid( GridW, GridH, CellSize ); sPoint FirstPoint = sPoint( RandomFloat(), RandomFloat() ); // update containers ProcessList.push_back( FirstPoint ); SamplePoints.push_back( FirstPoint ); Grid.Insert( FirstPoint ); // generate new points for each point in the queue while ( !ProcessList.empty() && SamplePoints.size() < NumPoints ) { // a progress indicator, kind of if ( SamplePoints.size() % 100 == 0 ) std::cout << "."; sPoint Point = PopRandom( ProcessList ); for ( int i = 0; i < NewPointsCount; i++ ) { sPoint NewPoint = GenerateRandomPointAround( Point, MinDist ); bool Fits = Circle ? NewPoint.IsInCircle() : NewPoint.IsInRectangle(); if ( Fits && !Grid.IsInNeighbourhood( NewPoint, MinDist, CellSize ) ) { ProcessList.push_back( NewPoint ); SamplePoints.push_back( NewPoint ); Grid.Insert( NewPoint ); continue; } } } std::cout << std::endl << std::endl; return SamplePoints; }