SourceForge has been redesigned. Learn more.
Close

[6dd4ed]: / src / plugins / automatic_router / utils.h  Maximize  Restore  History

Download this file

78 lines (59 with data), 1.6 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
66
67
68
69
70
71
72
73
74
75
#ifndef UTILS_H
#define UTILS_H
#include <qpoint.h>
#include <math.h>
class QSize;
inline int roundDown(const int x, const int roundness) {
//FIXME: What is this function really supposed to do?
// must be important because it's called millions of times!
if (x < 0)
return (x - roundness + 1) / roundness;
else return (x / roundness);
}
inline QPoint roundDown(const QPoint &p, const int roundness) {
return QPoint(roundDown(p.x(), roundness), roundDown(p.y(), roundness));
}
inline int toCanvas(const int pos) {
return (pos << 3) + 4;
}
inline int fromCanvas(const int pos) {
return (pos - 4) >> 3;
}
inline QPoint toCanvas(const QPoint &pos) {
return QPoint(toCanvas(pos.x()), toCanvas(pos.y()));
}
inline QPoint fromCanvas(const QPoint &pos) {
return QPoint(fromCanvas(pos.x()), fromCanvas(pos.y()));
}
inline int roundDouble(const double x) {
return int(floor(x + 0.5));
}
inline double qpoint_distance(const QPoint &p1, const QPoint &p2) {
return hypot(p1.x() - p2.x(), p1.y() - p2.y());
}
inline int snapToCanvas(const int x) {
return (x & ~7) | 4;
}
inline int snapToCanvas(const double x) {
return snapToCanvas(int(x));
}
inline QPoint snapToCanvas(const QPoint &pos) {
return QPoint(snapToCanvas(pos.x()), snapToCanvas(pos.y()));
}
template<class T> inline T mapToCells(const T& value)
{
return (value - T(4,4)) / 8;
}
template<class T> inline T mapFromCells(const T& value)
{
return value * 8 + T(4,4);
}
template<> inline QSize mapToCells(const QSize& value)
{
return value / 8;
}
template<> inline QSize mapFromCells(const QSize& value)
{
return value * 8;
}
#endif