-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToQtCoordinates.cpp
53 lines (46 loc) · 1.38 KB
/
ToQtCoordinates.cpp
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
#include "ToQtCoordinates.h"
ToQtCoordinates::ToQtCoordinates(int width, int height)
:
typeOfTransformation(Type::Basic),
width(width),
height(height),
initialP(QPointF()),
endP(QPointF())
{
}
ToQtCoordinates::ToQtCoordinates( Type typeOfTransformation, int width, int height)
:
typeOfTransformation(typeOfTransformation),
width(width),
height(height),
initialP(QPointF()),
endP(QPointF())
{
}
ToQtCoordinates::ToQtCoordinates(Type typeOfTransformation, int width, int height, QPointF initialP, QPointF endP)
:
typeOfTransformation(typeOfTransformation),
width(width),
height(height),
initialP(initialP),
endP(endP)
{
}
QPointF ToQtCoordinates::convertToQtCoordinates(QPointF realCoordinates)
{
switch(typeOfTransformation){
case Type::Basic :
return QPointF(realCoordinates.x(), this->height - realCoordinates.y());
break;
case Type::MidPoint :
return QPointF(realCoordinates.x() + this->width/2, this->height - realCoordinates.y());
break;
case Type::Scaled :
double deltaPx = endP.x() - initialP.x();
double deltaPy = endP.y() - initialP.y();
return QPointF((realCoordinates.x()-initialP.x())*this->width/deltaPx,
(realCoordinates.y()-initialP.y())*this->height/deltaPy);
break;
}
return QPointF();
}