Skip to content

Commit

Permalink
Normalize rotation values when rotating objects
Browse files Browse the repository at this point in the history
Avoids weird / confusing values.

Closes mapeditor#2775
  • Loading branch information
bjorn committed Jun 12, 2020
1 parent 093cd3d commit 0daeaa7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/tiled/objectselectiontool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,15 @@ void ObjectSelectionTool::startRotating(const QPointF &pos)
updateHandleVisibility();
}

// Brings rotation values within the range of 0 - 360
static qreal normalizeRotation(qreal rotation)
{
qreal normalized = fmod(rotation, 360.);
if (normalized < 0.)
normalized += 360.;
return normalized;
}

void ObjectSelectionTool::updateRotatingItems(const QPointF &pos,
Qt::KeyboardModifiers modifiers)
{
Expand Down Expand Up @@ -1247,7 +1256,7 @@ void ObjectSelectionTool::updateRotatingItems(const QPointF &pos,
const QPointF newPixelPos = mOriginPos + newRelPos - offset;
const QPointF newPos = renderer->screenToPixelCoords(newPixelPos);

const qreal newRotation = object.oldRotation + angleDiff * 180 / M_PI;
const qreal newRotation = normalizeRotation(object.oldRotation + angleDiff * 180 / M_PI);

mapObject->setPosition(newPos);
if (mapObject->canRotate())
Expand Down

0 comments on commit 0daeaa7

Please sign in to comment.