Skip to content

Commit

Permalink
Adopt the (now stable) euclidean modulo feature
Browse files Browse the repository at this point in the history
This increases our Rust requirement to 1.38.0
  • Loading branch information
est31 committed Aug 14, 2019
1 parent d030e2b commit 4e6f438
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
8 changes: 1 addition & 7 deletions mehlon-server/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,6 @@ fn durtofl(d :Duration) -> f32 {
d.as_millis() as f32 / 1_000.0
}

// TODO: once euclidean division stabilizes,
// use it: https://github.com/rust-lang/rust/issues/49048
fn mod_euc(a :f32, b :f32) -> f32 {
((a % b) + b) % b
}

/// Block position to chunk position
pub fn btchn(v :Vector3<isize>) -> Vector3<isize> {
fn r(x :isize) -> isize {
Expand All @@ -841,5 +835,5 @@ pub fn btchn(v :Vector3<isize>) -> Vector3<isize> {

/// Block position to position inside chunk
fn btpic(v :Vector3<isize>) -> Vector3<isize> {
v.map(|v| mod_euc(v as f32, CHUNKSIZE as f32) as isize)
v.map(|v| (v as f32).rem_euclid(CHUNKSIZE as f32) as isize)
}
8 changes: 1 addition & 7 deletions mehlon/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,12 +891,6 @@ fn clamp(a :f32, min :f32, max :f32) -> f32 {
}
}

// TODO: once euclidean division stabilizes,
// use it: https://github.com/rust-lang/rust/issues/49048
fn mod_euc(a :f32, b :f32) -> f32 {
((a % b) + b) % b
}

/// Degrees to radians
fn dtr(v :f32) -> f32 {
v / 180.0 * std::f32::consts::PI
Expand Down Expand Up @@ -1039,7 +1033,7 @@ impl Camera {
const MAX_PITCH :f32 = 89.0;
self.pitch = clamp(factor * delta.y as f32 + self.pitch, -MAX_PITCH, MAX_PITCH);
self.yaw += factor * delta.x as f32;
self.yaw = mod_euc(self.yaw + 180.0, 360.0) - 180.0;
self.yaw = (self.yaw + 180.0).rem_euclid(360.0) - 180.0;
}
fn fast_speed(&self) -> bool {
self.fast_mode || self.fast_pressed
Expand Down

0 comments on commit 4e6f438

Please sign in to comment.