forked from bedrock-dev/MCBEStructureFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.h
97 lines (73 loc) · 2.54 KB
/
tools.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// Created by xhy on 2021/12/16.
//
#ifndef MCBE_STRUCTUE_TOOLS_H
#define MCBE_STRUCTUE_TOOLS_H
#include <chrono>
#include <cstring>
#define DEBUG
#ifdef WIN32
#define FN (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define FN (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define LOG(...) log(FN,__FUNCTION__,__LINE__,__VA_ARGS__)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
#define INFO(...) fprintf(stdout,__VA_ARGS__)
typedef std::chrono::high_resolution_clock timer_clock;
#define TIMER_START auto start = timer_clock::now();
#define TIMER_END \
auto elapsed = timer_clock::now() - start; \
long long timeReslut = \
std::chrono::duration_cast<std::chrono::microseconds>(elapsed) \
.count();
struct Vec2i {
int x = 0;
int z = 0;
bool operator<(const Vec2i &rhs) const;
bool operator==(const Vec2i &rhs) const;
constexpr Vec2i(int xx, int zz) : x(xx), z(zz) {}
Vec2i operator+(const Vec2i &rhs) const {
return {x + rhs.x, z + rhs.z};
}
Vec2i operator-(const Vec2i &rhs) const {
return {x - rhs.x, z - rhs.z};
}
Vec2i() = default;
};
struct Box {
Vec2i min;
Vec2i max;
bool operator<(const Box &rhs) const;
bool operator==(const Box &rhs) const;
};
typedef Vec2i ChunkPos;
typedef Vec2i Pos;
typedef Vec2i AreaPos;
template<typename T>
inline bool between(const T &min, const T &max, const T &x) {
return x >= min && x <= max;
}
inline Pos scala_down(const Vec2i &origin, int SCALA) {
auto cx = origin.x < 0 ? origin.x + 1 - SCALA : origin.x;
auto cz = origin.z < 0 ? origin.z + 1 - SCALA : origin.z;
return {cx / SCALA, cz / SCALA};
}
inline Box scala_up(const Pos &origin, int scala) {
auto x = origin.x * scala;
auto z = origin.z * scala;
return {{x, z},
{x + scala - 1, z + scala - 1}
};
}
//get the fisrt number(>= begin) which === remain (mod module)
//返回区间[begin,+inf)中和remain同余的最小的数(模modulo)
inline int get_cong_with_module(int begin, int modulo, int remain) {
int r = begin - (begin % modulo);
if (begin > 0)
r += modulo;
auto c1 = r + remain;
return between(begin, begin + modulo, c1) ? c1 : c1 - modulo;
}
void log(const char *file_name, const char *function_name, size_t line, const char *fmt, ...);
#endif //MCBE_STRUCTUE_TOOLS_H