Skip to content

Commit

Permalink
flip tiles if needed, prevent adding already added ids
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Nov 1, 2020
1 parent c4d63bf commit 360df03
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/libtiled/wangset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,11 @@ WangSet::Type wangSetTypeFromString(const QString &string)

void WangSet::addRotations(bool alternate) {
QList<WangTile> to_add;
QSet<WangId> already_added; // to avoid adding more tiles than requested
for (const WangTile & i: mWangIdToWangTile) {
for (unsigned rotation=1;rotation<4;++rotation) {
WangId rotid=i.wangId().rotated(rotation);
if (alternate || !mWangIdToWangTile.contains(rotid))
if (alternate || (!mWangIdToWangTile.contains(rotid) || !already_added.contains(rotid)))
{
WangTile newtile = i;
newtile.setAutogenerated(true);
Expand All @@ -1007,6 +1008,26 @@ void WangSet::addRotations(bool alternate) {
case 3: newtile.rotateLeft(); break;
}
to_add.push_back(std::move(newtile));
already_added.insert(newtile.wangId());
}
}
// rotation alone will not cover all eight possible variations, but flipped once+rotation will complete it
WangId flipId = i.wangId();
flipId.flipHorizontally();
for (unsigned rotation=0;rotation<4;++rotation) {
WangId rotid=flipId.rotated(rotation);
if (alternate || (!mWangIdToWangTile.contains(rotid) || !already_added.contains(rotid)))
{
WangTile newtile = i;
newtile.setAutogenerated(true);
newtile.flipHorizontally();
switch (rotation) {
case 1: newtile.rotateRight(); break;
case 2: newtile.rotateRight(); newtile.rotateRight(); break;
case 3: newtile.rotateLeft(); break;
}
to_add.push_back(std::move(newtile));
already_added.insert(newtile.wangId());
}
}
}
Expand Down

0 comments on commit 360df03

Please sign in to comment.