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
|
#include "inputtypes.h"
#include <QtMath>
const CursorNavigationCommand CursorNavigationCommand::Up(-M_PI_2, 0);
const CursorNavigationCommand CursorNavigationCommand::Down(M_PI_2, 0);
const CursorNavigationCommand CursorNavigationCommand::Left(M_PI, 0);
const CursorNavigationCommand CursorNavigationCommand::Right(0, 0);
CursorNavigationCommand::CursorNavigationCommand()
:angle(-1), angleTolerance(-1), action(NoAction)
{}
CursorNavigationCommand::CursorNavigationCommand(qreal a, qreal tolerance)
:angle(CursorNavigationCommand::fitAngle(a)), angleTolerance(tolerance), action(NoAction)
{}
CursorNavigationCommand::CursorNavigationCommand(Action a)
:angle(-1), angleTolerance(-1), action(a)
{}
//test if this commands angle is between given angles. clockwise from begin to end
//bool CursorNavigationCommand::angleIsBetween(qreal begin, qreal end)
//{
// return CursorNavigationCommand::angleIsBetween(this->angle, begin, end);
//}
bool CursorNavigationCommand::angleIsBetween(qreal angle, qreal begin, qreal end)
{
if (begin > end)
return angle >= begin || angle <= end;
else
return angle >= begin && angle <= end;
}
qreal CursorNavigationCommand::fitAngle(qreal angle)
{
if (angle > M_PI)
return -M_PI + std::fmod(angle ,M_PI);
else if (angle < -M_PI)
return M_PI + std::fmod(angle ,M_PI);
return angle;
}
|