blob: 66d9a2ea11e359c88ea7b204ffda11ab51bf56be (
plain)
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
|
//! Random miscellaneous things like UUIDs that don't deserve their own crate.
#![feature(int_roundings)]
mod difficulty;
pub use difficulty::*;
mod resource_location;
pub use resource_location::*;
mod game_type;
pub use game_type::*;
mod slot;
pub use slot::*;
mod position;
pub use position::*;
mod direction;
pub use direction::*;
mod delta;
pub use delta::*;
mod particle;
pub use particle::*;
mod cursor3d;
pub use cursor3d::*;
mod bitset;
pub use bitset::*;
mod aabb;
pub use aabb::*;
mod block_hit_result;
pub use block_hit_result::*;
// java moment
// TODO: add tests and optimize/simplify this
pub fn floor_mod(x: i32, y: u32) -> u32 {
if x < 0 {
y - ((-x) as u32 % y)
} else {
x as u32 % y
}
}
// TODO: make this generic
pub fn binary_search(mut min: i32, max: i32, predicate: &dyn Fn(i32) -> bool) -> i32 {
let mut diff = max - min;
while diff > 0 {
let diff_mid = diff / 2;
let mid = min + diff_mid;
if predicate(mid) {
diff = diff_mid;
} else {
min = mid + 1;
diff -= diff_mid + 1;
}
}
min
}
|