From 56de0fe9899999a361df2a97d33753043857922d Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 14 Aug 2015 10:57:40 -0300 Subject: [PATCH] Fix rotation in straight angle (fix #592) --- src/app/ui/editor/pixels_movement.cpp | 2 +- src/gfx/transformation.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/ui/editor/pixels_movement.cpp b/src/app/ui/editor/pixels_movement.cpp index 291ad4a52..300fa335f 100644 --- a/src/app/ui/editor/pixels_movement.cpp +++ b/src/app/ui/editor/pixels_movement.cpp @@ -396,7 +396,7 @@ void PixelsMovement::moveImage(const gfx::Point& pos, MoveModifier moveModifier) if ((moveModifier & AngleSnapMovement) == AngleSnapMovement) { // TODO make this configurable static const double keyAngles[] = { - 0.0, 26.565, 45.0, 63.435, 90.0, 116.565, 135.0, 153.435, -180.0, + 0.0, 26.565, 45.0, 63.435, 90.0, 116.565, 135.0, 153.435, 180.0, 180.0, -153.435, -135.0, -116, -90.0, -63.435, -45.0, -26.565 }; diff --git a/src/gfx/transformation.cpp b/src/gfx/transformation.cpp index 59bc095a8..c6bbad32f 100644 --- a/src/gfx/transformation.cpp +++ b/src/gfx/transformation.cpp @@ -11,6 +11,7 @@ #include "gfx/transformation.h" #include "gfx/point.h" #include "gfx/size.h" +#include "fixmath/fixmath.h" #include @@ -72,13 +73,18 @@ PointT Transformation::rotatePoint( const PointT& pivot, double angle) { - double cos = std::cos(-angle); - double sin = std::sin(-angle); - double dx = (point.x-pivot.x); - double dy = (point.y-pivot.y); + using namespace fixmath; + + fixed fixangle = ftofix(-angle); + fixangle = fixmul(fixangle, radtofix_r); + + fixed cos = fixcos(fixangle); + fixed sin = fixsin(fixangle); + fixed dx = fixsub(ftofix(point.x), ftofix(pivot.x)); + fixed dy = fixsub(ftofix(point.y), ftofix(pivot.y)); return PointT( - pivot.x + dx*cos - dy*sin, - pivot.y + dy*cos + dx*sin); + fixtof(fixadd(ftofix(pivot.x), fixsub(fixmul(dx, cos), fixmul(dy, sin)))), + fixtof(fixadd(ftofix(pivot.y), fixadd(fixmul(dy, cos), fixmul(dx, sin))))); } Rect Transformation::transformedBounds() const