-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.h
65 lines (54 loc) · 1.2 KB
/
utils.h
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
#ifndef UTILS_H
#define UTILS_H
#include <QFile>
#include <QDebug>
#include <QByteArray>
#include <QVector2D>
#define qd qDebug()
#define ftoStr(x) QString::number(x, 'f', 2)
#define toStr(x) QString::number(x)
inline float d2r(float deg)
{
return deg * 0.0174533f;
}
inline float r2d(const float rad)
{
return rad * 57.2958f;
}
inline QVector2D vRot90(const QVector2D v) {
QVector2D res;
res.setX(v.y());
res.setY(-v.x());
return res;
}
inline float vDot(const QVector2D& a, const QVector2D& b)
{
return a.x() * b.x() + a.y() * b.y();
}
inline float vCrossZ(const QVector2D & a, const QVector2D & b)
{
return a.x() * b.y() - a.y() * b.x();
}
inline QByteArray readFile(const QString fname)
{
QFile f(fname);
f.open(QFile::ReadOnly);
QByteArray data = f.readAll();
f.close();
return data;
}
inline void writeFile(const QString fname, QByteArray data)
{
QFile f(fname);
f.open(QFile::WriteOnly);
f.write(data);
f.close();
}
inline void appendFile(const QString fname, QByteArray data)
{
QFile f(fname);
f.open(QFile::Append);
f.write(data);
f.close();
}
#endif // UTILS_H