-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern.cpp
49 lines (43 loc) · 1.53 KB
/
Pattern.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
#include "Pattern.h"
Pattern::Pattern() {}
void Pattern::startNewPattern()
{
while(pattern.count() > 0)
{
pattern.pop_back();
}
}
void Pattern::addNewSequence(double movement, QString direction, double angle)
{
QJsonObject qjsobj = {
{"movement", movement},
{"direction", direction},
{"angle", angle}
};
pattern.append(qjsobj);
}
bool Pattern::isPatternMatch(Pattern source, Pattern tobeAuthed)
{
if(source.pattern.size() != tobeAuthed.pattern.size())
{
return false;
}
for(int i = 0; i < source.pattern.size(); i++)
{
double moveLowerBound = source.pattern.at(i).toObject().value("movement").toDouble() * (1-moveTolerance);
double moveHigherBound = source.pattern.at(i).toObject().value("movement").toDouble() * (1+moveTolerance);
double angleLowerBound = source.pattern.at(i).toObject().value("angle").toDouble() * (1-angleTolerance);
double angleHigherBound = source.pattern.at(i).toObject().value("angle").toDouble() * (1+angleTolerance);
if(moveLowerBound > tobeAuthed.pattern.at(i).toObject().value("movement").toDouble() ||
moveHigherBound < tobeAuthed.pattern.at(i).toObject().value("movement").toDouble())
{
return false;
}
if(angleLowerBound > tobeAuthed.pattern.at(i).toObject().value("angle").toDouble() ||
angleHigherBound < tobeAuthed.pattern.at(i).toObject().value("angle").toDouble())
{
return false;
}
}
return true;
}