Cell WangFiller::findFittingCell(const TileLayer &back, const TileLayer &front, const QRegion &fillRegion, QPoint point) const { Q_ASSERT(mWangSet); QList<WangTile> wangTilesList = mWangSet->findMatchingWangTiles(wangIdFromSurroundings(back, front, fillRegion, point)); RandomPicker<WangTile> wangTiles; for (const WangTile &wangTile : wangTilesList) wangTiles.add(wangTile, mWangSet->wangTileProbability(wangTile)); WangTile wangTile; if (!mWangSet->isComplete()) { // goes through all adjacent, empty tiles and sees if the current wangTile // allows them to have at least one fill option. while (!wangTiles.isEmpty()) { wangTile = wangTiles.take(); bool continueFlag = false; QPoint adjacentPoints[8]; getSurroundingPoints(point, mStaggeredRenderer, mStaggerAxis, adjacentPoints); // now goes through and checks adjacents, continuing if any can't be filled for (int i = 0; i < 8; ++i) { QPoint adjacentPoint = adjacentPoints[i]; // check if the point is empty, otherwise, continue. if (!getCell(back, front, fillRegion, adjacentPoint).isEmpty()) continue; WangId adjacentWangId = wangIdFromSurroundings(back, front, fillRegion, adjacentPoint); WangId wangId = wangTile.wangId(); adjacentWangId.updateToAdjacent(wangId, (i + 4) % 8); if (!mWangSet->wildWangIdIsUsed(adjacentWangId)) { continueFlag = true; break; } } if (!continueFlag) break; } } else if (!wangTiles.isEmpty()) { wangTile = wangTiles.pick(); } return wangTile.makeCell(); }
const TileStampVariation &TileStamp::randomVariation() const { Q_ASSERT(!d->variations.isEmpty()); RandomPicker<const TileStampVariation *> randomPicker; for (const TileStampVariation &variation : qAsConst(d->variations)) randomPicker.add(&variation, variation.probability); return *randomPicker.pick(); }
Map *TileStamp::randomVariation() const { if (d->variations.isEmpty()) return 0; RandomPicker<const TileStampVariation *> randomPicker; for (const TileStampVariation &variation : d->variations) randomPicker.add(&variation, variation.probability); return randomPicker.pick()->map; }