-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
46 lines (31 loc) · 1.06 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
#ifndef UTILS_H_
#define UTILS_H_
#include <QPoint>
#include <QPointF>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <ctime>
#include <random>
#include <utility>
namespace utils {
extern std::mt19937 random;
enum class Direction { kLeft, kRight };
std::pair<int64_t, int64_t> ArithmeticalDivMod(int64_t a, int64_t b);
int64_t ArithmeticalMod(int64_t a, int64_t b);
struct QPointLexicographicalCompare {
bool operator()(QPoint lhs, QPoint rhs) const;
};
constexpr double MapRange(double value, double from_min, double from_max,
double to_min, double to_max) {
return to_min +
(value - from_min) / (from_max - from_min) * (to_max - to_min);
}
double DivideDouble(double first, double second, double percentage);
QPointF DivideSegment(QPointF first, QPointF second, double percentage);
double GetRandomDouble(double left_bound = 0, double right_bound = 1);
double GetDistance(QPointF lhs, QPointF rhs);
std::array<QPoint, 4> NeighbourPoints(QPoint point);
} // namespace utils
#endif // UTILS_H_