aboutsummaryrefslogtreecommitdiff
path: root/symbol.cpp
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-02-23 20:39:30 +0200
committerMikko Syrjä <mikko@3d-system.fi>2019-02-23 20:39:30 +0200
commit498b1b9a56b399225d3a70742fdcb01245aa91c4 (patch)
tree2fd8596e3e049b46aad818cbe029a48c9df3e7e0 /symbol.cpp
parent07599f27937b8af9a3d3a46f17e34b51d6eada2c (diff)
downloadsymedit-498b1b9a56b399225d3a70742fdcb01245aa91c4.tar.gz
symedit-498b1b9a56b399225d3a70742fdcb01245aa91c4.zip
Implement rotations.
Diffstat (limited to 'symbol.cpp')
-rw-r--r--symbol.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/symbol.cpp b/symbol.cpp
index 11d9791..f95ba71 100644
--- a/symbol.cpp
+++ b/symbol.cpp
@@ -238,5 +238,20 @@ const SymEditSymbol::Item& SymEditSymbol::GetItem(int index) const
*/
void SymEditSymbol::RotateSymbol(int dir)
{
- //##
+ auto rotate = [](QPoint& point, int dir)
+ {
+ double length = sqrt(point.x() * point.x() + point.y() * point.y());
+ double angle = atan2(point.y(), point.x());
+ angle += (dir > 0 ? -M_PI / 2.0 : M_PI / 2.0);
+ double x = cos(angle) * length, y = sin(angle) * length;
+ point.setX(static_cast<int>(x + (x > 0.0 ? 0.5 : -0.5)));
+ point.setY(static_cast<int>(y + (y > 0.0 ? 0.5 : -0.5)));
+ };
+
+ for ( auto& item : Items )
+ {
+ rotate(item.Point, dir);
+ if ( item.Operation != 'R' )
+ rotate(item.Value, dir);
+ }
}