-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbasicpolygon.cpp
More file actions
65 lines (57 loc) · 1.91 KB
/
basicpolygon.cpp
File metadata and controls
65 lines (57 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "basicpolygon.h"
void BasicPolygon::applyTransformations(QList<AbstractTransform*> trans)
{
if(trans.size() == 0)
return;
for(int i=trans.size()-1; i>=0; i--)
{
AbstractTransform* t = trans.at(i);
if(t->type() == AbstractTransform::TRANS_ROTATE)
{
RotationTransform *rot = dynamic_cast<RotationTransform*>(t);
setRotation(rot);
}
else if(t->type() == AbstractTransform::TRANS_MATRIX)
{
Matrix3x3* m = dynamic_cast<Matrix3x3*>(t);
setMatrix(m);
}
else if(t->type() == AbstractTransform::TRANS_TRANSLATE)
{
Translate* translate = dynamic_cast<Translate*>(t);
setTranslate(translate);
}
}
}
void BasicPolygon::applyTransformations(QList<QList<AbstractTransform *> > trans)
{
for(int i=trans.size()-1; i>=0; i--)
{
applyTransformations( trans.at(i) );
}
}
void BasicPolygon::setTranslate(Translate* offset)
{
myPolygon.translate( offset->translate );
}
void BasicPolygon::setRotation(RotationTransform* transform)
{
QTransform t;
t.translate( transform->center.x(), transform->center.y() );
t.rotate( transform->angle );
t.translate( -transform->center.x(), -transform->center.y() );
myPolygon = t.map(myPolygon);
}
void BasicPolygon::setMatrix(Matrix3x3* matrix)
{
//qDebug() << "BEFORE Matrix transformed polygon: " << myPolygon;
QPolygonF tempPoly;
foreach(QPointF p, myPolygon)
{
//See this website: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform
tempPoly << QPointF( matrix->m11*p.x() + matrix->m12*p.y()+matrix->m13,
matrix->m21*p.x()+matrix->m22*p.y()+matrix->m23 );
}
//qDebug() << "Matrix transformed polygon: " << tempPoly;
myPolygon = tempPoly;
}